Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [Dfhack] a general help for lua coders  (Read 2103 times)

Warmist

  • Bay Watcher
  • Master of unfinished jobs
    • View Profile
[Dfhack] a general help for lua coders
« on: January 09, 2014, 02:12:22 pm »

First question:
how to access/understand adventurers inventory
Answer:
a bit complicated thing:
first adventurer is first unit in "active" units (except ofcourse fort mode), so we get him to be a more usable variable:
Code: [Select]
local adventurer=df.global.world.units.active[0]
now his inventory is held in "inventory" :). Lets print stuff that is in there:
Code: [Select]
printall(adventurer.inventory)
individual entries can be accessed with array operator "[ ]"
Code: [Select]
printall(adventurer.inventory[0]) --print what's in first entry
now will see that it has:
  • item
  • mode - how it's used
  • body_part_id - where it's used
  • anon_1 - nobody knows what this does
  • wound_id - i don't know what this does but probably for sutures


That's it for now, try exploring the rest...
« Last Edit: January 09, 2014, 02:22:48 pm by Warmist »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: [Dfhack] a general help for lua coders
« Reply #1 on: January 09, 2014, 03:51:23 pm »

ah, nice.

EDIT: Here's mode, by the way, from the XML:

Code: [Select]
     <enum base-type='int16_t' name='mode'>
            <enum-item name='Hauled'/>
            <enum-item name='Weapon' comment='also shield, crutch'/>
            <enum-item name='Worn' comment='quiver'/>
            <enum-item name='InBody'/>
            <enum-item name='Flask' comment='attached to clothing'/>
            <enum-item name='WrappedAround' comment='e.g. bandage'/>
            <enum-item name='StuckIn'/>
            <enum-item name='InMouth' comment='string descr like Worn'/>
            <enum-item name='Shouldered'/>
            <enum-item name='SewnInto'/>
        </enum>

This means that a hauled item is 0, wielded is 1 etc.
« Last Edit: January 09, 2014, 03:53:44 pm by Putnam »
Logged

Socharis

  • Bay Watcher
    • View Profile
Re: [Dfhack] a general help for lua coders
« Reply #2 on: January 09, 2014, 03:52:23 pm »

Beautiful!

I'll give this a look and see what I can find.
Logged