# Creating an in game experience system

This has been asks at least a quarter dozen times, I know. This has a second part the others didn't. In my question I am looking towards a math function that can be used and inverted for finding exp/ levels.

From my reading, Runescape does: Exp for next level = (Previous Level XP + Previous Level XP * 10%)

What kind of math function could I look to to find your current level from a number of XP?

• Possible duplicate of Algorithm for dynamically calculating a level based on experience points? – Vaillancourt Feb 22 '17 at 12:43
• @AlexandreVaillancourt I was looking towards a formula or math function from the getgo. That is a bit different from the dupe. Reguardless I found the answer here. The solution, come up with my own number formula and either hard code it or generate and save it in the game. A exp/ level table. – Evan Carslake Feb 22 '17 at 12:48
• The formula you gave is trivial to invert, so there's no particular reason you'd need to store it in a table. – DMGregory Feb 22 '17 at 12:58
• @DMGregory that was just from what I read, not looking to implement it. It was just an example to show I did make an effort. (also by invert I meant the opposite, hp > level and level > hp). The solution as below, I will generate an array of ints, each one taking the value of the previous and adding to it. – Evan Carslake Feb 22 '17 at 13:02
• 'Exp for level n = (baseValue)*(multiplier)^n' solving for n yeilds 'n=floor(ln(exp/baseValue)/ln(multiplier))' in your Runescape example the multiplier=2.1 . – Will Apr 2 '17 at 1:38

You can look at Blizzards WoW implementation. On server, they have a database table which is responsible for for holding XP values for each level, and the level player is on now. So it basically fetches the data from database and applies it to the client. Also, on wowpedia I guess, they have many formulas used for different in-game mechanics (damage multipliers, damage mitigation with armor, etc).

• That is what I will do, thanks. I will probably come up with a generic math formula/ pattern. From there I will generate a xp/ level table when the game loads. That works perfect. – Evan Carslake Feb 22 '17 at 12:50

I don't see why you would ever want to use an algorithm to determine the level based on an experience total. For one thing - you need to be storing the player's level, not only because you're going to need it and don't want to have to calculate it but also because you may adjust your experience curve at some point and you don't want that to impact player levels.

Secondly, you're making a pretty big assumption here that the experience per level needs to scale. Personally, I think having absurd amounts of experience/level to be absurd and pointless because it either gets too grind-heavy or you need to ramp up experience gains to compensate.

IE: why should killing an equal level mob at level 50 give more experience than killing an equal level mob at level 1? In my opinion... it probably shouldn't. What a lot of games do is simply adjust exp gains based on relative level so that it encourages progression but allows for a static exp/level number.

If you want a scaling experience system then I would suggest what you said above: simply create a table and store the exp per level values. You shouldn't have so many levels that it becomes a burden and should be relatively easy to set up.

• yeah that is what the answer was to do. I didn't think that at first. So basically I do this: Create a formula, populate an int array with it, index being the level. The pattern is: Exp Needed is exp from last level * 110%. Each level takes an additional 10% exp than needed for previous level. This will work perfect. – Evan Carslake Feb 23 '17 at 15:20
• I would say that you don't even need to do an array, unless what you mean is for initially creating the values to stick them in a table (then yes that would be easiest unless you want to do it manually). Otherwise you'd just need to grab the current level and exp to next level from the table when they log in and calculate each level as the player levels if you don't want to query the table after the initial login. – Aithos Feb 23 '17 at 16:17