Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Script: show-cursed  (Read 3610 times)

Bo-Rufus CMVII

  • Bay Watcher
    • View Profile
Script: show-cursed
« on: March 09, 2014, 12:02:31 am »

"Hi, I'm Urist Van Helsing and I'm here to check everyone's pulse."

For when you don't feel like playing find-the-vampire.  Outputs cursed citizens' names followed by the name of the curse (e.g., "vampire").

Tested with dfhack r3.  Finds my pet vampire, but only experience will tell if the logic is right for all curse types.

Store in hack/scripts/, or maybe hack/scripts/cheats/ ...

Invoke as show-cursed

show-cursed.lua
Code: [Select]
-- Show any cursed citizens.
--
-- Version 1.0

local args = {...}
local dorfs = {}
local name

dfhack.color(nil)

-- sanity checks:
if not dfhack.isMapLoaded() then
    qerror('show-cursed only works when a map is loaded.')
end
if #args > 0 then
   qerror('No arguments are currently allowed')
end

-- comparator for sorting units by name:
function compNames(a,b)
    return dfhack.TranslateName(dfhack.units.getVisibleName(a)) < dfhack.TranslateName(dfhack.units.getVisibleName(b))
end

-- build a list of citizens:
for _,v in ipairs(df.global.world.units.active) do
    if dfhack.units.isCitizen(v) then
        table.insert(dorfs,v)
    end
end

-- sort the list by name:
table.sort(dorfs,compNames)

-- show the list:
for _,v in ipairs(dorfs) do
    name = dfhack.units.getIdentity(v)
    if name == nil then
--        print(name)
    else
       print(dfhack.TranslateName(dfhack.units.getVisibleName(v)),v.curse.name)
    end
end
dfhack.color(nil)
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: Script: show-cursed
« Reply #1 on: March 09, 2014, 01:01:29 pm »

I think it'd be better to just ignore arguments than to give an error when any are given.

Also, since "name" is going to change for every iteration of that for loop, you'll probably want to have name defined locally there.

Also, the "nil" is implied in a functions arguments if you have no argument: dfhack.color() is the same as dfhack.color(nil).

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Script: show-cursed
« Reply #2 on: March 09, 2014, 01:45:12 pm »

There's already a "cursecheck" plugin (seemingly dating back to version 0.34.05 according to its documentation) which scans either the entire fortress or the tile under your cursor and counts the number of cursed units and optionally also does the following:
1. print the full name, date of birth, date of curse, and the "type" of curse (recognizes "ghost", "zombie", "necromancer", "werebeast", and "vampire")
2. give the cursed unit a special nickname to indicate their curse type
3. optionally include units that are already dead (so you can retroactively determine if they were cursed)
4. list the exact details of their curse
« Last Edit: March 09, 2014, 01:47:47 pm by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Bo-Rufus CMVII

  • Bay Watcher
    • View Profile
Re: Script: show-cursed
« Reply #3 on: March 09, 2014, 04:54:03 pm »

Ah, great.  I didn't realize that cursecheck would show anything but the count, and I was tired of iterating over 50+ dorfs to find out which one it is.

(Now that I try it I notice that it only shows their real name, so you've still got a problem figuring out who it is.)
Logged