Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 5

Author Topic: DFHack script: The Librarian  (Read 33046 times)

PatrikLundell

  • Bay Watcher
    • View Profile
DFHack script: The Librarian
« on: April 27, 2018, 11:34:37 am »

The Librarian is a script for viewing the contents of your library (actually everything present in the Stocks screen).
The scripts provides 5 views of the works:
- Main view: Everything. It can be filtered on category and whether works have any references.
- Scientific view: Indicator of which scientific topics the works cover, as well as listing of works per category.
- Values view: As the scientific view, but for values, with all values/strength combinations accessible.
- Authors view: Lists all your authors who have works in the fortress, as well as those works.
- Interactions view: Show all works containing interactions (i.e. The Secret of Life and Death in vanilla).
- The scientific and Values views also lists all works outside of the fortress in the selected category, which might give you ideas for which works to try to "acquire"...
- All pages also provide some basic details on the currently selected work, and in the case of a local work, also a further list of all the actual books (there may be multiple copies) with a number of their flags (Original/Copy, Forbidden, Dump, Trader, and In Inventory), with the ability to toggle the Forbidden, Dump, and Trader flags.
- A 'zoom to book' command allows you to go to a particular book location in the fortress. Note that this sub view is not intended to be playable, as there are known issued with that, which implies there are probably unknown ones as well. Return to The Librarian with the 'O'ok! command when done looking around.

The script can be found on this web page: https://github.com/PatrikLundell/scripts/blob/own_scripts/librarian.lua. The script section of the script is copied into a "text" file as <DF>\hack\scripts\librarian.lua. This can be done either by using the "raw" selection of the page and then "save as" of the page, or through copy & paste of the script section of the page. The script is invoked from the DFHack console by typing "librarian" (without the quotes) when a fortress is active. The script is dismissed with <ESC>.

Revision History:
0.21: 2023-04-30: 0.20 was based on an old version. 0.21 is based on 0.19, with (hopefully) the same changes. Same limited testing.
0.20: 2023-04-30: Changed to Premium release. The Help key doesn't work (no keyboard support). Limited testing.
0.19: 2020-08-03: Fixed bug causing the script to blow up when no interaction books are present.
0.18: 2020-07-17: Added a crude interactions view (Secrets of Life and Death), and handled added NONE value to the Values enum.
0.17 2020-05-24: Added some info to some additional referenced contents. Introduced wrapping for Detailed lines too long to fit on the screen so they continue on subsequent lines.
0.16 2020-05-23: Adapted to changed field names.
0.15 2019-01-22: Added slightly more info for Interactions (i.e. secrets of life and death), and worked around a reference to a non existent vector index.
0.14 2018-07-14: Fixed bug indexing values.
0.13 2018-07-12: Address bug caused by entity of unknown race.
0.12 2018-05-22: Fixed bug when no authors are available.
0.11 2018-05-05: Added category counts and fixed a bug.
0.10 2018-04-28: Added a 'zoom to book' functionality.
0.9 2018-04-27. First version in this thread.

Meph has created a Librarian's Office to allow role playing to open The Librarian as well as Legends Mode in game. The workshop is described here: http://www.bay12forums.com/smf/index.php?topic=170462.msg7805879#msg7805879.
Note that opening Legends Mode should be done with care. Save the game before opening Legends Mode and kill DF (e.g. with the DFHack "die" command) when done, as there are still potential fatal save game corruption issues with opening Legends Mode from Fortress Mode.

This first post is intended to be updated when/if the functionality changes to reflect the current functionality without any particular change markers beyond the revision history.
« Last Edit: April 30, 2023, 06:56:46 am by PatrikLundell »
Logged

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: DFHack script: The Librarian
« Reply #1 on: April 29, 2018, 11:52:38 am »

Fascinating tool, so much info. Woaw it shows how all the books in the world can affect the readers... we can find awesome books to go and raid ! :D
Logged
Klok the Kloker !

Leonidas

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #2 on: April 29, 2018, 04:35:41 pm »

For me, the biggest use of this script so far has been tracking the productivity of my scholars and scribes.
Logged

jecowa

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #3 on: April 30, 2018, 03:01:00 am »

Does this go in the /hack/scripts/ folder or the /hack/lua/ folder?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #4 on: April 30, 2018, 03:13:02 am »

Does this go in the /hack/scripts/ folder or the /hack/lua/ folder?
hack/scripts. Updated the first post to clarify that.
The hack/lua folder is for DFHack lua support functionality used by scripts.
« Last Edit: April 30, 2018, 03:19:19 am by PatrikLundell »
Logged

strainer

  • Bay Watcher
  • Goatherd
    • View Profile
Re: DFHack script: The Librarian
« Reply #5 on: May 01, 2018, 01:00:33 pm »

Its really a peach, feels like part of the game. Ook!
Logged
Klok the Kloker !

Leonidas

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #6 on: May 04, 2018, 06:12:37 am »

The new features are terrific, Patrik. The flag display works well, especially being able to quickly flip through the whole library. Two books in my library were forbidden, and I didn't know it. And one book, dropped by a spooked caravan, has been stuck unmovable on the surface for years. With this script, I was able to to turn off the Trader flag and retrieve it.

The zoom-and-return feature seems to be working fine this time.

A suggestion: The "Content Type" submenu would be much more useful if it showed the number of titles in each category.

I ran the script five times, and the third time I got a bunch of errors. The script still ran fine, so far as I could tell. And I can't tell why it was the third time and not any of the others. Here's the error log:
Spoiler (click to show/hide)


Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #7 on: May 04, 2018, 08:41:30 am »

Found the bug (a typing error ('.' rather than ':').

New version 0.11:
- Fixed bug
- Added category counts
Logged

Leonidas

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #8 on: May 04, 2018, 03:36:56 pm »

I assume that the "Trade" flag means that the book is owned by a merchant, probably available for purchase. Would it be possible to display and set the flags that designate items to be carried to the depot and made available for sale? That way, you could build a fortress where the primary export is copies of books, like some medieval monasteries.
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #9 on: May 04, 2018, 05:46:04 pm »

"Trader" might be intended to mean it's brought by traders. However, about half of the books infiltrators bring are marked as Trader as well, and that also goes for many visitors killed by goblins.

I don't think there's a flag for bringing things to the trade depot, but rather a task of the same kind as those stockpiles generate (but with a much higher priority, of course). Those tasks can be generated only when a caravan is inbound or at the trade depot. I'm not sure why it's harder to go through the normal trade depot selection menu than it would be to use The Librarian, especially if you use the filtering function with the name of the books you want.
Logged

Leonidas

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #10 on: May 18, 2018, 09:56:29 pm »

Thanks for adding the totals on the category screen. Nearly all my books are manuals, but Legends Viewer tells me that necromancers write all sorts of things.
Logged

jecowa

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #11 on: May 18, 2018, 10:34:25 pm »

Patrik, are you okay with your Librarian script being included in Lazy Newb Packs?
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #12 on: May 19, 2018, 03:44:27 am »

Patrik, are you okay with your Librarian script being included in Lazy Newb Packs?
The scripts I make are intended to be used, so I definitely don't have any problem with them being distributed (or, for that matter, modified, but in those cases I'd like the modifiers to change the version number to indicate it, so versions can be told apart). It can be noted, though, that I don't follow any pack threads except PeridexisErrant's LNP, so I won't see any issues reported in those threads unless I'm alerted to them in this thread.
Logged

Clément

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #13 on: May 22, 2018, 01:45:02 pm »

Hi, I tried this script a few days ago and it worked. Trying again today it does not work (same save but a little earlier since DF crashed last time for an unknown reason). I made sure I have the latest version (commit b29e3e7).

Code: [Select]
[DFHack]# librarian
E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:1697: attempt to index a nil value (field '?')
stack traceback:
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:1697: in global 'Populate_Author_Works'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2639: in function <E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2638>
        [C]: in field 'on_select'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:519: in method 'moveCursor'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:475: in method 'setSelected'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:470: in method 'setChoices'
        E:\Games\Dwarf Fortress\hack\lua\gui\widgets.lua:451: in local 'fun'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:98: in upvalue 'invoke_after_rec'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:127: in field 'List'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:2445: in local 'fun'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:98: in upvalue 'invoke_after_rec'
        E:\Games\Dwarf Fortress\hack\lua\class.lua:127: in upvalue 'Ui'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3426: in global 'Show_Viewer'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3433: in global 'Librarian'
        E:\Games\Dwarf Fortress/hack/scripts/librarian.lua:3436: in local 'script_code'
        E:\Games\Dwarf Fortress\hack\lua\dfhack.lua:562: in function 'dfhack.run_script_with_env'
        (...tail calls...)
Logged

PatrikLundell

  • Bay Watcher
    • View Profile
Re: DFHack script: The Librarian
« Reply #14 on: May 22, 2018, 04:40:36 pm »

Thanks for the report.
The bug was caused by the complete absence of authors, so an empty list was processed.
Updated to 0.12 2018-05-22.
Logged
Pages: [1] 2 3 ... 5