Math formula for leveling a player based on the value counted over the last level( just look )

So I have a skill system with levels, the way it works is they start at level 1, then they can gain progress.

Each level has their own progress limits, which is calculated by [lua]level*72[/lua]. So at level 1, they need to get 72 progress points to get to level 2, and then once at level 2, the progress resets to zero, and they need to get 158 progress points to get to level 3, and so on.

Now, the problem is, lets say I award them more progress points than the levels limit, so lets say I give them 158 progress points at level 1. First I calculate the difference, [lua]CurrentProgress + AddedProgress - max[/lua]. the value max is the max amount of points the current level can hold before going to a next level.

Now, here is the problem, if I give them 158 progress points at level one, it will only level them to 2, obviously. How can I figure out how many levels to give them based on the amount of progress i give them. This is really confusing to explain for me so ask questions if you’re still confused.

Are you using a timer say, like every 5 seconds to promote them if they have the right points? Or each time they get progress points you check?

Try math.floor(progress/(level*72))


4:23 PM - #swag wolf haley: ( Points + AdditionalPoints ) / 72
4:24 PM - Lau: that’s the level to set them to?
4:24 PM - #swag wolf haley: ok
4:24 PM - #swag wolf haley: 144 is 72 * 2
4:24 PM - #swag wolf haley: not 158
4:25 PM - #swag wolf haley: 144 / 72 = 2
4:25 PM - Lau: ROFL
4:25 PM - Lau: this is the results of coding high hahahahah

hey now, cowboy.

Say Totalprogress = Currentprogress + Addedprogress

if (Totalprogress > Max) {

  1. Calculate difference between Totalprogress and Max
  2. Level up the player
  3. Add the remaining difference, and repeat the check


Very rough example if someone is level 1 and you add 144 points, it would set them to level 2 and give them an additional 72 points.


function AddPoints(ply, PointsAdded)
Max = ply:CurrentLevel*72

TotalProgress = ply:CurrentProgress + PointsAdded

if (TotalProgress > Max) then

	ply:CurrentLevel += 1
	ply:CurrentProgress = 0
	Difference = math.abs(TotalProgress - Max)

	AddPoints(ply, Difference) 
	ply:CurrentProgress += PointsAdded



using this method, thanks.

That method has errors … Ill write one one sec…

[editline]7th August 2011[/editline]


Name: pointsToLevels
Return: int,int (new level, new points)
Param: int,int (current level, current points)
Desc: Converts the points into the levels
then returns the level and the points
1) Convert the level into points, add to current points
2) While the current amount of points is greater then the
amount of points needed for the next level, increment
the current level and subtract the amount of points
for that level from the current points
3) Return the current level and points

function pointsToLevels(intCurLevel, intCurPoints)
intCurPoints = intCurLevel * 72 + intCurPoints;
intNxtLevelPoints = intCurLevel + 1 * 72;

while(intCurPoints > intNxtLevelPoints)do
	intCurPoints = intCurPoints - intNxtLevelPoints;
	intCurLevel = intCurLevel + 1;
	intNxtLevelPoints = intCurLevel + 1 * 72;

return intCurLevel, intCurPoints;


Example Use

local curPoints = 0;
local curLevel = 0;
local addPoints = 7000;

local curLevel, curPoints = pointsToLevels(curLevel,curPoints+addPoints);

print("Level: " .. curLevel .. "

Points: " … curPoints … "
Next Level: " … curLevel * 72);