Post your modding questions here

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Sat Mar 02, 2013 22:07

how to manipulate images through lua?
sorry for bad english
Linux debian 7 wheezy 64
kde
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Sun Mar 03, 2013 05:59

Actual manipulation of images may not be possible. For example, I don't think you can get a pixel array and set pixels or draw arbitrary shapes. However, in places you are asked for a texture name, you may be able to do some simple manipulations using a custom Minetest texture specification language in place of a simple filename.
 

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40

by 1244 » Sat Mar 16, 2013 20:45

In which way I can add meta float from node to formspec this node? Example:

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
x_formspec =
"invsize[8,9;]"..
"label[1,3;Variable_from_node]"

minetest.register_node("X:x", {
local Variable_from_node = 10
})

In which way I can do this?
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Sat Mar 16, 2013 20:58

1244 wrote:In which way I can add meta float from node to formspec this node? Example:

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
x_formspec =
"invsize[8,9;]"..
"label[1,3;Variable_from_node]"

minetest.register_node("X:x", {
local Variable_from_node = 10
})

In which way I can do this?

I think you can do something like 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
"label[1,3;$(Variable_from_node)]"

Also, the 'local' inside the table is wrong; remove it.
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

User avatar
10twenty4
Member
 
Posts: 40
Joined: Tue Mar 12, 2013 20:54

by 10twenty4 » Sun Mar 17, 2013 21:57

I'm trying to remove whatever you're holding onto when you punch a node. I'm not seeing any change occur, however. Should I be using something besides take_item()?

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
on_punch = function(pos, node, puncher)
            wield = puncher:get_wielded_item()
            print(wield: get_count())
            wield:take_item()
            print(wield: get_count())
            end


edit: scratch that, I fixed it by adding puncher: set_wielded_item(wield)
Last edited by 10twenty4 on Sun Mar 17, 2013 22:50, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Sun Mar 17, 2013 23:55

Calling "take_item()" will change the local ItemStack you have in your function there, but the API actually passes ItemStacks around by value (copies) rather than by reference. So you have to tell the API to do something with the modified ItemStack. For example, you could pass it back to ObjectRef:set_wielded_item(...).
 

User avatar
10twenty4
Member
 
Posts: 40
Joined: Tue Mar 12, 2013 20:54

by 10twenty4 » Mon Mar 18, 2013 23:28

I'm trying to create a menu when you right click a node. I believe I'm doing this correctly (adding a formspec to the metadata), but nothing happens. I've tried copying the line from the furnace code and other examples, but that doesn't work either. I'm assuming I'm missing something, but I don't know what.

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
on_construct= function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec",
                "size[8,9]"..
        "list[current_name;fuel;2,3;1,1;]"..
        "list[current_player;main;0,5;8,4]"
        )
        meta:set_string("infotext", "Campfire")
        local inv = meta:get_inventory()
        inv:set_size("fuel",1)

    end,
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

by Evergreen » Tue Mar 19, 2013 00:44

10twenty4 wrote:I'm trying to create a menu when you right click a node. I believe I'm doing this correctly (adding a formspec to the metadata), but nothing happens. I've tried copying the line from the furnace code and other examples, but that doesn't work either. I'm assuming I'm missing something, but I don't know what.

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
on_construct= function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec",
                "size[8,9]"..
        "list[current_name;fuel;2,3;1,1;]"..
        "list[current_player;main;0,5;8,4]"
        )
        meta:set_string("infotext", "Campfire")
        local inv = meta:get_inventory()
        inv:set_size("fuel",1)

    end,
Exactly what I was going to ask.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
10twenty4
Member
 
Posts: 40
Joined: Tue Mar 12, 2013 20:54

by 10twenty4 » Tue Mar 19, 2013 02:03

This time, I'm trying to have a craftitem decrement by one when used on a 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
on_use = function(itemstack, user, pointed_thing)
            if pointed_thing.type == "node" then
                itemstack: take_item()
                user:set_wielded_item(itemstack)
            end
        end
    })


I've done a bit of testing, and it appears that while user's wielded item is decremented, user is a different object from the player, so the player's inventory is unaffected. Can you recommend a way around that?

edit: nvrmind, I just released I can use return itemstack
Last edited by 10twenty4 on Tue Mar 19, 2013 02:24, edited 1 time in total.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Tue Mar 19, 2013 04:47

If the formspec is badly formed, nothing happens. Silent failure. And unfortunately the documentation for formspecs is a little inconsistent and wrong. I believe you'll need a semicolon at the name of the player's list, just like the node inventory's list.
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Tue Mar 26, 2013 14:54

There is already a way to check for a collision between two objects?
sorry for bad english
Linux debian 7 wheezy 64
kde
 

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

by Sokomine » Tue Mar 26, 2013 15:19

Ask sapier. AFAIK he was working on something like that or at least knows where to look. Perhaps a patch is even linked in the mobf-thread. The mobf mobs do at least detect collusion with ground/nodes even without that patch.
A list of my mods can be found here.
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Tue Mar 26, 2013 15:30

thanks for now!
sorry for bad english
Linux debian 7 wheezy 64
kde
 

User avatar
Likwid H-Craft
Member
 
Posts: 1113
Joined: Sun Jan 06, 2013 14:20

by Likwid H-Craft » Wed Mar 27, 2013 15:54

I am try make a info box show a node/item/block in a menu so how do I make it work plus I like it have text here code.


[lua]
minetest.register_node("ibox:info_box", {
description = "Info Box",
tiles = {"ibox_info_box.png"},
is_ground_content = true,
groups = {cracky=3,fleshy=2},
drop = 'default:bookshelf 7', 'default:mese_crystal_fragment 2',
on_construct = function(pos)
--local n = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", "field[text;;${text}]")
meta:set_string("infotext", "\"\"")
end,
on_receive_fields = function(pos, formname, fields, sender)
--print("Sign at "..minetest.pos_to_string(pos).." got "..dump(fields))
local meta = minetest.env:get_meta(pos)
fields.text = fields.text or ""
print((sender:get_player_name() or "").. wrote \""..fields.text..
"\" to sign at "..minetest.pos_to_string(pos))
meta:set_string("text", fields.text)
meta:set_string("infotext", '"'..fields.text..'"')
end,
})
[/lua]

I edit made the color text so make it just like, as if it the real deal :) and you don't know how long it took me, to edit the text have the right color...

Oh and, How I make the block drop 2 thing not one.
Last edited by Likwid H-Craft on Wed Mar 27, 2013 15:57, edited 1 time in total.
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)
 

bentleysb
Member
 
Posts: 18
Joined: Sat Feb 09, 2013 02:18

by bentleysb » Thu Mar 28, 2013 19:53

I am trying to make it so when a block is placed then 2 other blocks are placed to the right and left of that block (resulting in a 3 x 1 panel) here is what I have so far:

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 on_place_trans = function(pos, node, placer)
        if node.name == 'mod:panel_center'then
        fdir = minetest.dir_to_facedir(placer:get_look_dir())
        minetest.env:add_node({x=pos.x+1, y=pos.y, z=pos.z}, { name = "mod:panel_right", paramtype2='none', param2=fdir})
        nodeupdate(pos)
        minetest.env:add_node({x=pos.x-1, y=pos.y, z=pos.z}, { name = "mode:panel_left", paramtype2='none', param2=fdir})
        nodeupdate(pos)
        end
        end

minetest.register_on_placenode(on_place_trans)


what happens currently is that the 2 nodes place to the x+1 and x-1. What i want to do, but don't know how, is to code it so that if placer:dir = front then it will use the x+1 and x-1, if the placer:dir = right then it will use the z-1 and z+1. If someone could tell me how to code something like that, that would be great.
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Fri Mar 29, 2013 05:00

bentleysb wrote:I am trying to make it so when a block is placed then 2 other blocks are placed to the right and left of that block....


Just test whether the absolute value of the look direction's x or z coordinate is smaller, and modify that direction. Something like:

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 lookDir = placer:get_look_dir()
local pos1, pos2
if math.abs(lookDir.x) < math.abs(lookDir.z) then
   pos1 = { x = pos.x-1, y = pos.y, z = pos.z }
   pos2 = { x = pos.x+1, y = pos.y, z = pos.z }
else
   pos1 = { x = pos.x, y = pos.y, z = pos.z-1 }
   pos2 = { x = pos.x, y = pos.y, z = pos.z+1 }
end
Last edited by prestidigitator on Fri Mar 29, 2013 05:01, edited 1 time in total.
 

User avatar
Casimir
Member
 
Posts: 1101
Joined: Fri Aug 03, 2012 16:59

by Casimir » Fri Mar 29, 2013 13:13

I tried to make a register_on_item_eat function, but failed. Nothing happens.

in item.lua
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
function minetest.register_on_item_eat(hp_change, replace_with_item)
    print("[register_on_item_eat] 2")
    return function(itemstack, user, pointed_thing)  -- closure
        if itemstack:take_item() ~= nil then
            user:set_hp(user:get_hp() + hp_change)
            itemstack:add_item(replace_with_item) -- note: replace_with_item is optional
        end
        return itemstack
    end
end

function minetest.item_eat(hp_change, replace_with_item)
    print("[register_on_item_eat] 1")
    -- Run script hook
    local _, callback
    for _, callback in ipairs(minetest.registered_on_item_eat) do
        -- Copy hp_change and replace_with_item because callback can modify them
        local hp_change_copy = {x=pos.x, y=pos.y, z=pos.z}
        local replace_copy = hp_change
        callback(hp_change_copy, return_copy)
    end
end


in misc_register.lua
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.registered_on_item_eat, minetest.register_on_item_eat = make_registration()
 

User avatar
jojoa1997
Member
 
Posts: 2890
Joined: Thu Dec 13, 2012 05:11

by jojoa1997 » Fri Mar 29, 2013 13:17

I think you either have to change player.lua or some code that is in C++
Coding;
1X coding
3X debugging
12X tweaking to be just right
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Fri Mar 29, 2013 16:54

Casimir wrote:I tried to make a register_on_item_eat function, but failed. Nothing happens.

Here is why. minetest.item_eat(...) is called by mods when they are registering items. This is before the game is really started, and players do not have the chance yet to interact. At that time your list of callbacks is probably going to be empty or uninteresting (depending on what mods have been loaded in what order), so calling them probably isn't going to do much. Also, the way the mods use minetest.item_eat(...), they expect it to return a function to assign to the item's on_use() callback. Your minetest.item_eat(...) returns nothing (nil). So when the player takes an item and left-clicks with it to use it, the game will see the item's on_use as nil, meaning there is no callback.

Your other function...I think maybe you meant to call minetest.register_on_item_eat(...) rather than define it? Not sure.

(And no, this doesn't need to be done in C++. It is very possible to do it in Lua.)
Last edited by prestidigitator on Fri Mar 29, 2013 16:55, edited 1 time in total.
 

User avatar
Likwid H-Craft
Member
 
Posts: 1113
Joined: Sun Jan 06, 2013 14:20

by Likwid H-Craft » Thu Apr 04, 2013 14:11

Is there a way make a node, to be set on fire forever like MC Nether block?
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)
 

User avatar
Zsoltisawesome
Member
 
Posts: 177
Joined: Sun Dec 18, 2011 18:07
GitHub: realtinymonster
IRC: zsoltisawesome microcarrot
In-game: ManOfMinetest24 Name zsoltisawesome

by Zsoltisawesome » Thu Apr 04, 2013 17:45

Is there way to make a node edible?
Check Out Moontest! www.tinyurl.com/moontest
Buddies: Likwid H-Craft, 0gb.us, Death, Starfellow, and many more!
 

User avatar
Likwid H-Craft
Member
 
Posts: 1113
Joined: Sun Jan 06, 2013 14:20

by Likwid H-Craft » Thu Apr 04, 2013 18:14

Zsoltisawesome wrote:Is there way to make a node edible?

Yes
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)
 

User avatar
Zsoltisawesome
Member
 
Posts: 177
Joined: Sun Dec 18, 2011 18:07
GitHub: realtinymonster
IRC: zsoltisawesome microcarrot
In-game: ManOfMinetest24 Name zsoltisawesome

by Zsoltisawesome » Thu Apr 04, 2013 21:22

Likwid H-Craft wrote:
Zsoltisawesome wrote:Is there way to make a node edible?

Yes

How? I Really Need To KNOW!
Check Out Moontest! www.tinyurl.com/moontest
Buddies: Likwid H-Craft, 0gb.us, Death, Starfellow, and many more!
 

User avatar
Likwid H-Craft
Member
 
Posts: 1113
Joined: Sun Jan 06, 2013 14:20

by Likwid H-Craft » Thu Apr 04, 2013 21:33

Add this:
on_use = minetest.item_eat(#),
#: Any number.
My Domain's/others:
http://likwidtest.hj.cx/ (Not Done)
 

User avatar
ch98
Member
 
Posts: 463
Joined: Wed Jan 02, 2013 06:14

by ch98 » Fri Apr 05, 2013 00:35

Copy of my forcefield mod help topic:


I am going to make a forcefield mod where undigable block (forcefield block) is placed around about 6 blocks from forcefield generator block when it has coal in it and takes a coal away every 10 times forcefield block is hit, every 10 seconds, or if any block is missing, and destroys all forcefield block when there is no more coal. I am stuck on part detecting if coal is in the forcefield generator and there will be way more help needed afterwards.

init.lua:
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("forcefield:forcefield", {
    tiles = {"forcefield_forcefield.png"},
    drawtype = glasslike,
    sunlight_propagates = true,
    walkable = true,
    diggable = false,
    on_punch = function(pos, node, puncher)
        pos = position
        a = "a" + "1"
    end,
})




default.forcefield_formspec =
    "size[8,9]"..
    "list[current_name;coal;1,1;6,3;]"..
    "list[current_player;main;0,5;8,4;]"



minetest.register_node("forcefield:fmaker", {
    description = "Forcefield Generator",
    tiles = {"forcefield_sides.png","forcefield_sides.png","forcefield_front.png","forcefield_sides.png","forcefield_sides.png","forcefield_sides.png"},
    groups = {snappy=2, choppy=2},
    on_construct = function(pos)
        local meta = minetest.env:get_meta(pos)
        meta:set_string("formspec", default.forcefield_formspec)
        meta:set_string("infotext", "forcefield generator")
        local inv = meta:get_inventory()
        inv:set_size("coal", 18)
    end,
    can_dig = function(pos,player)
        local meta = minetest.env:get_meta(pos);
        local inv = meta:get_inventory()
        if not inv:is_empty("coal", 18) then
            return false
        end
        return true
    end,
 
})



minetest.register_abm({
    nodenames = {"forcefield:fmaker"},
    interval = 1.0,
    chance = 1,
    action = function(pos, node, active_object_count, active_object_count_wider)
        local meta = minetest.env:get_meta(pos)
        local inv = meta:get_inventory()
        local fuel = inv:get_list("coal")
            if fuel == "default:coal_lump" then
            srcstack = inv:get_stack("coal", 1)
                    srcstack:take_item("default:coal_lump")
                    inv:set_stack("coal", 1, srcstack)
                else
                    print("there was no coal")
        end
    end,
})


minetest.register_craft({
    output = 'forcefield:fmaker',
    recipe = {
        {'default:mese', 'default:mese', 'default:mese'},
        {'default:mese', 'default:furnace', 'default:mese'},
        {'default:mese', 'default:mese', 'default:mese'},
    }
})

Mudslide mod Click Here
 

prestidigitator
Member
 
Posts: 632
Joined: Thu Feb 21, 2013 23:54

by prestidigitator » Sat Apr 06, 2013 07:20

ch98 wrote:Copy of my forcefield mod help topic:
...
I am stuck on part detecting if coal is in the forcefield generator....


Non-copy of answer: http://forum.minetest.net/viewtopic.php?pid=81855#p81855

;-)
 

User avatar
pandaro
Member
 
Posts: 266
Joined: Sun Jan 08, 2012 21:34
GitHub: pandaro

by pandaro » Sun Apr 07, 2013 09:46

how to handle collisions between objects?
sorry for bad english
Linux debian 7 wheezy 64
kde
 

1244
Member
 
Posts: 45
Joined: Fri Jul 13, 2012 16:40

by 1244 » Sun Apr 07, 2013 12:34

Why this function isn't working?

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
function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")

minetest.register_craftitem("chemistry:..name1..", {   
description = "..description1..",
inventory_image = "..image.."
})
end
 

deivan
Member
 
Posts: 452
Joined: Fri Feb 15, 2013 10:16

by deivan » Sun Apr 07, 2013 12:50

I think ".." don't be a valid part of a name.
 

User avatar
kaeza
Member
 
Posts: 2141
Joined: Thu Oct 18, 2012 05:00
GitHub: kaeza
IRC: kaeza diemartin blaaaaargh
In-game: kaeza

by kaeza » Sun Apr 07, 2013 13:27

1244 wrote:Why this function isn't working?

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
function register_element (name1,image,description1)
minetest.register_alias("chemistry:..name1..","..name1..")

minetest.register_craftitem("chemistry:..name1..", {   
description = "..description1..",
inventory_image = "..image.."
})
end


Maybe this is what you meant:
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
function register_element (name1,image,description1)
minetest.register_alias(name1,"chemistry:"..name1)

minetest.register_craftitem("chemistry:"..name1, {   
description = description1,
inventory_image = image
})
end
Your signature is not the place for a blog post. Please keep it as concise as possible. Thank you!

Check out my stuff! | Donations greatly appreciated! PayPal | BTC: 1DFZAa5VtNG7Levux4oP6BuUzr1e83pJK2
 

PreviousNext

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 11 guests

cron