oh guys you might want this in your commons if you want to run any of my future functions...
function getItemAtPos(x,y,z) -- gets the item index @ x,y,z coord
--local x,y,z=getxyz() --get 'X' coords
local vector=df.global.world.items.all -- load all items
for i = 0, #vector-1 do -- look into all items offsets
local curpos=vector[i].pos --get its coordinates
local cx=curpos.x
local cy=curpos.y
local cz=curpos.z
if cx==x and cy==y and cz==z then --compare them
return vector[i] --return index
end
end
--print("item not found!")
return nil
end
like this one which allows you to trap souls into items though this is mostly warmist code I just slightly modified.
function putInItem(item,unit)
if unit==nil then
unit=getCreatureAtPos(getxyz())
end
if item==nil then
item=getItemAtPos(getxyz())
end
for a,b in ipairs(df.global.world.items.all) do for c,d in ipairs(b.itemrefs) do end end
local u_ref=df.general_ref_contains_unitst:new()
u_ref.unit_id=unit.id
item.itemrefs:insert(#item.itemrefs,u_ref)
local u_cr_ref=df.general_ref_contained_in_itemst:new()
unit.flags1.caged=true
u_cr_ref.item_id=item.id
unit.refs:insert(#unit.refs,u_cr_ref)
end
tools.menu:add("Shove in bag",putInItem)