Skip to content

Instantly share code, notes, and snippets.

@IndigoFenix
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndigoFenix/ee7fea7ff0512146d206 to your computer and use it in GitHub Desktop.
Save IndigoFenix/ee7fea7ff0512146d206 to your computer and use it in GitHub Desktop.
Adds a set amount of experience in a particular skill to a unit.
--Gives a unit a certain amount of experience in a certain skill, leveling them up as appropriate. Intended for autosyndrome. Params: Unit id, skill name, exp. amount, max level (20 by default).
local args = {...}
local ok = true
--local unit=dfhack.gui.getSelectedUnit()
local unit = df.unit.find(tonumber(args[1]))
local skillname = args[2]
local amount = args[3]
local maxlevel = args[4]
if maxlevel == nil then maxlevel = 20 end
local skillId = df.job_skill[skillname]
if skillId == nil or skillId == -1 then print("Invalid skill name") ok = false end
if ok == true then
local skill = df.unit_skill:new()
local foundSkill = false
for k, soulSkill in ipairs(unit.status.current_soul.skills) do
if soulSkill.id == skillId then
skill = soulSkill
foundSkill = true
break
end
end
if foundSkill then
-- Let's not train beyond the max skill
if skill.rating >= max_skill then
return false
end
skill.experience = skill.experience + amount
if skill.experience > 100 * skill.rating + 500 then
skill.experience = skill.experience - (100 * skill.rating + 500)
skill.rating = skill.rating + 1
end
else
skill.id = skillId
skill.experience = amount
skill.rating = 0
unit.status.current_soul.skills:insert('#',skill)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment