Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
Basically, to get the xp required for the next level, they start at 200, add 0 and 200, increase the 200 to 300, add to get 500, increase by 300 to 400, add to get 900, etc...
The formula should be:
(level + 1) * 100 + prevLevelXp
Which gets turned into a recursive algorithm >:O
If you have low levels (like 10 or 20 in your map), it would be fine to use this... but then again, why wouldn't it be fine to cache the amounts required yourself in such cases? ._.
If you have values like 100, this recursive algorithm is going to be costly :/
100 function calls... NEVERMIND. You can use a loop.
It's going to look like this:
JASS:
function GetRequiredXP takes integer level returns integer
local integer xp = 0
loop
exitwhen level == 0
set xp = xp + (level + 1) * 100
set level = level - 1
endloop
return xp
endfunction
Now, to get the differences, you could do this: GetRequiredXP(5) - GetRequiredXP(2)
Or, for more optimizations, you could use this:
JASS:
function GetRequiredXPDifference takes integer level1, integer level2 returns integer
local integer xp = 0
loop
exitwhen level1 == level2
set xp = xp + (level1 + 1) * 100
set level1 = level1 - 1
endloop
return xp
endfunction
edit
All of this assumes you haven't touched any of the XP-config stuff in the "Gameplay Constants"
edit
GetRequiredXPDifference is optimized, so it's going to crash if level1 is less than level2.
You can use checks for that :>
JASS:
if int1 >= int2 then
set xp = GetRequiredXPDifference(int1, int2)
else
set xp = GetRequiredXPDifference(int2, int1)
endif
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.