Skip to content

Instantly share code, notes, and snippets.

@warmist
Created January 18, 2015 15:42
Show Gist options
  • Save warmist/f477d37a2083d5bedf7a to your computer and use it in GitHub Desktop.
Save warmist/f477d37a2083d5bedf7a to your computer and use it in GitHub Desktop.
add_xp
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
@Raidau
Copy link

Raidau commented Feb 3, 2015

replace
if thresh>s_entry.experience then
with?
if thresh<s_entry.experience then

I got a crash until I changed the condition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment