Created
January 18, 2015 15:42
-
-
Save warmist/f477d37a2083d5bedf7a to your computer and use it in GitHub Desktop.
add_xp
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
function add_xp(unit,skill_id,xp) | |
--get skill entry | |
local skills=unit.status.current_soul.skills | |
local s_entry=utils.binsearch(skills,skill_id,'id') | |
--does not exist so create skill entry | |
if not s_entry then | |
s_entry=df.unit_skill:new() | |
s_entry.id = skill_id | |
utils.insert_sorted(skills,s_entry,'id') | |
end | |
--add xp | |
s_entry.experience=s_entry.experience+xp | |
--check if it levels up | |
repeat | |
local thresh=df.skill_rating.attrs[s_entry.rating].xp_threshold | |
if thresh>s_entry.experience then | |
s_entry.rating=s_entry.rating+1 | |
s_entry.experience=s_entry.experience-thresh | |
else | |
break | |
end | |
until false | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
replace
if thresh>s_entry.experience then
with?
if thresh<s_entry.experience then
I got a crash until I changed the condition