Page 1 of 1

on_walk_over event for nodes

PostPosted: Mon Nov 21, 2016 23:41
by lordfingle
Image

Some mode developers have shown an interest in having an on_walk_over event. This is useful for pressure-plates and the like.

See this issue - https://github.com/minetest/minetest/issues/247

I have implemented a server_side version in lua using globalstep which people might find useful. Of course this would better implemented via a client-based "on walk over", but it is sufficient for my needs now.

Latest downloadable version now as a WIP mod at viewtopic.php?f=9&t=15991&p=241701#p241701

Example Usage:

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("somemod:someblock", {

       description = key,
       tiles = {"somemod_someblock.png"},
           groups = {cracky=1},
             on_walk_over = function(pos, node, player)
           
                    minetest.chat_send_player(player, "Hey! Watch it!")
             end
})


Here's the code:

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
local timer = 0
minetest.register_globalstep(function(dtime)
   timer = timer + dtime;
   if timer >= 1 then
      for _,player in pairs(minetest.get_connected_players()) do
            local loc = vector.add(player:getpos(),{x=0,y=-1,z=0})
            if loc ~= nil then
               
                local nodeiamon = minetest.get_node(loc)
                if nodeiamon ~= nil then
                    local def = minetest.registered_nodes[nodeiamon.name]
                    if def ~= nil and def.on_walk_over ~= nil then
                        def.on_walk_over(loc, nodeiamon, player)
                    end
                end   
            end
        end
   
      timer = 0
   end
end)

Re: on_walk_over event for nodes

PostPosted: Fri Nov 25, 2016 04:46
by octacian
Neat! I wanted to use something like this for a teleporter and several other things, but I didn't know how. Can't wait till client side Lua gets fully implemented, but until then, this will definitely help. I didn't know it took that little to do that...

Re: on_walk_over event for nodes

PostPosted: Sun Nov 27, 2016 11:50
by lordfingle
Glad it helps. I use it for quite a few things and it works fine for now.

Re: on_walk_over event for nodes

PostPosted: Sun Nov 27, 2016 22:35
by Byakuren
This doesn't need client-side lua for it to be implemented in engine, the client would just send a message when it walks over a node with the thing defined. Something implemented like that would probably be rejected in anticipation of client-side scripting, though.

Re: on_walk_over event for nodes

PostPosted: Fri Dec 02, 2016 23:41
by Wuzzy
This seems useful. Can you please post this as a proper mod in WIP Mods?

Re: on_walk_over event for nodes

PostPosted: Mon Dec 05, 2016 23:19
by lordfingle