block gives you item when you click it
block gives you item when you click it
Does anyone know how I do this? It needs to be infinite.
Testin' mines since 1989
- Krock
- Developer
- Posts: 4650
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: block gives you item when you click it
Unclear instructions whether it should happen on right-click or on punch. However, here's a code example that gives the player 1 gold when punching and 1 steel when right-clicking.
Untested, but will work most likely.
Code: Select all
minetest.register_node("mymod:mynode", {
-- .. other fields
on_punch = function(pos, node, puncher, pointed_thing)
if not (puncher and puncher:is_player()) then
return -- punched by a non-player
end
local inv = puncher:get_inventory()
inv:add_item("main", ItemStack("default:gold_ingot 1"))
minetest.log("action", "Ouch! I was punched by "
.. puncher:get_player_name())
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not (clicker and clicker:is_player()) then
return -- right-clicked by a non-player
end
local inv = clicker:get_inventory()
inv:add_item("main", ItemStack("default:steel_ingot 1"))
minetest.log("action", "Huh? I was right-clicked by "
.. clicker:get_player_name())
end,
})
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
Re: block gives you item when you click it
Thank you! That’s perfect! I needed the right click one.Krock wrote:Unclear instructions whether it should happen on right-click or on punch. However, here's a code example that gives the player 1 gold when punching and 1 steel when right-clicking.Untested, but will work most likely.Code: Select all
minetest.register_node("mymod:mynode", { -- .. other fields on_punch = function(pos, node, puncher, pointed_thing) if not (puncher and puncher:is_player()) then return -- punched by a non-player end local inv = puncher:get_inventory() inv:add_item("main", ItemStack("default:gold_ingot 1")) minetest.log("action", "Ouch! I was punched by " .. puncher:get_player_name()) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not (clicker and clicker:is_player()) then return -- right-clicked by a non-player end local inv = clicker:get_inventory() inv:add_item("main", ItemStack("default:steel_ingot 1")) minetest.log("action", "Huh? I was right-clicked by " .. clicker:get_player_name()) end, })
Testin' mines since 1989
Re: block gives you item when you click it
Thank you! That’s perfect! I needed the right click one.Krock wrote:Unclear instructions whether it should happen on right-click or on punch. However, here's a code example that gives the player 1 gold when punching and 1 steel when right-clicking.Untested, but will work most likely.Code: Select all
minetest.register_node("mymod:mynode", { -- .. other fields on_punch = function(pos, node, puncher, pointed_thing) if not (puncher and puncher:is_player()) then return -- punched by a non-player end local inv = puncher:get_inventory() inv:add_item("main", ItemStack("default:gold_ingot 1")) minetest.log("action", "Ouch! I was punched by " .. puncher:get_player_name()) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not (clicker and clicker:is_player()) then return -- right-clicked by a non-player end local inv = clicker:get_inventory() inv:add_item("main", ItemStack("default:steel_ingot 1")) minetest.log("action", "Huh? I was right-clicked by " .. clicker:get_player_name()) end, })
Testin' mines since 1989
Re: block gives you item when you click it
I get an error: unexpected symbol near ‘}’ on the last line of code. I’ve looked for mistakes but I copied it exactly (except for my stuff) any ideas?Krock wrote:Unclear instructions whether it should happen on right-click or on punch. However, here's a code example that gives the player 1 gold when punching and 1 steel when right-clicking.Untested, but will work most likely.Code: Select all
minetest.register_node("mymod:mynode", { -- .. other fields on_punch = function(pos, node, puncher, pointed_thing) if not (puncher and puncher:is_player()) then return -- punched by a non-player end local inv = puncher:get_inventory() inv:add_item("main", ItemStack("default:gold_ingot 1")) minetest.log("action", "Ouch! I was punched by " .. puncher:get_player_name()) end, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) if not (clicker and clicker:is_player()) then return -- right-clicked by a non-player end local inv = clicker:get_inventory() inv:add_item("main", ItemStack("default:steel_ingot 1")) minetest.log("action", "Huh? I was right-clicked by " .. clicker:get_player_name()) end, })
Testin' mines since 1989
- Krock
- Developer
- Posts: 4650
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: block gives you item when you click it
If removing the tailing comma before '}' (comma on the line above) does not help, paste the code. Otherwise I'll not be able to help you.Joseph13 wrote:I get an error: unexpected symbol near ‘}’ on the last line of code. I’ve looked for mistakes but I copied it exactly (except for my stuff) any ideas?
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
Re: block gives you item when you click it
Ok thanks!Krock wrote:If removing the tailing comma before '}' (comma on the line above) does not help, paste the code. Otherwise I'll not be able to help you.Joseph13 wrote:I get an error: unexpected symbol near ‘}’ on the last line of code. I’ve looked for mistakes but I copied it exactly (except for my stuff) any ideas?
Testin' mines since 1989
Re: block gives you item when you click it
I re-copied it and looked it all and realized I had it all wrong. After fixing it I get a new error: ‘end’ expected (to close ‘if’ at line 11) near ‘by’. Can you re wright the code? I’m so lost!Krock wrote:If removing the tailing comma before '}' (comma on the line above) does not help, paste the code. Otherwise I'll not be able to help you.Joseph13 wrote:I get an error: unexpected symbol near ‘}’ on the last line of code. I’ve looked for mistakes but I copied it exactly (except for my stuff) any ideas?
Testin' mines since 1989
- GamingAssociation39
- Member
- Posts: 858
- Joined: Mon Apr 25, 2016 16:09
- GitHub: Gerold55
- IRC: Gerold55
- In-game: Gerold55
- Location: Maryland, USA
Re: block gives you item when you click it
Joseph13 wrote:I re-copied it and looked it all and realized I had it all wrong. After fixing it I get a new error: ‘end’ expected (to close ‘if’ at line 11) near ‘by’. Can you re wright the code? I’m so lost!Krock wrote:If removing the tailing comma before '}' (comma on the line above) does not help, paste the code. Otherwise I'll not be able to help you.Joseph13 wrote:I get an error: unexpected symbol near ‘}’ on the last line of code. I’ve looked for mistakes but I copied it exactly (except for my stuff) any ideas?
Code: Select all
minetest.register_node("mymod:mynode", {
-- .. other fields
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
if not (clicker and clicker:is_player()) then
return -- right-clicked by a non-player
end
local inv = clicker:get_inventory()
inv:add_item("main", ItemStack("default:steel_ingot 1"))
minetest.log("action", "Huh? I was right-clicked by "
.. clicker:get_player_name())
end,
})
Jesus Is Lord and Savior!!!
Who is online
Users browsing this forum: No registered users and 5 guests