Skip to content

Instantly share code, notes, and snippets.

@IndigoFenix IndigoFenix/add-exp.lua
Last active Aug 29, 2015

What would you like to do?
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 == skillId then
skill = soulSkill
foundSkill = true
if foundSkill then
-- Let's not train beyond the max skill
if skill.rating >= max_skill then
return false
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
else = skillId
skill.experience = amount
skill.rating = 0
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.