Yes, I wrote it a couple of months ago for my own use, although I think I've shared it on the forum before.
Here's a somewhat improved version that sorts the entries and removes duplicates (which resulted because the original script just added preferences as they were encountered, without checking of another dorf had the same one).
function add (list, item)
for i, element in ipairs (list) do
if element == item then
return
end
end
table.insert (list, item)
end
-----------------------------
function sort (list)
local temp
for i = 1, #list - 1 do
for k = i + 1, #list do
if list [k] < list [i] then
temp = list [i]
list [i] = list [k]
list [k] = temp
end
end
end
end
-----------------------------
function food_needs ()
local preferences = {}
for i, unit in ipairs (df.global.world.units.all) do
if dfhack.units.isCitizen (unit) and
dfhack.units.isAlive (unit) and
unit.status.current_soul then
for k, preference in ipairs (unit.status.current_soul.preferences) do
if preference.active then
if preference.type == df.unit_preference.T_type.LikeFood then
local found = false
for l, pref in ipairs (preferences) do
if pref.mattype == preference.mattype and
pref.matindex == preference.matindex and
pref.item_type == preference_item_type then
found = true
break
end
end
if not found then
table.insert (preferences, preference)
end
end
end
end
end
end
local drink_list = {}
local food_list = {}
for i, preference in ipairs (preferences) do
local material = dfhack.matinfo.decode (preference.mattype, preference.matindex)
if preference.matindex ~= -1 and
(material.mode == "plant" or
material.mode == "creature") then
if preference.item_type == df.item_type.DRINK or
preference.item_type == df.item_type.LIQUID_MISC then -- The state in the preferences seems locked to Solid
add (drink_list, material.material.state_name.Liquid)
else
if material.material.prefix == "" then
add (food_list, material.material.state_name.Solid)
else
add (food_list, material.material.prefix .. " " .. material.material.state_name.Solid)
end
end
else
add (food_list, df.global.world.raws.creatures.all [preference.mattype].name [0])
end
end
sort (drink_list)
sort (food_list)
dfhack.color (COLOR_YELLOW)
dfhack.println ("Drink preferences found:")
dfhack.color (COLOR_RESET)
for i, drink in ipairs (drink_list) do
dfhack.println (drink)
end
dfhack.println ()
dfhack.color (COLOR_YELLOW)
dfhack.println ("Food preferences found:")
dfhack.color (COLOR_RESET)
for i, food in ipairs (food_list) do
dfhack.println (food)
end
end
food_needs ()