PilzAdam wrote:There are two kinds of metadata:
Nodemeta:
Each node has an own meta object. The meta object has data stored in a table indexed by a strings and an inventory. It can be gotten via minetest.get_node_meta(pos). https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L805 https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1514
ItemStack metadata:
ItemStacks only have a single string for metadata. https://github.com/minetest/minetest/blob/master/doc/lua_api.txt#L1666
if mode==1 then
if player:get_inventory("bag1"):get_definition.description.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
function arguments expected near '.'
wcwyes wrote:Thanks looks like it will be alot of help.
It seems I still can't get it right thoughYour 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 player:get_inventory("bag1"):get_definition.description.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
not sure what I did wrong, I always getYour 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 arguments expected near '.'
if mode==1 then
if player:get_inventory("bag1"):get_definition==suitcase 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
function arguments expected near '=='
if mode==1 then
if player:get_inventory("bag1"):get_definition().description.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
if mode==1 then
if player:get_inventory("bag1"):get_definition()==suitcase 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
attempt to index global 'player' (a nil value)
rubenwardy wrote:tryif mode==1 then
if player:get_inventory("bag1"):get_definition().description.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
orif mode==1 then
if player:get_inventory("bag1"):get_definition()==suitcase 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
if mode==1 then
if user:get_player_name():get_inventory("bag1"):get_definition()==suitcase 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
attempt to call method 'get_inventory' (a nil value)
if mode==1 then
if user:get_player_name():get_inventory("bag1"):get_definition():get_current_modname()==suitcase 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
attempt to call method 'get_inventory' (a nil value)
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
attempt to call global 'get_current_modname' (a nil value)
wcwyes wrote:tried thisYour 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 gotYour 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.
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 thisYour 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 gotYour 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.
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 beingYour 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 thisYour 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 gotYour 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.
ElectricSolstice wrote: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 beingYour 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:
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 ItemStack(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.
wcwyes wrote:I've already made the individual tool/nodes https://scontent-b-dfw.xx.fbcdn.net/hphotos-prn1/v/1241327_10201179085972019_1997570415_n.jpg?oh=dd51c3320dc1e1c8f032f2f05d749865&oe=525B6D29
ElectricSolstice wrote:wcwyes wrote:I've already made the individual tool/nodes https://scontent-b-dfw.xx.fbcdn.net/hphotos-prn1/v/1241327_10201179085972019_1997570415_n.jpg?oh=dd51c3320dc1e1c8f032f2f05d749865&oe=525B6D29
Cool, figured out how to do what you were wanting? Should be able to be done.
minetest.register_tool("suitcase:briefcase", {
description = "Briefcase",
inventory_image = "briefcase.png",
on_use = function(itemstack, user, pointed_thing)
use_handler(itemstack, user, pointed_thing)
return itemstack
end,
})
for i=1,4,1 do
minetest.register_tool("suitcase:briefcase"..i, {
description "Briefcase targeting slot"..i
inventory_image = "briefcase.png"^"tool_mode"..i..".png",
wield_image = "briefcase.png",
groups = {not_in_creative_inventory=1},
on_use = function(itemstack, user, pointed_thing)
use_handler(itemstack, user, pointed_thing)
return itemstack
end,
})
end
function use_handler (itemstack, user, pointed_thing)
local keys=user:get_player_control()
local player_name=user:get_player_name()
local item=itemstack:to_table()
if item["metadata"]=="" or keys["sneak"]==true then return briefcase_setslot(user, itemstack) end
local mode=tonumber((item[metadata"]))
if pointed_thing.type~="node"then return end
local pos=minetest.get_pointed_thing_position(pointed_thing.above)
local node=minetest.env:get_node(pos)
local node_name=node.name
if minetest.registered_nodes[node_name].drawtype == "nodebox" then
end
if node.param2==nil then return end
local n = node.param2
local axisdir=math.floor(n/4)
local rotation=n-axisdir*4
if mode==1 then
if user:get_inventory():get_list("bag1"):get_current_modname()==suitcase then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt=pointed_thing
minetest.set_node(pt.above, {name="suitcase:general_node"})
return itemstack
end
end
end
wcwyes wrote:ElectricSolstice wrote:wcwyes wrote:I've already made the individual tool/nodes https://scontent-b-dfw.xx.fbcdn.net/hphotos-prn1/v/1241327_10201179085972019_1997570415_n.jpg?oh=dd51c3320dc1e1c8f032f2f05d749865&oe=525B6D29
Cool, figured out how to do what you were wanting? Should be able to be done.
I haven't figured out the next step which is targeting the bag slots and setting them on the ground(with their inventory in them) using a tool I call the briefcase. The problem I'm trying to overcome is checking for a mod name and if it is suitcase then a node would be placed.
ElectricSolstice wrote:
--assumes that bag1 list is of size 1,1 in the formspec
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
--code to place node and add metadata
end
if mode==1 then
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt=pointed_thing
minetest.set_node(pt.above, {name="suitcase:general_node"})
return itemstack
end
end
end
local S
if minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("initllib").."/initllib.lua")
S = initllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
end
if mode==1 then
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
minetest.set_node(pt.above, {name=suitcase_name .. "_node"})
--\/\/fixme\/\/
local meta =minetest.env:get_meta(pt.above)
local inv = meta:get_inventory()
local player_inv = user:get_inventory()
inv:set_size("main", 24)
local empty_list = inv:get_list("bag1contents")
inv:set_list("main", player_inv:get_list("bag1contents"))
player_inv:set_list("bag1contents", empty_list)
meta:set_string("formspec", "size[10,10;]"..
"list[current_name;main;0,0;8,3]"..
"list[current_player;main;1,6;8,4;]")
meta:set_string("infotext", S("suitcase"))
local inv = meta:get_inventory()
inv:set_size("main",24)
--/\/\fixme/\/\
return itemstack
end
end
end
wcwyes wrote:I've got it transferring the data but, it won't show player inventory(I feel like there's a better way to do it too)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 S
if minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("initllib").."/initllib.lua")
S = initllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
endYour 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
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
if string.match(suitcase_name,"suitcase:") then
local pt = pointed_thing
if minetest.get_node(pt.above).name=="air" then
local pt = pointed_thing
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
minetest.set_node(pt.above, {name=suitcase_name .. "_node"})
--\/\/fixme\/\/
local meta =minetest.env:get_meta(pt.above)
local inv = meta:get_inventory()
local player_inv = user:get_inventory()
inv:set_size("main", 24)
local empty_list = inv:get_list("bag1contents")
inv:set_list("main", player_inv:get_list("bag1contents"))
player_inv:set_list("bag1contents", empty_list)
meta:set_string("formspec", "size[10,10;]"..
"list[current_name;main;0,0;8,3]"..
"list[current_player;main;1,6;8,4;]")
meta:set_string("infotext", S("suitcase"))
local inv = meta:get_inventory()
inv:set_size("main",24)
--/\/\fixme/\/\
return itemstack
end
end
end
user:get_inventory():set_stack("bag1",1, Empty)
user:get_inventory():remove_item("main", meta:get_string("nodename") .. " " .. meta:get_string("amount"))
rubenwardy wrote:I assume meta is defined, and so is "nodename" and "amount".
local bag1_stack = user:get_inventory():get_stack("bag1",1)
local suitcase_name = bag1_stack:get_name()
user:get_inventory():remove_item("bag1", {name=suitcase_name.." "..1})
fairiestoy wrote:I suggest that you set some debug info. Like what name is printing 'suitcase_name'. It might be possible that you are even getting a nil value here, if your bag has more than one inventory slot and you didn't put the item in the first index. Since thats the only indexing your asking for in your code.
Users browsing this forum: No registered users and 3 guests