Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [Lua script] Script to show most valuable items - list-valuables.lua  (Read 2661 times)

Saiko Kila

  • Bay Watcher
  • Dwarven alchemist
    • View Profile

A little LUA console script for dfhack (versions 0.43.x-0.44.12). Used to list, help locate and optionally log most valuable items on map. Works with every mode (i.e. arena, fort and adventurer), but some functionality may be missing depending on mode. Should be placed in the scripts directory, e.g.
\DwarfFortress\hack\scripts\list-valuables.lua

Spoiler (click to show/hide)

It was made specifically to help with selecting bait items for kobold traps, but it can be used for some other tasks, like saving a list of all items to a file (sorted according to value), or total value of some specific items. I use it regularly to check value of roasts stored in trading depot for example.

It can be configured both with line options and with in-script options (part of script near beginning which is named "CONFIGURATION"). Several line options can be used at once.

Without options, it simply lists 10 most valuable items. Example:
 1 @<@adamantine chain leggings@>@ (1234800¤) at x=116 y=8 z=170
 1->Item in a building.
 2 {@<@segmented adamantine breastplate@>@} (944400¤) at x=133 y=56 z=159
 3 @<@iron nadak@>@ (822000¤) at x=139 y=89 z=166
 3->Item in a building and in location.
 4 {@<@giant cave spider silk coat@>@} (760760¤) at x=132 y=59 z=159
 5 @<@iron mini-forge@>@ (379200¤) at x=136 y=62 z=159
 5->Item in a building.
 6 =vodka roast [149]= (312304¤) at x=99 y=83 z=117
 7 @<@cinnamon grossular gudas@>@ (163200¤) at x=147 y=109 z=166
 7->Item in inventory (unit) and owned.
 8 @<@native gold door@>@ (140400¤) at x=133 y=97 z=168 H
 9 @<@steel weapon rack@>@ (91200¤) at x=129 y=67 z=168
 9->Item in a building.
10 @<@iron statue of Cilob Urnwrung@>@ (88800¤) at x=136 y=96 z=29
10->Item in a building.



First line for each entry gives chart position in the ranking of most valuable items, description or name of the item, value and position on map. Additionally a letter H at the end denotes "hidden" flag (which can be set/cleared by the script), like in position 8 of the list above.
Second line (optional) gives some additional info about state of the item, if it is held in inventory or built into building for example. No all items have this info.

If the script is configured to show total, also number and total value of items shown is presented, e.g.:
Items shown: 10 (total value: 4937064¤)
   
   
Line options:
list-valuables -help - display line options

list-valuables -show N - shows N most valuable items.
For example list-valuables -show 100 will show up to one hundred most valuable items. If you want to see all items (or rather all which fits into console buffer) then use a very high number, like 99999 or 1000000.

list-valuables -state - shows state if not shown, or hides if shown (default state is in CONFIGURATION, see below)
State is additional line of information for some items, like whether it is in inventory, if it is owned, held by visitor or a trader. This is important for baiting, because kobolds don't steal items in inventory of live persons, or built into buildings.

list-valuables -hide N - hides/unhides Nth item to help localize it
Switches the hidden flag of an item, which is particularly helpful in quantum stockpiles or other heaps. N is the number on the most valuable items list (printed before name of the item, a chart position). To get item you must run the script once, to set the flag you need another run. Since this number is temporary, changes for less valuable items often, it's best to pause the game before trying to us this option. NOTE: in adventurer mode the hidden items do not disappear, but they are listed at the end of a particular list, so this option still can be useful to a degree.

list-valuables -filter NAME - shows items containing NAME only
Show only items containing a NAME in their description. NAME can be a standard Lua pattern. Additionally the curly brackets can be used to show forbidden items. Use a dot instead of space (or %s pattern, as it's a standard in Lua). Examples of filters:

-filter large.*leather --match large items made of leather
-filter giant.*leather --match items made of leather of giant animals
-filter giant.cave.spider.silk --match GCS silk or item made from it
-filter giant%scave%sspider%ssilk --match GCS silk or item made from it
-filter {.*roast --match forbidden roasts
-filter [^{].*roast --match unforbidden roasts

Masterwork quality uses @ sign, exceptional items use =.

Note that the items shown still must belong to the top N valuable on map, like in -show option (defaults to ten). If you suspect that not all interesting items are shown, then increase N value in -show.

list-valuables -total - shows number and total value of items
Display number and sums up the value of items shown. Useful for counting particular type of items and their value, when paired with -filter option.

list-valuables -log - logs the list to a file in main DF directory
The file allows to see more items than the console buffer holds, including all items, by saving the output to a file in main DF directory. If huge number of items is shown, this may take a couple of megabytes. Name of this file depends on mode and name of the fortress (if available). Use a text editor for looking through the log file.


CONFIGURATION options are switches which can set some default behaviour of the script. They are located near beginning of the script. They have format OPTION = true or OPTION = false. If "true" the OPTION is enabled, if "false" the OPTION is disabled. CONFIGURATION options and their default state:

MULTICOLOR = true -- change to false to prevent use of different colours. By default uses grey to show the state (second) line, red to show items barred from fortress (usually trader or visitor owned), and yellow to show items off-map (just stolen or carried by missionairies, though stolen trader items are still red). Disable to use only the default console colour.

SHOW_OWNERSHIP = true -- checks ownership (apart from trader's, which is always checked), items not owned by fortress are red. Disabling marginally speds up the script. If SHOW_STATE is enabled, then ownership is checked regardless.

SHOW_STATE = true --shows second line with more info, if item is in building, or in inventory, or owned by someone etc. Implies enabled SHOW_OWNERSHIP. Line option -state temporarily switches this setting to opposite.
NOTE: "trader" means the item has "trader" flag, which rarely has something to do with actual trader. Sometimes one of your visitors or residents have such item. It is barred from being used by the rest of the fortress, though. If it is owned (as opposed to only held) then it is described as "not for sale".

SHOW_FORBID = true --shows curly brackets around forbidden item. The brackets are outside description, which slightly differs from the DF behaviour. The bracket can be used in filter. Disable if you don't care if the items are forbidden or not.

SHOW_TOTAL = false --change to true to always show number of items shown and their total value, it then works as if the -total option was always enabled. If set to false you can still use -total option.

DEEP_CHECK = true --more thoroughly checks item presence on map in non-dwarf mode. It's always disabled in dwarf fortress mode, because it is not necessary (standard checks suffice) and very CPU demanding. You may disable it if the script works slowly in adventurer mode. This will result in showing items which are not really present on current map, like demonic slabs or corpses, body parts and equipment of creatures slain by your adventurer in the past (not all of such items will be shown, only those which by coincidence have x,y coordinates inside current map). However, I recommend to have it enabled, unless the script works with too noticeable delay in adventurer.

Issues:
One issue with this script is that it will show items not yet discovered by you or your people. Fortunately they are rarely very spoilerific, usually it's bodies, remains and spider webs, and as such they are not in the top 10 of most valuable items. If you have DEEP_CHECK disabled in adventurer and are away from the vault, the demonic slabs can be still shown in top ten (they cost 1200), though their location doesn't give much in most cases. Similarly mummy treasue can be seen before you enter the pyramid.

All items must have unique rank (chart position), even if they have the same value, to use with -hide option. The items are sorted in this order:
-value
--age (older items first if the same value)
---ID number (lower numbers first if the same age)
The second and third order rules (age and ID) are not really guaranteed, but they are usually observed.
Logged