Skip to content

Instantly share code, notes, and snippets.

@warmist
Created May 9, 2012 20:36
Show Gist options
  • Save warmist/2648613 to your computer and use it in GitHub Desktop.
Save warmist/2648613 to your computer and use it in GitHub Desktop.
A script to return bodypart with item ref
function getInv(unit)
local ret={}
if unit==nil then
error("Failed to list unit's items. Unit not selected/valid")
end
for k,v in ipairs(unit.inventory) do
local caste=df.global.world.raws.creatures.all[unit.race].caste[unit.caste]
local bp_code=caste.body_info.body_parts[v.body_part_id].part_code
local key=bp_code
--print("Item:"..tostring(v.item).." "..key)
ret[key]=ret[key] or {}
table.insert(ret[key],{v:_field('mode')._type[v.mode],v})
end
return ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment