On_rightclick action

Post Reply
Nekrofage
Member
Posts: 52
Joined: Mon Oct 17, 2016 21:12
GitHub: Nekrofage

On_rightclick action

by Nekrofage » Post

Hi all !! :D

I want an 'on_rightclick' action on mesescons node, I have this code:

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: 839
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese
Location: USA

Re: On_rightclick action

by BrandonReese » Post

You can add an on_rightclick to the node definition.

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

Re: On_rightclick action

by Nekrofage » Post

Hi BrandonReese, Oky.

But finally, I use this code :

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: 839
Joined: Wed Sep 12, 2012 00:44
GitHub: bremaweb
IRC: BrandonReese
In-game: BrandonReese
Location: USA

Re: On_rightclick action

by BrandonReese » Post

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

Code: Select all

local meta = minetest.get_meta(pos)

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

Re: On_rightclick action

by Nekrofage » Post

Thank you BrandonReese !!

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

For information, my code is the following:

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,

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests