Need help for mod

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

Need help for mod

by diabolus » Fri Dec 06, 2013 00:36

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

User avatar
minermoder27
Member
 
Posts: 127
Joined: Wed Nov 20, 2013 23:24
GitHub: ZNixian
In-game: minermoder27

by minermoder27 » Sat Dec 07, 2013 03:59

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)"
Last edited by minermoder27 on Sat Dec 07, 2013 03:59, edited 1 time in total.
My best mods:
Buildtest
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Sat Dec 07, 2013 13:15

Thx. I fix it yesterday. Sometimes its better to sleep one night and try it the day after ;)
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Sun Dec 08, 2013 13:32

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?
 

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

by webdesigner97 » Sun Dec 08, 2013 13:51

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.
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Sun Dec 08, 2013 14:02

lol ok. So I have to use setpos()?
 

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

by webdesigner97 » Sun Dec 08, 2013 16:41

setpos() also only works for entities. You can't move nodes smoothly.
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Sun Dec 08, 2013 16:42

The dont need to move smooth.

Can I change the position of an node?
 

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

by webdesigner97 » Sun Dec 08, 2013 16:48

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
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Sun Dec 08, 2013 16:59

Thats the only way?
 

User avatar
minermoder27
Member
 
Posts: 127
Joined: Wed Nov 20, 2013 23:24
GitHub: ZNixian
In-game: minermoder27

by minermoder27 » Mon Dec 09, 2013 08:43

Yes, it is.

Look up how to turn the metadata and inventory into a table and then put that into a new node
My best mods:
Buildtest
 

diabolus
New member
 
Posts: 7
Joined: Fri Dec 06, 2013 00:30

by diabolus » Mon Dec 09, 2013 13:27

OK thx
 


Return to WIP Mods

Who is online

Users browsing this forum: Google [Bot] and 5 guests

cron