Let's say you have a game about pressing a button, each time you press it, the XP goes up, and if you collect enough, you level up. Something people normally do wrong, is setting a linear ecuation for the level system, wich will at some point make leveling up super hard to do. By dividing, it will make leveling up the same at some point. So nerds like me use another mathematical trick.
What is a logarithm?
A logarithm is a quantity representing the power to which a fixed number (the base) must be raised to produce a given number. To understand it better, lets have the next example
local Logarithm = math.log(1000,10) print(Logarithm)
why did the output print 3? The output said 3 beacouse 10(Input Y) ^ 3(Output) is 1000(Input X)
We use math.log(x,y) to calculate the logarithm of x in base y.
If you draw a line joining all the solutions with the Base 2, you'll have a line, wich joins all the powers of 2 in a circular way. Let's check some of the first powers of 2:
1 2 4 8 16 32 64 128 256
You can see that each time we hit a power of 2, the difference highers, but if we draw a line that pass through all of the numbers, you'll see that each time the line hits a power of 2, it increases less and less.
This will help us make a level system, so lets start it
local Level = 1 local XP = 0 local PointsForNextLvl function AddXP(N) PointsForNextLvl = math.ceil(math.log(Level+1,1.5)*100) if XP+N >= PointsForNextLvl then XP = math.abs(PointsForNextLvl-(N+XP)) Level = Level+1 else XP = XP+N end end
Let's explain it. First, the Values: Level, is the level the player has, you need to change it to the actual player's level value, same for XP. PointsForNextLvl represents the number of XP you need for the next lvl.
The function below is to add Experience Points: Points for next lvl will change to the rounded logarithm of the players level with a base of 1.5 times 100. It will check if this value is lower than the XP the player is gonna get, and if it is, It'll level up the player and change the XP to the absolute value of the difference between points for next lvl and the XP the player is gonna get+the current XP (|a-b|) wich is a way to say the numbers between two numbers,even if one is negative. If the points for the next level is higher than the points the player will get, it will just change the XP.
>The XP Value should be a Number Value
So it should work perfectly now, if you feel that the rate of leveling up is too slow or too fast, change the base of the logarithm (1.5) inside the line 6. Don't put 0 as it will result in a mathematical error.
How should I reward players?
Every game is centered about a game mechanic, it could be a tycoon, a simulator, a game where you have a super power, an RPG... Each time the player does the main mechanic, you should reward the player, in tycoons and simulators is simple, you do the game mechanic, you earn money, and you then buy things to make faster money. In an RPG, the player should be rewarded each time he/she completes a main mission. And in a game where you have a super power, you should make challenges with that game mechanic to make the players use it in order to get a reward, being each challenge, always original.
But if you make a way to earn XP other than using the game mechanic, or something important to the game. Then the reward should be worse than by doing the mechanic.
Lastly, if there's a broken way to earn XP. It should be by doing the game mechanic. As people wich break the game by a secondary mission or an optional challenge, will not experience the actuall game.
Feel free to comment and make a feedback, I really like it. C ya in the next tutorial!
Med Written By idonthackbutiflame
See idonthackbutiflame's profile on Roblox