-- first part is copied from another mod
local players = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
end)
-- chance for deterioate for x of 100, but on every global step
local odd = 10
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y), z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
end
end)
local playersFilth = {}
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"filth_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=2,oddly_breakable_by_hand=1},
drop = "",
})
minetest.register_abm(
{nodenames = {"default:dirt","default:dirt_with_grass","default:dirt_with_grass_footsteps"},
interval = 1.0,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local objs = minetest.env:get_objects_inside_radius(pos, 1)
for k, obj in pairs(objs) do
if obj:is_player() and obj:getpos().y > pos.y+.25 then
playersFilth[obj:get_player_name()] = 10
end
end
end,
})
minetest.register_abm(
{nodenames = {"default:wood"},
interval = .5,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local objs = minetest.env:get_objects_inside_radius(pos, 1)
for k, obj in pairs(objs) do
if obj:is_player() and playersFilth[obj:get_player_name()] > 0 and obj:getpos().y > pos.y+.25 then
local nPos = {x=pos.x,y=pos.y+1,z=pos.z}
playersFilth[obj:get_player_name()] = 0
minetest.env:add_node(nPos, {name="filth:dirt"})
end
end
end,
})
minetest.register_on_joinplayer(function(obj)
playersFilth[obj:get_player_name()] = 0
end)ashenk69 wrote:I am not sure if using a global step or an ABM is more efficient for the processor since with an ABM you can set the time check but the global step is called every half second or so.
local players = {}
local playersFilth = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
playersFilth[player:get_player_name()] = 0
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
playersFilth[player:get_player_name()] = nil
end)
-- chance for deterioate for x of 100, but on every global step <--- needs to be changed
local odd = 10
local max_distance = 5
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"filth_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=2,oddly_breakable_by_hand=1},
drop = "",
})
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y), z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if p_ground ~= p_ground_previous then
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersFilth[player:get_player_name()] < 1 then
playersFilth[player:get_player_name()] = 1
-- (X+5)/2 aproximates 5
elseif playersFilth[player:get_player_name()] >= 1 then
playersFilth[player:get_player_name()] = math.floor((playersFilth[player:get_player_name()] + max_distance) /2 )
end
end
end
-- making node to previous node
local p_ground_previous = p_ground
end
end)
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y), z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if p_ground ~= p_ground_previous then
if n_ground.name == "default:wood" then
if playersFilth[player:get_player_name()] > 0 then
local p_add_filth = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_filth = minetest.env:get_node(p_add_filth)
-- to not replace doors with filth
if n_add_filth.name == "air" then
minetest.env:add_node(p_add_filth,{type="node",name="filth:dirt"})
end
-- I think thats not the right place for this line
playersFilth[player:get_player_name()] = playersFilth[player:get_player_name()] - 1
end
end
end
-- making node to previous node
local p_ground_previous = p_ground
end
end)
Casimir wrote:[...]I'm not sure either. I thought an ABM is executed for all the relevant nodes. So with one pressure plate it's just a little bit, but with tons of dirt it's more. In the walking_light mod it is done without ABM.[...]
Echo wrote:Right, it would be nice if there was an event every time a step is made. It's really inefficient to call the functions every 0.05 sec, for my walking_light mod, too.
Hmmmm, I'm new to programming mods for minetest, is there such an event?
local players = {}
local playersFilth = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
playersFilth[player:get_player_name()] = 0
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
playersFilth[player:get_player_name()] = nil
end)
-- chance for deterioate for x of 100, but on every global step <--- needs to be changed
local odd = 10
local max_distance = 5
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"filth_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=2, oddly_breakable_by_hand=1, falling_node=1},
drop = "",
})
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
local player_pos = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5), z=math.floor(pos.z+0.5) }
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5)-1, z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if player_pos ~= player_pos_previous then
-- gettin your feet dirty when walking on blanc dirt
if n_ground.name == "default:dirt" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersFilth[player:get_player_name()] < 1 then
playersFilth[player:get_player_name()] = 1
print (playersFilth[player:get_player_name()]) -- for debuging
-- (X+5)/2 aproximates 5
elseif playersFilth[player:get_player_name()] >= 1 then
playersFilth[player:get_player_name()] = math.floor((playersFilth[player:get_player_name()] + max_distance) /2 )
print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- turning grass into dirt
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
-- reducing filth when not walking on dirt
if n_ground.name ~= "default:dirt" then
if playersFilth[player:get_player_name()] > 0 then
-- I think thats not the right place for this line
playersFilth[player:get_player_name()] = playersFilth[player:get_player_name()] - 1
print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- making filth when walking on wood
if n_ground.name == "default:wood" then
if playersFilth[player:get_player_name()] > 0 then
local p_add_filth = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_filth = minetest.env:get_node(p_add_filth)
-- to not replace doors with filth
if n_add_filth.name == "air" then
minetest.env:add_node(p_add_filth,{type="node",name="filth:dirt"})
end
end
end
end
-- making node to previous node
local player_pos_previous = player_pos
end
end)
local players = {}
local playersFilth = {}
local player_pos = {}
local player_pos_previous = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
playersFilth[player:get_player_name()] = 0
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
playersFilth[player:get_player_name()] = nil
end)
-- chance for deterioate for x of 100, but on every global step <--- needs to be changed
local odd = 10
local max_distance = 5
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"filth_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=2, oddly_breakable_by_hand=1, falling_node=1},
drop = "",
})
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
player_pos[player:get_player_name()] = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5), z=math.floor(pos.z+0.5) }
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5)-1, z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if player_pos[player:get_player_name()] ~= player_pos_previous[player:get_player_name()] then
-- gettin your feet dirty when walking on blanc dirt
if n_ground.name == "default:dirt" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersFilth[player:get_player_name()] < 1 then
playersFilth[player:get_player_name()] = 1
print (playersFilth[player:get_player_name()]) -- for debuging
-- (X+5)/2 aproximates 5
elseif playersFilth[player:get_player_name()] >= 1 then
playersFilth[player:get_player_name()] = math.floor((playersFilth[player:get_player_name()] + max_distance) /2 )
print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- turning grass into dirt
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
-- reducing filth when not walking on dirt
if n_ground.name ~= "default:dirt" then
if playersFilth[player:get_player_name()] > 0 then
-- I think thats not the right place for this line
playersFilth[player:get_player_name()] = playersFilth[player:get_player_name()] - 1
print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- making filth when walking on wood
if n_ground.name == "default:wood" then
if playersFilth[player:get_player_name()] > 0 then
local p_add_filth = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_filth = minetest.env:get_node(p_add_filth)
-- to not replace doors with filth
if n_add_filth.name == "air" then
minetest.env:add_node(p_add_filth,{type="node",name="filth:dirt"})
end
end
end
end
-- making node to previous node
player_pos_previous[player:get_player_name()] = player_pos[player:get_player_name()]
end
end)
local players = {}
local playersFilth = {}
local playersSand = {}
local playersGravel = {}
local player_pos = {}
local player_pos_previous = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
playersFilth[player:get_player_name()] = 0
playersSand[player:get_player_name()] = 0
playersGravel[player:get_player_name()] = 0
player_pos_previous[player:get_player_name()] = { x=0, y=0, z=0 }
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
playersFilth[player:get_player_name()] = nil
playersSand[player:get_player_name()] = nil
playersGravel[player:get_player_name()] = nil
player_pos_previous[player:get_player_name()] = nil
end)
-- chance for deterioate for x of 100
local odd = 20
local max_distance = 5
-- the filth you leave behind
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"default_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=3, falling_node=1, filthy=2},
drop = "",
})
minetest.register_node("filth:sand", {
drawtype = "nodebox",
tile_images = {"default_sand.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=3, falling_node=1, filthy=3},
drop = "",
})
minetest.register_node("filth:gravel", {
drawtype = "nodebox",
tile_images = {"default_gravel.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=2, falling_node=1, filthy=1},
drop = "",
})
-- "invisible" extra nodes for crating the path
--[[ the order when walking over it is:
grass,
grass_walked,
dirt,
dirt_walked
--]]
minetest.register_node("filth:dirt_with_grass_walked", {
description = "Dirt with Grass - you walked over it",
tiles = {"default_grass.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"},
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
-- sound missing
})
minetest.register_node("filth:dirt_walked", {
description = "Dirt - you walked over it",
tiles = {"default_dirt.png"},
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
-- sound missing
})
minetest.register_abm(
{nodenames = {"filth:dirt_with_grass_walked"},
interval = 37,
chance = 13,
action = function(pos)
minetest.env:add_node(pos, {name="default:dirt_with_grass"})
end,
})
minetest.register_abm(
{nodenames = {"filth:dirt_walked"},
interval = 37,
chance = 13,
action = function(pos)
minetest.env:add_node(pos, {name="default:dirt"})
end,
})
-- the broom (not finished)
minetest.register_tool("filth:broom", {
description = "Broom",
inventory_image = "default:stick.png",
tool_capabilities = {
max_drop_level=0,
groupcaps={
filthy={times={[1]=0.80, [2]=0.40, [3]=0.20}, uses=30, maxlevel=1}
}
},
})
minetest.register_craft({
output = 'filth:broom',
recipe = {
{'default:stick'},
{'default:stick'},
{'default:leaves'},
}
})
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
player_pos[player:get_player_name()] = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5), z=math.floor(pos.z+0.5) }
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5)-1, z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if player_pos[player:get_player_name()].x ~= player_pos_previous[player:get_player_name()].x or player_pos[player:get_player_name()].y ~= player_pos_previous[player:get_player_name()].y or player_pos[player:get_player_name()].z ~= player_pos_previous[player:get_player_name()].z then
-- gettin your feet dirty when walking on blanc dirt
if n_ground.name == "default:dirt" or n_ground.name == "filth:dirt_walked" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersFilth[player:get_player_name()] < 1 then
playersFilth[player:get_player_name()] = 1
-- print (playersFilth[player:get_player_name()]) -- for debuging
-- (X+5)/2 aproximates 5
elseif playersFilth[player:get_player_name()] >= 1 then
playersFilth[player:get_player_name()] = math.floor((playersFilth[player:get_player_name()] + max_distance) /2 )
-- print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- gettin your feet dirty when walking on sand
if n_ground.name == "default:sand" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersSand[player:get_player_name()] < 1 then
playersSand[player:get_player_name()] = 1
-- (X+5)/2 aproximates 5
elseif playersSand[player:get_player_name()] >= 1 then
playersSand[player:get_player_name()] = math.floor((playersSand[player:get_player_name()] + max_distance) /2 )
end
end
-- gettin your feet dirty when walking on gravel
if n_ground.name == "default:gravel" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersGravel[player:get_player_name()] < 1 then
playersGravel[player:get_player_name()] = 1
-- (X+5)/2 aproximates 5
elseif playersGravel[player:get_player_name()] >= 1 then
playersGravel[player:get_player_name()] = math.floor((playersGravel[player:get_player_name()] + max_distance) /2 )
end
end
-- turning grass into dirt
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="filth:dirt_with_grass_walked"})
end
end
if n_ground.name == "filth:dirt_with_grass_walked" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
if n_ground.name == "default:dirt" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="filth:dirt_walked"})
end
end
-- reducing filth when not walking on dirt
if n_ground.name ~= "default:dirt" and n_ground.name ~= "filth:dirt_walked" then
if playersFilth[player:get_player_name()] > 0 then
playersFilth[player:get_player_name()] = playersFilth[player:get_player_name()] - 1
-- print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- reducing sand
if n_ground.name ~= "default:sand" then
if playersSand[player:get_player_name()] > 0 then
playersSand[player:get_player_name()] = playersSand[player:get_player_name()] - 1
end
end
-- reducing gravel
if n_ground.name ~= "default:gravel" then
if playersGravel[player:get_player_name()] > 0 then
playersGravel[player:get_player_name()] = playersGravel[player:get_player_name()] - 1
end
end
-- making filth
if n_ground.name == "default:wood" or n_ground.name == "default:stone" or n_ground.name == "default:cobble" or n_ground.name == "default:sand" or n_ground.name == "default:gravel" then
if playersFilth[player:get_player_name()] > 0 then
if math.random(1, 100) <= odd then
local p_add_filth = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_filth = minetest.env:get_node(p_add_filth)
-- to not replace doors with filth
if n_add_filth.name == "air" then
minetest.env:add_node(p_add_filth,{type="node",name="filth:dirt"})
end
end
end
end
-- making sand when walking on wood
if n_ground.name == "default:wood" or n_ground.name == "default:stone" or n_ground.name == "default:cobble" or n_ground.name == "default:dirt" or n_ground.name == "default:dirt_with_grass" or n_ground.name == "default:gravel" then
if playersSand[player:get_player_name()] > 0 then
if math.random(1, 100) <= odd then
local p_add_sand = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_sand = minetest.env:get_node(p_add_sand)
-- to not replace doors with filth
if n_add_sand.name == "air" then
minetest.env:add_node(p_add_sand,{type="node",name="filth:sand"})
end
end
end
end
-- making gravel when walking on wood
if n_ground.name == "default:wood" or n_ground.name == "default:stone" or n_ground.name == "default:cobble" or n_ground.name == "default:dirt" or n_ground.name == "default:dirt_with_grass" or n_ground.name == "default:sand" then
if playersGravel[player:get_player_name()] > 0 then
if math.random(1, 100) <= odd then
local p_add_gravel = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_gravel = minetest.env:get_node(p_add_gravel)
-- to not replace doors with filth
if n_add_gravel.name == "air" then
minetest.env:add_node(p_add_gravel,{type="node",name="filth:gravel"})
end
end
end
end
end
-- making node to previous node
player_pos_previous[player:get_player_name()] = { x=player_pos[player:get_player_name()].x, y=player_pos[player:get_player_name()].y, z=player_pos[player:get_player_name()].z }
end
end)
x | x
x | U
# # #
p p p
w w w
local players = {}
local playersFilth = {}
local playersSand = {}
local playersGravel = {}
local player_pos = {}
local player_pos_previous = {}
minetest.register_on_joinplayer(function(player)
table.insert(players, player)
playersFilth[player:get_player_name()] = 0
playersSand[player:get_player_name()] = 0
playersGravel[player:get_player_name()] = 0
player_pos_previous[player:get_player_name()] = { x=0, y=0, z=0 }
end)
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
playersFilth[player:get_player_name()] = nil
playersSand[player:get_player_name()] = nil
playersGravel[player:get_player_name()] = nil
player_pos_previous[player:get_player_name()] = nil
end)
-- chance for deterioate for x of 100
local odd = 37
local max_distance = 5
-- the filth you leave behind
minetest.register_node("filth:dirt", {
drawtype = "nodebox",
tile_images = {"default_dirt.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {crumbly=3, falling_node=1, filthy=2},
drop = "",
})
-- "invisible" extra nodes for crating the path
--[[ the order when walking over it is:
grass,
grass_walked,
dirt,
dirt_walked
--]]
minetest.register_node("filth:dirt_with_grass_walked", {
description = "Dirt with Grass - you walked over it",
tiles = {"default_grass.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"},
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
-- sound missing
})
minetest.register_node("filth:dirt_walked", {
description = "Dirt - you walked over it",
tiles = {"default_dirt.png"},
is_ground_content = true,
groups = {crumbly=3},
drop = 'default:dirt',
-- sound missing
})
minetest.register_abm(
{nodenames = {"filth:dirt_with_grass_walked"},
interval = 53,
chance = 31,
action = function(pos)
minetest.env:add_node(pos, {name="default:dirt_with_grass"})
end,
})
minetest.register_abm(
{nodenames = {"filth:dirt_walked"},
interval = 53,
chance = 31,
action = function(pos)
minetest.env:add_node(pos, {name="default:dirt"})
end,
})
-- things for cleaning up
minetest.register_tool("filth:broom", {
description = "Broom",
inventory_image = "filth_tool_broom.png",
tool_capabilities = {
max_drop_level=0,
groupcaps={
filthy={times={[1]=0.80, [2]=0.40, [3]=0.20}, uses=90, maxlevel=1}
}
},
})
minetest.register_tool("filth:mop", {
description = "super Mop!",
inventory_image = "filth_tool_mop.png",
tool_capabilities = {
max_drop_level=0,
groupcaps={
filthy={times={[1]=0.70, [2]=0.30, [3]=0.10}, uses=5, maxlevel=1}
}
},
})
minetest.register_node("filth:mat", {
description = "Home sweet Home",
drawtype = "nodebox",
tile_images = {"filth_mat.png"},
paramtype = "light",
is_ground_content = true,
walkable = false,
node_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
selection_box = {
type = "fixed",
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,flammable=3},
})
minetest.register_craft({
output = 'filth:broom',
recipe = {
{'default:stick'},
{'default:stick'},
{'default:leaves'},
}
})
minetest.register_craft({
output = 'filth:mop',
recipe = {
{'', 'default:stick', ''},
{'', 'default:stick', 'bucket:bucket_water'},
{'wool:white', 'wool:white', 'wool:white'},
}
})
minetest.register_craft({
output = 'filth:mat',
recipe = {
{'default:papyrus', 'default:papyrus', 'default:papyrus'},
{'default:wood', 'default:wood', 'default:wood'},
}
})
minetest.register_globalstep(function(dtime)
for i,player in ipairs(players) do
local pos = player:getpos()
player_pos[player:get_player_name()] = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5), z=math.floor(pos.z+0.5) }
local p_ground = { x=math.floor(pos.x+0.5), y=math.floor(pos.y+0.5)-1, z=math.floor(pos.z+0.5) }
local n_ground = minetest.env:get_node(p_ground)
-- checking if the node is the previous node
if player_pos[player:get_player_name()].x ~= player_pos_previous[player:get_player_name()].x or player_pos[player:get_player_name()].y ~= player_pos_previous[player:get_player_name()].y or player_pos[player:get_player_name()].z ~= player_pos_previous[player:get_player_name()].z then
-- gettin your feet dirty when walking on blanc dirt
if n_ground.name == "default:dirt" or n_ground.name == "filth:dirt_walked" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersFilth[player:get_player_name()] < 1 then
playersFilth[player:get_player_name()] = 1
-- print (playersFilth[player:get_player_name()]) -- for debuging
-- (X+5)/2 aproximates 5
elseif playersFilth[player:get_player_name()] >= 1 then
playersFilth[player:get_player_name()] = math.floor((playersFilth[player:get_player_name()] + max_distance) /2 )
-- print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- gettin your feet dirty when walking on sand
if n_ground.name == "default:sand" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersSand[player:get_player_name()] < 1 then
playersSand[player:get_player_name()] = 1
-- (X+5)/2 aproximates 5
elseif playersSand[player:get_player_name()] >= 1 then
playersSand[player:get_player_name()] = math.floor((playersSand[player:get_player_name()] + max_distance) /2 )
end
end
-- gettin your feet dirty when walking on gravel
if n_ground.name == "default:gravel" then
-- increase the players filth on a logarithmic scale.
-- starting with 1
if playersGravel[player:get_player_name()] < 1 then
playersGravel[player:get_player_name()] = 1
-- (X+5)/2 aproximates 5
elseif playersGravel[player:get_player_name()] >= 1 then
playersGravel[player:get_player_name()] = math.floor((playersGravel[player:get_player_name()] + max_distance) /2 )
end
end
-- turning grass into dirt
if n_ground.name == "default:dirt_with_grass" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="filth:dirt_with_grass_walked"})
end
end
if n_ground.name == "filth:dirt_with_grass_walked" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
if n_ground.name == "default:dirt" then
if math.random(1, 100) <= odd then
minetest.env:add_node(p_ground,{type="node",name="filth:dirt_walked"})
end
end
-- reducing filth when not walking on dirt
if n_ground.name ~= "default:dirt" and n_ground.name ~= "filth:dirt_walked" then
if playersFilth[player:get_player_name()] > 0 then
playersFilth[player:get_player_name()] = playersFilth[player:get_player_name()] - 1
-- print (playersFilth[player:get_player_name()]) -- for debuging
end
end
-- reducing sand
if n_ground.name ~= "default:sand" then
if playersSand[player:get_player_name()] > 0 then
playersSand[player:get_player_name()] = playersSand[player:get_player_name()] - 1
end
end
-- reducing gravel
if n_ground.name ~= "default:gravel" then
if playersGravel[player:get_player_name()] > 0 then
playersGravel[player:get_player_name()] = playersGravel[player:get_player_name()] - 1
end
end
local n_playerpos = minetest.env:get_node(player_pos[player:get_player_name()])
if n_playerpos.name == "filth:mat" then
playersFilth[player:get_player_name()] = 0
playersSand[player:get_player_name()] = 0
playersGravel[player:get_player_name()] = 0
else
-- making filth
if n_ground.name == "default:wood" or n_ground.name == "default:stone" or n_ground.name == "default:cobble" then
if playersFilth[player:get_player_name()] > 0 then
if math.random(1, 100) <= odd then
local p_add_filth = { x=p_ground.x, y=p_ground.y+1, z=p_ground.z }
local n_add_filth = minetest.env:get_node(p_add_filth)
-- to not replace doors with filth
if n_add_filth.name == "air" then
minetest.env:add_node(p_add_filth,{type="node",name="filth:dirt"})
end
end
end
end
-- turning dirt and gravel into sand
if n_ground.name == "default:dirt" or n_ground.name == "default:gravel" or n_ground.name == "filth:dirt_walked" then
if playersSand[player:get_player_name()] > 0 then
local r_number = math.random(1, (200*max_distance))
local odd_temp = odd * playersSand[player:get_player_name()]
if r_number <= odd_temp then
minetest.env:add_node(p_ground,{type="node",name="default:sand"})
end
end
end
-- turning dirt and sand into gravel
if n_ground.name == "default:dirt" or n_ground.name == "default:sand" or n_ground.name == "filth:dirt_walked" then
if playersGravel[player:get_player_name()] > 0 then
local r_number = math.random(1, (200*max_distance))
local odd_temp = odd * playersGravel[player:get_player_name()]
if r_number <= odd_temp then
minetest.env:add_node(p_ground,{type="node",name="default:gravel"})
end
end
end
-- turning gravel and sand into dirt
if n_ground.name == "default:gravel" or n_ground.name == "default:sand" then
if playersFilth[player:get_player_name()] > 0 then
local r_number = math.random(1, (200*max_distance))
local odd_temp = odd * playersFilth[player:get_player_name()]
if r_number <= odd_temp then
minetest.env:add_node(p_ground,{type="node",name="default:dirt"})
end
end
end
end
end
-- making node to previous node
player_pos_previous[player:get_player_name()] = { x=player_pos[player:get_player_name()].x, y=player_pos[player:get_player_name()].y, z=player_pos[player:get_player_name()].z }
end
end)
Casimir wrote:Working with metadata seems to complicated for me, just to save one block. But you are free to do it if you want to.
Yet another version, close to finish.
Sand, gravel and dirt mix up when walking over. So your path to the beach gets sandy within time.
There is a Super-Mop for cleaning up.
Crafting:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
x | x
x | U
# # #
x=nothing, |=stick, #=wool, U=bucket of water
And a mat for getting your feet clean.Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
p p p
w w w
p=papyrus w=woodYour phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
-------Removed Code------
If now somebody tells me how to get the sound working, it could make it to release.
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
end)minetest.register_on_leaveplayer(function(player)
for i,v in ipairs(players) do
if v == player then
table.remove(players, i)
end
end
end)Echo wrote:@Casimir: you useYour phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_on_leaveplayer(function(player)
table.remove(players, player)
end)
That's wrong. I used it in my mod, too. (I copied these three lines from here) ;-).
You have to declare a position, not a value.
Use this:Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
minetest.register_on_leaveplayer(function(player)
for i,v in ipairs(players) do
if v == player then
table.remove(players, i)
end
end
end)
minetest.get_connected_players()Echo wrote:That's wrong. I used it in my mod, too. (I copied these three lines from here) ;-).
Casimir wrote:Echo wrote:That's wrong. I used it in my mod, too. (I copied these three lines from here) ;-).
And I taught I copied it from you...
@ PilzAdam
Can you tell me how exactly to use this?
Then I would fix the drowning-mod too. It has bugs over and over.
for _,player in ipairs(minetest.get_connected_players()) do
[code here]
end
Users browsing this forum: Bing [Bot] and 8 guests