Skip to content
This repository has been archived by the owner on Dec 15, 2020. It is now read-only.

Commit

Permalink
Create list-citizens
Browse files Browse the repository at this point in the history
  • Loading branch information
kane-t committed Jul 19, 2015
1 parent a4c9bc7 commit 9bd15c9
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions list-citizens
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- List names and unit IDs of all citizens in a fort.
-- (Code stolen from a Roses script.)
function getSexString(sex)
local sexStr
if sex==0 then
sexStr=string.char(12)
elseif sex==1 then
sexStr=string.char(11)
else
return ""
end
return string.char(40)..sexStr..string.char(41)
end

local function nameOrSpeciesAndNumber(unit)
if unit.name.has_name then
return dfhack.TranslateName(dfhack.units.getVisibleName(unit))..' '..getSexString(unit.sex),true
else
return 'Unit #'..unit.id..' ('..df.creature_raw.find(unit.race).caste[unit.caste].caste_name[0]..' '..getSexString(unit.sex)..')',false
end
end

for k,v in ipairs(df.global.world.units.active) do
if dfhack.units.isCitizen(v) then
print(nameOrSpeciesAndNumber(v) .. ": ID=" .. v.id)
end
end

0 comments on commit 9bd15c9

Please sign in to comment.