# Exp equation for enemy and player in rpg

I am making an rpg game with specific leveling system I want when a level 1 player fights a level 25 monster to level up to level 20-25 then when he goes and fight the same monster he then levels slowly like level 30 then level 32, 35, 36 on his next 4 fights respectively meaning you must always fight a monster higher than your level else you will level up really slow

At the same time I want a level 1 player to fight a 20000 enemy and then gains like 10000 levels then on his next fight he gains like 50000 then he gains another 50000 meaning that if the player fights a really strong monster he levels up fast until he reaches the level of that monster then he level up real slowly, This system doesn't have to be perfect at all but you get the idea So any help on the equations, I searched really hard and found elementary functions like

Power function:

y = a * x^b + c

Or Linear functions:

y = mx + b

Also exp. functions and log functions but I cant seem to get the desired effect or even get any close to it, Any help or any tip on where I can find my answer is highly appreciated ty

• Your two equations are both linear functions – Bálint Mar 25 '17 at 14:28
• I am sorry I had 1 txt file and it was messed up all fixed now my bad – La3eb Mar 25 '17 at 14:41
• Possible duplicate of How to balance experience gain in an RPG – Philipp Mar 25 '17 at 16:06
• Philipp I have read your post long before I placed mine I don't see any resemblance between both questions your answer is basically saying how to make an MMORPG leveling system mine is very different if you read it carefully I don't care about the time it takes to gain each level and I don't care about the level ^ c algo. ( I tried it didn't work), What I simply ask is this when my level 1 player hits a level 20,000 monster he will gain exp to make him go just above 20,000 and stop gaining any meaningful levels after that now I do understand that (level ^ c) * (level ^ c) makes sense but – La3eb Mar 25 '17 at 17:11
• It the player exp needed per level doesn't work at all in my case I am not looking for time needed for each level the only thing that I want is when a player fights a level 20 he goes to level 20 himself and when he fights level 20,000 he goes to level 20,000 and after that its all scrap so (time = c1 ^ (1 + Level / c2)). doesn't work with me at all, Not even 1 bit, And again I already tested your answer long long ago before I asked this question, Thanks for wanting to help tho XD – La3eb Mar 25 '17 at 17:13

It will be a different solution for each game, for example, some games will only give, you experience if the enemy is on a similar level. You need to start by giving a hard look to your requirements.

First, we need to start by recognize that the experience gained shall never be negative. Furthermore, I am inferring from your description that when you fight monsters of lower level than you are, it will never result in zero experience, but in increasingly diminishing values instead.

Second, I suspect you want to fix the amount of experience the playing will gain by fighting a monster of the same level.

If we are looking for a function g, that given a difference of levels x (monster_level - player_level) with the description provided, it follows that:

• Lim(g(x))_x->-∞ = 0: When the difference tends to negative infinity, the gained exprience tends to zero
• g(0) = k: When the difference is zero, the gained experience is a constant value k
• dg(x)/dx > 0: The gained experience is a growing function, the greater the difference of levels the greater the gained experience

We cannot represent this with a linear function. To speak is loose terms, a stright line that doesn't cross the origin, and meets the horizontal axis at negative infinity... is an horizontal line. So its slope would be zero. However, we need a slope greater than zero.

It cannot be a quadratic function, because they are not always growing. In fact, you will have a similar problem with higher order functions.

Trigonometric functions are periodic functions, so we can discard those too...

Logarithms are growing on the positive, but decreasing and with an imaginary part on the negative. So, do not base the function on that either...

Exponential functions fit the bill. For example take g(x) = 2^x:

• Lim(2^x)_x->-∞ = 0
• 2^0 = 1
• d/dx {2^x} = log(2) * 2^x > 0

It is very easy to tweak by changing the cosntant 2 to a parameter, but whatever constant we put there, we will get 1 when x = 0. We could consider to add another term, but that would change the limit when x -> -∞. Therefore, what we do is mess with the exponent, in particular:

g(x) = k^(x+1)

With this function, you get g(x) = k when x = 0. The next thing you will want is to tweak how fast it grows, you can do that by adding a factor to x:

g(x) = k^(fx+1)

If I want to make sure that g(a) = b, I do this:

g(x) = k^(fx+1)
g(a) = b
=>
b = k^(fa+1)
=>
log(b) = log(k^(fa+1)
=>
log(b) = (fa+1)*log(k)
=>
log(b)/log(k) = fa+1
=>
log(b)/log(k) - 1 = fa
=>
log(b)/log(k) - 1
------------------ = f
a


I can rewrite the function like this:

g(x) = k^((log(b)/log(k) - 1)*x/a + 1)
=>
g(x) = k*k^((log(b)/log(k) - 1)*x/a)
=>
g(x) = k*(b/k)^(x/a)


It will have the following properties:

• Lim(g(x))_x->-∞ = 0
• g(0) = k
• g(a) = b
• dg(x)/dx > 0 Where k, a and b. In addition, remember that x is monster_level - player_level.