On_rightclick action

Nekrofage
Member
 
Posts: 35
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

On_rightclick action

by Nekrofage » Mon Oct 24, 2016 19:04

Hi all !! :D

I want an 'on_rightclick' action on mesescons node, I have this 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
minetest.on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
        if node.name == "mesecons_switch:mesecon_switch_off" then
                local player_name = clicker:get_player_name()
                local mypos = minetest.pos_to_string(pos)
                minetest.chat_send_all(player_name .." is right-click on me. I'm located at ".. mypos)
        end
end


But it doesn't run... O_o

Do you have an good example?

Thank you
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: On_rightclick action

by BrandonReese » Mon Oct 24, 2016 20:56

You can add an on_rightclick to the node definition.
 

Nekrofage
Member
 
Posts: 35
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

Re: On_rightclick action

by Nekrofage » Mon Oct 24, 2016 22:15

Hi BrandonReese, Oky.

But finally, I use this 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
-- Use switch to on/off and use pick to change the value
minetest.register_tool("nekromod:pick_wood", {
       description = "Wooden Pickaxe Weapon",
       inventory_image = "default_tool_woodpick.png",
       tool_capabilities = {
       },
   -- Left button mouse
   on_use = function(itemstack, user, pointed_thing)
      local pos = pointed_thing.under
      if not pos then
         return itemstack
      end

      local meta = minetest.get_meta(pos)

      minetest.chat_send_all("on_use; x=" .. pos.x .. " y=" .. pos.y .. " z=" .. pos.z)

      return itemstack
   end,
   -- Right button mouse
       on_place = function(itemstack, user, pointed_thing)
      local pos = pointed_thing
      if not pos then
         return itemstack
      end

      minetest.chat_send_all("on_place")

           return itemstack
       end,
})


So my question, how to get the meta node?
 

User avatar
BrandonReese
Member
 
Posts: 836
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese

Re: On_rightclick action

by BrandonReese » Mon Oct 24, 2016 22:19

If you are creating a tool you can add on_secondary_use to your tool definition, it's just like on_use except it's executed when they right click.

To get meta use
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 meta = minetest.get_meta(pos)
 

Nekrofage
Member
 
Posts: 35
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

Re: On_rightclick action

by Nekrofage » Tue Oct 25, 2016 19:30

Thank you BrandonReese !!

It is very strange because the 'on_secondary_use' method doesn't run...

For information, my code is the following:
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
-- Left button mouse
   on_use = function(itemstack, user, pointed_thing)
      local pos = pointed_thing.under
      if not pos then
         return itemstack
      end

      local meta = minetest.get_meta(pos)

      local nodeName = minetest.get_node(pos).name

      minetest.chat_send_all("on_use; x=" .. pos.x .. " y=" .. pos.y .. " z=" .. pos.z .. " name=" .. nodeName)

      if nodeName  == "mesecons_switch:mesecon_switch_on" then
         minetest.set_node({x=pos.x, y=pos.y, z=pos.z }, {name="mesecons_switch:mesecon_switch_off"})
      else
         minetest.set_node({x=pos.x, y=pos.y, z=pos.z }, {name="mesecons_switch:mesecon_switch_on"})
      end

      return itemstack
   end,
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron