on_walk_over event for nodes

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

on_walk_over event for nodes

by lordfingle » Mon Nov 21, 2016 23:41

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)
Attachments
Banana_Peel.JPG
Banana_Peel.JPG (150.51 KiB) Viewed 1126 times
Last edited by lordfingle on Mon Dec 05, 2016 23:20, edited 1 time in total.
----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 

User avatar
octacian
Member
 
Posts: 408
Joined: Mon Dec 21, 2015 22:18
GitHub: octacian
IRC: octacian
In-game: octacian

Re: on_walk_over event for nodes

by octacian » Fri Nov 25, 2016 04:46

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...
God isn't dead!

My Coolest Mods:
MicroExpansion, Working Computers, Interchangeable Hands

Check out my YouTube channel! (octacian)
 

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

Re: on_walk_over event for nodes

by lordfingle » Sun Nov 27, 2016 11:50

Glad it helps. I use it for quite a few things and it works fine for now.
----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 

Byakuren
Member
 
Posts: 441
Joined: Tue Apr 14, 2015 01:59
GitHub: raymoo
IRC: Hijiri

Re: on_walk_over event for nodes

by Byakuren » Sun Nov 27, 2016 22:35

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.
Every time a mod API is left undocumented, a koala dies.
 

User avatar
Wuzzy
Member
 
Posts: 2161
Joined: Mon Sep 24, 2012 15:01
GitHub: Wuzzy2
IRC: Wuzzy
In-game: Wuzzy

Re: on_walk_over event for nodes

by Wuzzy » Fri Dec 02, 2016 23:41

This seems useful. Can you please post this as a proper mod in WIP Mods?
I'm creating MineClone 2, a Minecraft clone for Minetest.
I made the Help modpack, adding in-game help to Minetest.
 

User avatar
lordfingle
Member
 
Posts: 65
Joined: Sat Apr 04, 2015 09:21
GitHub: eidy
IRC: lordfingle
In-game: lordfingle

Re: on_walk_over event for nodes

by lordfingle » Mon Dec 05, 2016 23:19

----------------------------------------------------------------------------------------------
Team Lead on "eidy- Love learning"
I like reading, walks on the beach and building edutech experiences in lua (Find out more in this post)
"Coming together is a beginning; keeping together is progress; working together is success." - Henry Ford
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 58 guests

cron