placing nodes with on_construct

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

placing nodes with on_construct

by qwrwed » Wed Jul 24, 2013 15:24

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.
Last edited by qwrwed on Thu Jul 25, 2013 11:41, edited 1 time in total.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Jul 24, 2013 15:40

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})
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

by Sokomine » Wed Jul 24, 2013 15:46

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.
A list of my mods can be found here.
 

User avatar
PilzAdam
Member
 
Posts: 4026
Joined: Fri Jul 20, 2012 16:19
GitHub: PilzAdam
IRC: PilzAdam

by PilzAdam » Wed Jul 24, 2013 15:49

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.
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Wed Jul 24, 2013 15:58

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?
 

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Wed Jul 24, 2013 16:39

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.
 

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Wed Jul 24, 2013 16:44

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.
Last edited by qwrwed on Wed Jul 24, 2013 16:45, edited 1 time in total.
 

User avatar
webdesigner97
Member
 
Posts: 1307
Joined: Mon Jul 30, 2012 19:16
GitHub: webD97
IRC: webdesigner97
In-game: webdesigner97

by webdesigner97 » Wed Jul 24, 2013 17:10

Which line is 146?
 

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Wed Jul 24, 2013 18:43

(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.
Last edited by qwrwed on Wed Jul 24, 2013 19:11, edited 1 time in total.
 

User avatar
qwrwed
Member
 
Posts: 323
Joined: Sun Jul 22, 2012 20:56
In-game: qwrwed or Nitro

by qwrwed » Thu Jul 25, 2013 11:41

How do I place a node (with facedir) on_construct?
(see first post for more details)
 


Return to WIP Mods

Who is online

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

cron