# Level Up XP Formula

Hi, I’m wondering what to do for the EXP Formula, so whenever a player levels their XP capacity increases, e.g. Level 1 has a MaxXP of 50 to reach, then level 2 it increases to 75 and so on.

What formula should I use to calculate the MaxXP that needs to be reached per level?

There’s different formulas out there e.g.

1. MaxXP = PlayerLevel * 50 (I don’t know if this is good because imagine if a player is really high level)

I feel like a more linear formula would help if anyone could show how I can do so?

2 Likes

It all depends on how frequently you award exp and in what increments exp is awarded in.

I always really liked this answer when I was looking into this very question myself. progression - RPG level-experience formula - Game Development Stack Exchange

I think expressing levels as a function of time spent playing is a very good way to control the pacing of your game, especially if its an RPG like World of Warcraft or Runescape for example. If you do this then you have a basis for what your algorithm looks like. That’s a great starting point.

That said it’s not too difficult to come up with a decent algorithm. I typically like to create an algorithm that is can be determined with a single variable like level. Typically I also like to use logarithms to prevent exponential growth

Here’s one I came up with in just a minute or two.

local level = 1
local xp_for_level = math.ceil((level * (level / 12) * math.log((level + 1) ^ 2)) * 300)

Here’s what this results in for levels 1-100

19:25:17.685  1 35  -  Edit
19:25:17.685  2 220  -  Edit
19:25:17.686  3 624  -  Edit
19:25:17.686  4 1288  -  Edit
19:25:17.686  5 2240  -  Edit
19:25:17.686  6 3503  -  Edit
19:25:17.686  7 5095  -  Edit
19:25:17.686  8 7032  -  Edit
19:25:17.686  9 9326  -  Edit
19:25:17.687  10 11990  -  Edit
19:25:17.687  11 15034  -  Edit
19:25:17.687  12 18468  -  Edit
19:25:17.687  13 22301  -  Edit
19:25:17.687  14 26539  -  Edit
19:25:17.687  15 31192  -  Edit
19:25:17.687  16 36266  -  Edit
19:25:17.687  17 41766  -  Edit
19:25:17.687  18 47700  -  Edit
19:25:17.687  19 54073  -  Edit
19:25:17.687  20 60891  -  Edit
19:25:17.688  21 68158  -  Edit
19:25:17.688  22 75879  -  Edit
19:25:17.688  23 84060  -  Edit
19:25:17.688  24 92704  -  Edit
19:25:17.688  25 101816  -  Edit
19:25:17.688  26 111400  -  Edit
19:25:17.688  27 121459  -  Edit
19:25:17.688  28 131998  -  Edit
19:25:17.688  29 143021  -  Edit
19:25:17.688  30 154530  -  Edit
19:25:17.688  31 166529  -  Edit
19:25:17.689  32 179022  -  Edit
19:25:17.689  33 192011  -  Edit
19:25:17.689  34 205500  -  Edit
19:25:17.689  35 219491  -  Edit
19:25:17.689  36 233988  -  Edit
19:25:17.689  37 248993  -  Edit
19:25:17.689  38 264510  -  Edit
19:25:17.689  39 280540  -  Edit
19:25:17.689  40 297086  -  Edit
19:25:17.690  41 314152  -  Edit
19:25:17.690  42 331738  -  Edit
19:25:17.690  43 349849  -  Edit
19:25:17.690  44 368485  -  Edit
19:25:17.690  45 387650  -  Edit
19:25:17.690  46 407346  -  Edit
19:25:17.690  47 427575  -  Edit
19:25:17.690  48 448338  -  Edit
19:25:17.690  49 469639  -  Edit
19:25:17.690  50 491479  -  Edit
19:25:17.690  51 513860  -  Edit
19:25:17.690  52 536784  -  Edit
19:25:17.691  53 560253  -  Edit
19:25:17.691  54 584270  -  Edit
19:25:17.691  55 608835  -  Edit
19:25:17.691  56 633951  -  Edit
19:25:17.691  57 659619  -  Edit
19:25:17.691  58 685842  -  Edit
19:25:17.691  59 712621  -  Edit
19:25:17.691  60 739958  -  Edit
19:25:17.691  61 767854  -  Edit
19:25:17.691  62 796311  -  Edit
19:25:17.692  63 825331  -  Edit
19:25:17.692  64 854915  -  Edit
19:25:17.692  65 885065  -  Edit
19:25:17.692  66 915783  -  Edit
19:25:17.692  67 947069  -  Edit
19:25:17.692  68 978926  -  Edit
19:25:17.692  69 1011355  -  Edit
19:25:17.692  70 1044357  -  Edit
19:25:17.692  71 1077934  -  Edit
19:25:17.692  72 1112088  -  Edit
19:25:17.692  73 1146819  -  Edit
19:25:17.692  74 1182129  -  Edit
19:25:17.693  75 1218019  -  Edit
19:25:17.693  76 1254492  -  Edit
19:25:17.693  77 1291547  -  Edit
19:25:17.693  78 1329187  -  Edit
19:25:17.693  79 1367412  -  Edit
19:25:17.693  80 1406224  -  Edit
19:25:17.693  81 1445625  -  Edit
19:25:17.693  82 1485615  -  Edit
19:25:17.693  83 1526195  -  Edit
19:25:17.693  84 1567368  -  Edit
19:25:17.694  85 1609133  -  Edit
19:25:17.694  86 1651493  -  Edit
19:25:17.694  87 1694449  -  Edit
19:25:17.694  88 1738001  -  Edit
19:25:17.694  89 1782150  -  Edit
19:25:17.694  90 1826899  -  Edit
19:25:17.694  91 1872247  -  Edit
19:25:17.694  92 1918197  -  Edit
19:25:17.694  93 1964748  -  Edit
19:25:17.694  94 2011903  -  Edit
19:25:17.694  95 2059663  -  Edit
19:25:17.694  96 2108027  -  Edit
19:25:17.694  97 2156998  -  Edit
19:25:17.695  98 2206577  -  Edit
19:25:17.695  99 2256764  -  Edit
19:25:17.695  100 2307561  -  Edit

With this, say you wanted a player to reach level 10 in an hour. Just take the total XP for the first 10 levels (41353 xp in my example) then divide by 60 to get what XP you should give at a minimum per minute to each player, assuming they’re doing something XP worthy. 41353 / 60 = 689.217 XP per minute. Now this shows that my algorithm really sucks, so you can make it better now!

7 Likes

thank you very much for this example

can you explain to me the certain values in the algorithm ? for example what does the 12 represent and what does the ^ 2 represent, and what does the *300 represent, etc

I just sort of threw those in there to get a number that I felt looked nice at level 1 and level 100. They’re really just modifiers to make the number grow differently. You can play around with those or add more modifiers to make the algorithm generate the numbers you’re looking for.

how do you calculate the max_xp for each level for example lets say i wanted to make an xp system that could increase by more than 1 level how would i do that like lets say going up 5 levels

Assuming you’re setting the XP value to 0 + any extra after you level up each time?

I envision a set of functions like this:

local current_level = 1;
local current_xp = 40;

local function xp_needed_for_level(level: number)
return math.ceil((level * (level / 12) * math.log((level + 1) ^ 2)) * 300);
end

local function level_up()
local xp_for_level = xp_needed_for_level(current_level + 1);

local remaining_xp = current_xp - xp_for_level;

if (remaining_xp < 0) then
error('Cannot level up; not enough xp.');
return;
end

current_level += 1;
current_xp = 0;

award_xp(remaining_xp);
end

function award_xp(awarded_xp: number)
local xp_for_level = xp_needed_for_level(current_level + 1);

local xp = current_xp + awarded_xp;

if (xp >= xp_for_level) then
level_up();
end
end

award_xp(4000);

4 Likes