Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: DFHack script to allow burial of undead citizens  (Read 3398 times)

Pillbo

  • Bay Watcher
    • View Profile
DFHack script to allow burial of undead citizens
« on: November 23, 2020, 12:25:29 pm »

Maybe there's a fix I didn't know about but I made my own script to bury the undead I had laying on their coffins and figured I'd share it.

This script fixes a current (47.04) bug (0010396) that makes undead citizens unable to be put in coffins after being re-killed. To use it select with the cursor any part of a formerly undead citizen and run `bury-undead` in the dfhack terminal. It will find all the parts of that citizen and change the `unit.flags.dwad_dwarf`boolean to true making them buryable.

It likely works on were-creatures too but I haven't gotten the chance to test it yet. I tested it successfully on the couple a undead citizens corpses I had around but then a seasonal autosave got in the way and ended testing. I don't know about any problems but if you find one let me know, it handles the exceptions that I thought to try and gives useful feedback.

save this as `bury-undead.lua`
Code: [Select]
--[====[

bury-undead
===============================
This script fixes a current (47.04) bug (0010396) that makes undead citizens
unable to be put in coffins after being re-killed. To use it select with
the cursor any part of a formerly undead citizen and run `bury-undead` in
the dfhack terminal. It will find all their body parts and make them buryable.

by pillbo
]====]

local function buryUndead()
    local deadDwarf = dfhack.gui.getSelectedItem()
    local partsFound = 0
    local partsFixed = 0

    if deadDwarf == nil then
        return
    end

    -- check is cursor is on a corpse
    if df.item_corpsest:is_instance(deadDwarf) or df.item_corpsepiecest:is_instance(deadDwarf) then
        local unit = df.unit.find(deadDwarf.unit_id)
        local name = dfhack.TranslateName(dfhack.units.getVisibleName(unit))

        --loop through all corpses looking for other body parts from same dwarf
        for _, corpse in ipairs(df.global.world.items.other.ANY_CORPSE) do
            if corpse.unit_id == deadDwarf.unit_id then
                if corpse.flags.dead_dwarf == false then
                    corpse.flags.dead_dwarf = true
                    partsFixed = partsFixed + 1
                end
                partsFound = partsFound + 1
            end
        end
        print("Found " .. partsFound .. " pieces of " .. name .. ". Made " .. partsFixed .. " corpse pieces buryable.")
    else
        print("That's not a corpse! Put the cursor over a dead dwarf or body part that needs buried!")
    end
end

buryUndead()

« Last Edit: November 23, 2020, 12:28:25 pm by Pillbo »
Logged

FantasticDorf

  • Bay Watcher
    • View Profile
Re: DFHack script to allow burial of undead citizens
« Reply #1 on: June 29, 2021, 06:53:53 pm »

Old but gold, this script seems like a perfect compliment for accidental deaths via the sentient-butcher auto-dead-dwarf-false script when your non-central race citizens and visitors accidentally get mulched mixed with quickly marking all parts for good measure.  :)

Still, clearing up zombies and were's is pretty valuable too.
Logged