Page 1 of 1

Need help for mod

PostPosted: Fri Dec 06, 2013 00:36
by diabolus
Mahlzeit!

I try to code my own mod for minetest. Some friends and I play Minetest on a private server and now I try to build mods for us. Maybe in futur for public release if I think its stabel and someone are interestet.

My first problem, I craft an new node and if I put them on the ground I can open it like a furnace oder cest ore something like that. I become an Inventory with some seperated lists like src, fuel and player inventory and a field for some input.

Now the input in the field shoud me saved in the node so I can use it, change it usw. Nothing I can do to save the entry. I try it like the sign in default but nothing. Whats the problem?

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
local bauer_inactive_formspec =
    "size[8,9]"..
    "label[1,0;Baumaterial]"..
    "label[1,2;Treibstoff]"..
    "field[4,1;4,3;terminal;Terminal;${text}]"..
    "list[current_name;fuel;2,3;1,1;]"..
    "list[current_name;src;2,1;1,1;]"..
    "list[current_player;main;0,5;8,4;]"

minetest.register_node("diabolus:helfer_bauer", {
        description = "Bauarbeiter",
        tiles = {"helfer_bauer.png"},
        walkable = true,
        light_source = 10,
        groups = {cracky=2, flammable=3},
        on_construct = function(pos)
            local meta = minetest.get_meta(pos)
            meta:set_string("formspec", bauer_inactive_formspec)
            meta:set_string("infotext", "Hornbach")
            local inv = meta:get_inventory()
            inv:set_size("fuel", 1)
            inv:set_size("src", 1)
        end,
        can_dig = function(pos,player)
            local meta = minetest.get_meta(pos);
            local inv = meta:get_inventory()
            if not inv:is_empty("fuel") then
                return false
                elseif not inv:is_empty("src") then
                    return false
            end
            return true
   
        end,
        on_receive_fields = function(pos, formname, fields, sender)
            local meta = minetest.get_meta(pos)
            meta:set_string("text", fields.text)
        end,
        allow_metadata_inventory_put = function(pos, listname, index, stack, player)
            local meta = minetest.get_meta(pos)
            local inv = meta:get_inventory()
            if listname == "fuel" then
                if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
                    if inv:is_empty("src") then
                        meta:set_string("infotext","Hornbach ist leer")
                    end
                    return stack:get_count()
                else
                    return 0
                end
            elseif listname == "src" then
                return stack:get_count()
            end
        end,
    })

PostPosted: Sat Dec 07, 2013 03:59
by minermoder27
In the formspec you say "field[4,1;4,3;>>>>>terminal<<<<<<;Terminal;${text}]"

This sets the text box's name "terminal".

In the code you need to change "meta:set_string("text", fields.text)" to "meta:set_string("terminal", fields.text)"

PostPosted: Sat Dec 07, 2013 13:15
by diabolus
Thx. I fix it yesterday. Sometimes its better to sleep one night and try it the day after ;)

PostPosted: Sun Dec 08, 2013 13:32
by diabolus
New problem.

If I fill an object with information (position, fuel, etc) I want that it move step by step to the position. But moveto() calls an error (nil value).

How I become an object to move?

PostPosted: Sun Dec 08, 2013 13:51
by webdesigner97
diabolus wrote:New problem.

If I fill an object with information (position, fuel, etc) I want that it move step by step to the position. But moveto() calls an error (nil value).

How I become an object to move?

Move_to only works for entities, not for nodes.

PostPosted: Sun Dec 08, 2013 14:02
by diabolus
lol ok. So I have to use setpos()?

PostPosted: Sun Dec 08, 2013 16:41
by webdesigner97
setpos() also only works for entities. You can't move nodes smoothly.

PostPosted: Sun Dec 08, 2013 16:42
by diabolus
The dont need to move smooth.

Can I change the position of an node?

PostPosted: Sun Dec 08, 2013 16:48
by webdesigner97
diabolus wrote:The dont need to move smooth.

Can I change the position of an node?

You can minetest.remove_node(pos) the old one and minetest.set_node(pos) the new one

PostPosted: Sun Dec 08, 2013 16:59
by diabolus
Thats the only way?

PostPosted: Mon Dec 09, 2013 08:43
by minermoder27
Yes, it is.

Look up how to turn the metadata and inventory into a table and then put that into a new node

PostPosted: Mon Dec 09, 2013 13:27
by diabolus
OK thx