I've got a question regarding programming LUA scripts for dfhack. I hope this is the right place to ask.
First a rather specific one:
If you view the "Stocks" and press TAB the item list gets expanded. Items there are colored and according to the wiki, red items are "Not owned by the fort".
I'm interested in items in the category "Bars" or "Cloth"
In the list I see some white (traded items), a lot of dark yellow (created by the fort) and some red (not owned by the fort - e.g. if a caravan is currently at the depot). If you have opened a cavern already, uncollected spider silk cloth is also marked red.
How do I test an item, if is owned by the fort (which is NOT red) in the stocks list. Here is a small script I was using, to find all items that can be used for crafting.
local utils = require('utils')
for i,item in ipairs(df.global.world.items.all) do
if not item.flags.rotten and not item.flags.dump and not item.flags.forbid and not item.flags.construction then
if item:getMaterial() == df.builtin_mats.INORGANIC and item:getType() == df.item_type.BAR then
print(utils.getItemDescription(item,0))
end
end
end
I saw that there should be a flag "item.flags.owned". If I add this flag to the other flag checks, NO item will be printed. As I'm currently seeing items in dark yellow and red, there should always be printing something.
if item.flags.owned and not item.flags.rotten and not item.flags.dump and not item.flags.forbid and not item.flags.construction then
It seems, this flag is false for all items. Is this a bug? Does this flag represent something else? Is there another way to check the "owned" status? (I'm using DF 0.43.03 with DFHack 0.47.03-beta1).
Then a more general question. Is there a "useful resource" when looking for documentation regarding programming LUA in connection with DFHack.
I was looking at:
https://dfhack.readthedocs.io/en/stable/docs/Lua API.html
and I'm currently browsing the available scripts already provided by DFhack. But this is quite cumbersome and may not always be lead to success.
some examples, where I was struggling to find a solution:
item:getMaterial() == df.builtin_mats.INORGANIC
What are other material types, I could check? I found "df.builtin_mats.COAL", but there should be much more.
I was looking for wood, leather, cloth, bone, glass, ....
I found a function
df.inorganic_raw.find(matIndex).material.state_name.Solid
to get the material name for an inorganic item, if I have the materialIndex.
There are other "resources types" (cloth, thread, leather, bones,...) and was looking for a similar function to get the material name for "organic" materials, if I have the material index.
I found a global "df.material_common" which seems to get exported for DT, but I failed to get more information, what methods may be sent.
Any help is appreciated. Thanks in advance.