Created
March 8, 2014 23:18
-
-
Save Putnam3145/9440576 to your computer and use it in GitHub Desktop.
Allows skills to be changed with DFHack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Allows skills to be changed with DFHack. | |
--[[ | |
Args are arranged like this: | |
unitID SKILL level ADD/SUBTRACT/SET | |
SKILL being anything such as DETAILSTONE, level being a number that it will be set to (15 is legendary, 0 is dabbling). | |
Add will add skill levels, subtract will subtract, set will place it at exactly the level you put in. | |
]] | |
local utils=require('utils') | |
local args={...} | |
local skills=df.unit.find(args[1]).status.current_soul.skills | |
local skill=df.job_skill[tostring(args[2]):upper()] | |
local level=tonumber(args[3]) or 0 | |
local argfunctions={ | |
__index=function(t,k) | |
qerror(k..' is not a valid setting! Valid settings are SET, ADD and SUBTRACT.') | |
end, | |
set=function(skills,skill,level) | |
utils.insert_or_update(skills, {new=true, id=skill, rating=level}, 'id') | |
end, | |
add=function(skills,skill,level) | |
local skillExists,oldSkill=utils.linear_index(skills,skill,'id') | |
if skillExists then | |
oldSkill.rating=level+oldSkill.rating | |
else | |
argfunctions.set(skills,skill,level) | |
end | |
end, | |
subtract=function(skills,skill,level) | |
local skillExists,oldSkill=utils.linear_index(skills,skill,'id') | |
if skillExists then | |
local newRating=oldSkill['rating'] or 0 | |
oldSkill.rating=oldSkill.rating-level | |
if oldSkill.rating<0 or (oldSkill.rating==0 and oldSkill.experience<=0) then skills:erase(skillExists) end | |
end | |
end | |
} | |
setmetatable(argfunctions,argfunctions) | |
argfunctions[args[4]:lower()](skills,skill,level) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment