Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Allows for skill-based script running. DFHack Lua scripts only, unfortunately; no plugins or ruby scripts.
-- Allows skills to activate lua scripts.
--[[Example usage:
...syndrome stuff...
[SYN_CLASS:\COMMAND][SYN_CLASS:skillroll][SYN_CLASS:\WORKER_ID] For autoSyndrome/syndromeTrigger.
[SYN_CLASS:MELEE_COMBAT] Can use any skill.
[SYN_CLASS:20] Rolls d20. Skill will be weighted to this value.
[SYN_CLASS:DICEROLL_1] If diceroll ends up as one...
[SYN_CLASS:kill][SYN_CLASS:\SKILL_UNIT_ID] Theoretical kill-given-unit-id command; slayrace doesn't do so.
[SYN_CLASS:DICEROLL_10] If diceroll is between 1 and 10 (2-10, inclusive)...
[SYN_CLASS:force][SYN_CLASS:migrants][SYN_CLASS:player] Force migrants.
[SYN_CLASS:DICEROLL_19] If diceroll is between 10 and 19 (11-19, inclusive)...
[SYN_CLASS:fullheal][SYN_CLASS:\SKILL_UNIT_ID] Fully heals unit.
[SYN_CLASS:DICEROLL_20] If diceroll is at least 20...
[SYN_CLASS:shapechange][SYN_CLASS:\SKILL_UNIT_ID] Turns unit into any creature permanently.
]]
local args={...}
if args[1]=='dryrun' then
unit=df.global.world.units.all[0]
end
local unit = unit or df.unit.find(args[1])
local rando=dfhack.random.new()
local roll=rando:random(tonumber(args[3]))
local result=roll+(dfhack.units.getEffectiveSkill(unit,df.job_skill[args[2]])*(tonumber(args[3])/20))
result = result%1<.5 and math.floor(result) or math.ceil(result)
local i=4
local command={}
local scriptIsFinished
repeat
local arg=args[i]
if arg:find('DICEROLL') then
local dicerollnumber=tonumber(arg:match('%d+')) --yes this is truly naive as hell; I imagine if you put DICEROLL3%moa5oam3 it'll return 353.
if dicerollnumber>=result then
repeat
i=i+1
if not(i>#args) or (type(args[i])=='string' and args[i]:find('DICEROLL')) then
if args[i]~='\\SKILL_UNIT_ID' then table.insert(command,args[i]) else table.insert(command,args[1]) end
end
until i>#args or args[i]:find('DICEROLL')
dfhack.run_script(table.unpack(command))
scriptIsFinished=true
else
i=i+1
end
else
i=i+1
end
until i>#args or scriptIsFinished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.