wcwyes wrote:I've created a node/tool(i.e. a tool that places a node version of itself)that is a chest and a bag. I'm working on creating a tool to look at the bags and place the node version of that bag and transfer the inventory over to it and then remove the tool from the inventory. I'm using the screwdriver as a guide I've stripped it down to barely the rotating function and now I'm building mode1 up. think of mode1 being
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 user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
return itemstack
end,
ElectricSolstice wrote:wcwyes wrote:tried 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
if mode==1 then
if user:get_player_name():get_inventory("bag1", get_definition(get_current_modname(suitcase)))==true then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
minetest.get_node(pt.above, {name="suitcase:general_node"])
return itemstack
end
end
end
and got
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
attempt to call global 'get_current_modname' (a nil value)
I think I'm on the right track, someone help, please.
Someone correct me if I'm wrong but I would guess get_player_name would return a string rather than the data of a player. Then, you were trying to do get_definition on an Inventory object. When looking at the api documentation, there's a get_definition method for ItemStack, which are contained in the lists of an Inventory, but the Inventory itself doesn't appear to have a get_definition method. Also, get_inventory takes 0 arguments, ignoring the fact that the colon makes a method put the calling table in as the first argument. Not only that, but you have a "]" where i think you meant "}"
The code could probably use something along the lines of
if user:is_player() then
local bag_one = user:get_inventory():get_list("bag1")
However, I haven't dealt with the lists themselves, so I don't even know yet how to use them.
Also, the problem is, I can't tell from the code shown what you're trying to do. Is this what happens when you right click on something or what? Because a node is something that is one of those cubes out in the world outside the player. However, in the code, I see both return itemstack and minetest.get_node.
Give a better explanation of what you're trying to achieve and/or show more code. Most important right now would be an explanation.
Hmm, so it's the the tool you're using that contains an inventory and you want the tool to turn into a node with the same inventory?
If you want the tool to deploy itself maybe try something along the lines of
on use = function(itemstack, user, pointed_thing)
if itemstack:get_name() == "suitcase:bag" then
local pt = pointed_thing
if minetest.get_node(pt.above).name == "air" then
local itemstack_meta = itemstack:get_meta()
--haven't dealt with itemstack meta before so
--figure out what the difference is between it and
--a node's metadata and create a conversion
--function as neccesary
local node_meta_table,
node_inventory_table = yourConvFunc(itemstack_meta)
minetest.
set_node(pt.above,
{name="suitcase:general_node"
})
local node_meta = minetest.get_meta(pt.above)
node_meta:set_string("formspec",node_form_spec)
local key,meta_data, inv_data
for key,meta_data in pairs(node_meta_table) do
if type(meta_data) == "int" then
node_meta:set_int(key,meta_data)
elseif type(meta_data == "string") then
node_meta:set_string(key,meta_data)
end
end
local inv = node_meta:get_inventory()
--key is listname and inv_data are stacks
--or key can be listname and inv_data are lists
for key,inv_data in pairs(node_inventory_table) do
--code for inv_data = stacks
local stack
for _,stack in pairs(inv_data) do
inv:add_item(key,stack)
end
--code for inv_data = list
inv:set_list(key,inv_data)
end
--return empty item stack since tool is now a node
return
Item
Stack(nil)
end
end
--leave item stack alone since it didn't met conditions
return nil
end
I haven't tried it so the code is most likely wrong, has errors, and/or has more code than neccessary but should give an idea of maybe how to do it.