Page 1 of 1

[SOLVED] Help on on_step

PostPosted: Mon Aug 20, 2012 22:58
by rubenwardy
How does on step work?
I have a node called traps:cage and i want to know when someone walks on it.

The lua_api.txt says: on_step(self,dtime)

My current code is:

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_node(":traps:cage",{
    tile_images = {"default_grass.png", "default_dirt.png",
            "default_grass_side.png", "default_grass_side.png",
            "default_grass_side.png", "default_grass_side.png"},
    inventory_image = minetest.inventorycube("default_grass.png",
            "default_grass_side.png", "default_grass_side.png"),
    dug_item = '', -- Get nothing
    groups={immortal},
    description = "Mine Trap",

on_step=function(pos)
print("[Traps:Cage] Activated")
minetest.env:add_node(pos,{name="default:dirt"})

local tmp={pos.x-1,pos.y+1,pos.z}
minetest.env:add_node(tmp,{name="default:glass"})

end,
})

PostPosted: Mon Aug 20, 2012 23:08
by PilzAdam
You cant use this in a node definition.

PostPosted: Mon Aug 20, 2012 23:12
by rubenwardy
ok, how do you do it?

PostPosted: Mon Aug 20, 2012 23:23
by jin_xi
you can create a list of traps, and add a traps position to that list when you place a trap. use table.insert in the traps node definitions on_construct function.

then you need to check if players are in range of a trap. you can register your own functions to be run periodically.
minetest.register_on_globalstep does that. supply a function that checks if a player is in range of a trap.

hope this helps and there may be better ways to do this...

PostPosted: Tue Aug 21, 2012 08:01
by Casimir
Take a look at the pressureplates of the mesecon-mod.

PostPosted: Tue Aug 21, 2012 09:04
by rubenwardy
Thank you. It works!

So much easier, thank you to all replyers