Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DfHack Delete-Units Modification  (Read 552 times)

okelly4408

  • Bay Watcher
    • View Profile
DfHack Delete-Units Modification
« on: January 30, 2021, 04:33:13 pm »

Hello all,
I was attempting to modify the dfhack fix/dead-units script so that it deletes individual body parts from the "dead" list. When necromancers fight they raise hair, teeth, arm etc from the dead leading to a lot of clutter on the dead screen. I looked around but couldn't find an obvious way to detect if a unit is a body part...does anyone have any suggestions? Thanks.
Logged

Atomic Chicken

  • Bay Watcher
    • View Profile
Re: DfHack Delete-Units Modification
« Reply #1 on: January 31, 2021, 02:15:10 am »

Something like
Code: [Select]
if unit.enemy.undead.undead_name ~= "" thenshould enable you to identify reanimated units in general.

To target only reanimated body parts, I suppose the easiest way to do this would be to check whether the undead_name lacks the term "corpse", as in "dwarf corpse" and "Urist corpse", as opposed to "cow skin" and "Urist's right upper arm".
Code: [Select]
local undeadName = unit.enemy.undead.undead_name
if undeadName ~= "" and not string.find(undeadName, "corpse") then
Logged
As mentioned in the previous turn, the most exciting field of battle this year will be in the Arstotzkan capitol, with plenty of close-quarter fighting and siege warfare.  Arstotzka, accordingly, spent their design phase developing a high-altitude tactical bomber. 

okelly4408

  • Bay Watcher
    • View Profile
Re: DfHack Delete-Units Modification
« Reply #2 on: January 31, 2021, 06:49:28 pm »

Ok, I will try that out. Is there a place that details all attributes of of the "unit" object? I could not find this in the documentation.
EDIT:
I added this to the script:
Code: [Select]
if dfhack.units.isDead(unit) then
        if unit.enemy.undead ~= nil then
            local undeadName = unit.enemy.undead.undead_name
            if undeadName ~= "" and not string.find(undeadName, "corpse") then
                remove = true
            end
        end
    end
and I believe it worked. Does this look ok? I would really like to get started writing lua scripts for this but I can't even find where some of these objects are defined. Any pointers?
« Last Edit: January 31, 2021, 06:55:26 pm by okelly4408 »
Logged

Atomic Chicken

  • Bay Watcher
    • View Profile
Re: DfHack Delete-Units Modification
« Reply #3 on: February 01, 2021, 02:25:59 am »

Looks about right, yeah. In
Code: [Select]
if unit.enemy.undead ~= nil thenyou can remove the ~= nil, as this is implied. Come to think of it, if this is always nil for non-undead units, we can also remove the if undeadName ~= "" check.

Code: [Select]
if dfhack.units.isDead(unit) then
    if unit.enemy.undead and not string.find(unit.enemy.undead.undead_name, "corpse") then
        remove = true
    end
end

All the mapped structures are defined in DFHack's df-structures repo on github, which can be found here. You're looking for df.units.xml specifically.

I highly recommend using gui/gm-editor to visualise all of this in-game; you can enter this command with a unit or item selected to view the data specific to that object. You can also input commands such as
Code: [Select]
gui/gm-editor df.global
gui/gm-editor df.global.world
gui/gm-editor dfhack.gui.getCurViewscreen()
to bring up the specified structure accordingly. I keep a bunch of these hotkey'ed for convenience.

The DFHack Lua API contains lots of useful information information for script writers, including a number of inbuilt functions to facilitate various tasks, though the documentation tends to feel poor/incomplete at times. Feel free to ask for advice when in doubt.
« Last Edit: February 01, 2021, 02:37:17 am by Atomic Chicken »
Logged
As mentioned in the previous turn, the most exciting field of battle this year will be in the Arstotzkan capitol, with plenty of close-quarter fighting and siege warfare.  Arstotzka, accordingly, spent their design phase developing a high-altitude tactical bomber.