From Minetest Developer Wiki
Jump to navigation Jump to search


<source>minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing))</source>


Called when a node is punched.

Example 1

<source>minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) if puncher:get_wielded_item():get_name() == "moretools:pick" and node.name ~= "air" then minetest.remove_node(pos) puncher:get_inventory():add_item('main', node) end end)</source>

Example 2

<source>minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing) if node.name == "default:brick" then local puncher_name = puncher:get_player_name() local mypos = minetest.pos_to_string(pos) -- Sets variable to (X,Y,Z.. where Y is up) minetest.chat_send_all("Hey!! ".. puncher_name .." is hitting me. I'm located at ".. mypos .." Send help!!") end if node.name == "default:desert_stonebrick" then local puncher_name = puncher:get_player_name() minetest.chat_send_player(puncher_name, "That's got to hurt!!") end end) </source> If the player punches a default:brick, minetest will send chat message to all online players advising them that a particular player has punched the node. If a default:desert_stonebrick node has been punched, the server sends a message to the player only.