Page 1 of 1

placing nodes with on_construct

PostPosted: Wed Jul 24, 2013 15:24
by qwrwed
I am going to try and place 6 nodes with only one placed by the player, but I don't know how to use on_construct to place nodes. Right now I am using after_place_node, but that only works for adding a second node because there is no placer to activate the "after_place_node" function for any more. How do I place a node (with facedir) on_construct?
qwrwed wrote:How do I use add_node or set_node to create other nodes? i am making a plasma screen TV mod which has 6 nodes, arranged like this:
1 2 3
4 5 6
5 is the node that is placed, and when the player places it the other 5 nodes should generate. However, I don't know how to do this, and looking in the code for the stargate mod, doors mod and beds mod did not help - the first two were too complicated for this, and I don't even know where I'm going wrong using code from beds, so I would like to start from scratch. The nodes (which are nodeboxes) are plasmascreen:screen1, plasmascreen:screen2 etc. up to plasmascreen:screen6.

PostPosted: Wed Jul 24, 2013 15:40
by PilzAdam
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
-- pos is the position of the "5" node in the format {x=1, y=2 z=3}
pos.y = pos.y + 1
minetest.set_node(pos, {name="tv:screen_2})

PostPosted: Wed Jul 24, 2013 15:46
by Sokomine
If your plasma screen ought to switch pictures/channels like the TV from homedecor or the TV from Redcrabs server, perhaps you ought to take a diffrent approach and just make the nodebox larger than one node. That does work. Sideeffects are that nodes may really overlap.

PostPosted: Wed Jul 24, 2013 15:49
by PilzAdam
Sokomine wrote:If your plasma screen ought to switch pictures/channels like the TV from homedecor or the TV from Redcrabs server, perhaps you ought to take a diffrent approach and just make the nodebox larger than one node. That does work. Sideeffects are that nodes may really overlap.

And the texture just repeats itself, wich doesnt look good.

PostPosted: Wed Jul 24, 2013 15:58
by webdesigner97
If you need your manually placed node to facedir, make sure to add param2 to the node:

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
    after_place_node = function(pos,placer,itemstack)
        --Don't forget to modify the <pos> table
        minetest.set_node(pos,{name="bla", param2=minetest.dir_to_facedir(placer:get_look_dir())})
    end


And for changing pictures: Why not use a texture animation?

PostPosted: Wed Jul 24, 2013 16:39
by qwrwed
Thanks webdesigner and PilzAdam, I will try that. Sokomine, I did that after making the first 6 nodes (it seemed simpler than using set_node) but I found that even when using a 32x48 texture, it just reverted to 6 16x16 textures. As for animation, I'm not that good with textures (maybe I will ask VanessaE) so I'll try to get the placement of the TV and a stand for it first. Currently, I have used black for the borders and dark grey for the screen.

PostPosted: Wed Jul 24, 2013 16:44
by qwrwed
I get this error:
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
17:42:54: ERROR[main]: ServerError: LuaError: error: ...cuments\minetest-0.4.7\bin\..\mods\plasmascreen\init.lua:146: calling 'get_node' on bad self (table expected, got userdata)

The definition with the after_place_node is this:
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("plasmascreen:screen5", {
    description = "Plasma TV",
    tiles = {"plasmascreen_screen.png", "plasmascreen_back.png", "plasmascreen_screen.png", "plasmascreen_screen.png", "plasmascreen_back.png", "plasmascreen_screen5.png"},
    paramtype = "light",
    paramtype2 = "facedir",
    drawtype = "nodebox",
    node_box = {
                type = "fixed",
                fixed = {
                            {-0.5000, -0.5000, 0.4375, 0.5000, 0.5000, 0.5000},
                            {-0.5000, -0.5000, 0.3750, 0.5000, -0.3125, 0.4375},
                        }
    },
        selection_box = {
                type = "fixed",
                fixed = {
                            {-0.5000, -0.5000, 0.4375, 0.5000, 0.5000, 0.5000},
                            {-0.5000, -0.5000, 0.3750, 0.5000, -0.3125, 0.4375},
                        }
    },
    groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2},
       
 after_place_node = function(pos,placer,itemstack)
        pos.y = pos.y + 1
        minetest.set_node(pos,{name="plasmascreen:screen2", param2=minetest.dir_to_facedir(placer:get_look_dir())})
    end
})

This happened when I tried to modify the papyrus_bed/beds code as well.

PostPosted: Wed Jul 24, 2013 17:10
by webdesigner97
Which line is 146?

PostPosted: Wed Jul 24, 2013 18:43
by qwrwed
(previous problem solved)
Another problem: when I place screen5, screen4 appears to the left of it as planned, but instead of appearing to the right, screen6 appears in place of screen5. Here is the 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
after_place_node = function(pos,placer,itemstack)
    local param2 = minetest.get_node(pos).param2
        if param2 == 0 then
            pos.x = pos.x-1
        minetest.set_node(pos,{name="plasmascreen:screen4", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 1 then
            pos.z = pos.z+1
        minetest.set_node(pos,{name="plasmascreen:screen4", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 2 then
            pos.x = pos.x+1
        minetest.set_node(pos,{name="plasmascreen:screen4", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 3 then
            pos.z = pos.z-1
        minetest.set_node(pos,{name="plasmascreen:screen4", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        end
    local param2 = minetest.get_node(pos).param2
        if param2 == 0 then
            pos.x = pos.x+1
        minetest.set_node(pos,{name="plasmascreen:screen6", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 1 then
            pos.z = pos.z-1
        minetest.set_node(pos,{name="plasmascreen:screen6", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 2 then
            pos.x = pos.x-1
        minetest.set_node(pos,{name="plasmascreen:screen6", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        elseif param2 == 3 then
            pos.z = pos.z+1
        minetest.set_node(pos,{name="plasmascreen:screen6", param2=minetest.dir_to_facedir(placer:get_look_dir())})
        end
    end
})

Everything before the first "end" works fine.
Also, the nodes I place aren't being saved when I exit the world, although it is recorded in the terminal.

PostPosted: Thu Jul 25, 2013 11:41
by qwrwed
How do I place a node (with facedir) on_construct?
(see first post for more details)