Last active
August 29, 2015 14:01
-
-
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.
This file contains 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
--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