Page 1 of 1

How to?

PostPosted: Wed Jun 29, 2016 12:51
by azekill_DIABLO
how to make a node become another one on_rightclick?

Re: How to?

PostPosted: Wed Jun 29, 2016 15:32
by addi
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 function on_rightclick
(pos, node, player, pointed_thing)
minetest.swap_node(pos,{name="new:node"})
end

minetest
.register_node("default:stone", {
    description = "Stone",
    tiles = {"default_stone.png"},
    is_ground_content = true,
    groups = {cracky=3, stone=1},
    drop = 'default:cobble',
    legacy_mineral = true,
    on_rightclick = on_rightclick,
})
 

(untested)
http://dev.minetest.net/minetest.swap_node
http://dev.minetest.net/minetest.register_node

Re: How to?

PostPosted: Wed Jun 29, 2016 15:53
by azekill_DIABLO
omg it was so simple it's actually what i've done but missed only one thing :{
thank you!

Re: How to?

PostPosted: Wed Jun 29, 2016 15:54
by azekill_DIABLO
and if i want to do it backwards?

Re: How to?

PostPosted: Wed Jun 29, 2016 16:00
by addi
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 function on_rightclick(pos, node, player, pointed_thing)
   if node.name == "mod:node_1" then
       node
.name = "mod:node_2"
   else if node.name == "mod:node_2" then
       node
.name = "mod:node_1"
   end
  minetest
.swap_node(pos,node)
end

minetest
.register_node("mod:node_1", {
    description = "Stone",
    tiles = {"default_stone.png"},
    is_ground_content = true,
    groups = {cracky=3, stone=1},
    drop = 'default:cobble',
    legacy_mineral = true,
    on_rightclick = on_rightclick,
})

minetest.register_node("mod:node_2", {
    description = "Stone 2",
    tiles = {"default_stone.png"},
    is_ground_content = true,
    groups = {cracky=3, stone=1},
    drop = 'default:cobble',
    legacy_mineral = true,
    on_rightclick = on_rightclick,
})

Re: How to?

PostPosted: Wed Jun 29, 2016 16:02
by azekill_DIABLO
thank you addi :)

Re: How to?

PostPosted: Wed Jun 29, 2016 16:03
by azekill_DIABLO
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 function on_rightclick(pos, node, player, pointed_thing)
   if node.name == name then
   minetest.swap_node(pos,{name="doors:door"})
   elseif not node.name == name then
   minetest.swap_node(pos,{name="doors:door_opened"})
   end
end


this was my code :)

EDIT: your code is missing and end because you used else if and not elseif

Re: How to?

PostPosted: Wed Jun 29, 2016 16:10
by azekill_DIABLO
the code does not work :(
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 function on_rightclick(pos, node, player, pointed_thing)
   if node.name == "doors:door" then
      node.name = "doors:door_opened"
   else if node.name == "doors:door_opened" then
      node.name = "doors:door"
   end
   minetest.swap_node(pos,node)
   end
end

minetest.register_node("doors:door", {
   description = "Door",
   tiles = {
      "default_wood.png",
   },
   drawtype = "mesh",
   paramtype = "light",
   mesh = "door.obj",
   visual_scale = 0.8,
   is_ground_content = false,
   groups = {snappy = 3},
   sounds =  default.node_sound_wood_defaults(),
   on_rightclick = on_rightclick,
})

minetest.register_node("doors:door_opened", {
   description = "Door Opened",
   tiles = {
      "default_wood.png",
   },
   drawtype = "mesh",
   paramtype = "light",
   mesh = "door_opened.obj",
   visual_scale = 0.8,
   is_ground_content = false,
   groups = {snappy = 3, not_in_creative_inventory = 1},
   sounds =  default.node_sound_wood_defaults(),
   on_rightclick = on_rightclick,
})

Re: How to?

PostPosted: Wed Jun 29, 2016 18:59
by Krock
@azekill_DIABLO
Line 8: There's an "end" too much. Remove it and try again.

Re: How to?

PostPosted: Wed Jun 29, 2016 20:43
by pithy
You are overcomplicating everything. Try using...
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("doors:door", {
   description = "Door",
   tiles = {
      "default_wood.png",
   },
   drawtype = "mesh",
   paramtype = "light",
   mesh = "door.obj",
   visual_scale = 0.8,
   is_ground_content = false,
   groups = {snappy = 3},
   sounds =  default.node_sound_wood_defaults(),
   on_rightclick = function(pos, node, player, pointed_thing)
      minetest.swap_node(pos, {name = "doors:door_opened"})
   end,
})

minetest.register_node("doors:door_opened", {
   description = "Door Opened",
   tiles = {
      "default_wood.png",
   },
   drawtype = "mesh",
   paramtype = "light",
   mesh = "door_opened.obj",
   visual_scale = 0.8,
   is_ground_content = false,
   groups = {snappy = 3, not_in_creative_inventory = 1},
   sounds =  default.node_sound_wood_defaults(),
   on_rightclick = function(pos, node, player, pointed_thing)
      minetest.swap_node(pos, {name = "doors:door"})
   end,
})

Re: How to?

PostPosted: Thu Jun 30, 2016 09:32
by azekill_DIABLO
ok thanks.

Re: How to?

PostPosted: Thu Jun 30, 2016 09:39
by azekill_DIABLO
it's working! thank you guys! YOU are AWESOME!