Percent calculation
#1

Код:
XpToNextLvl[playerid]=20;
Rank[playerid]=1;

if(GetPlayerScore(playerid)>=XpToNextLvl[playerid])
{
 XpToNextLvl[playerid]=XpToNextLvl[playerid]+Rank[playerid]*5; // 20+1*5=25 (if im rank 1)
 Rank[playerid]++;
}

percent=(100*GetPlayerScore(playerid))/XpToNextLvl[playerid];
as you can see i'm creating ranking up system. But there's a problem. I don't know how to count percent for following ranks. Minimum rank XP = 0 %, Maximum rank XP = 100 %. So for example if I'm rank 2, 20 XP should be equal 0% and 25 XP = 100%. My percent formula above calculates percent corretly only for 1st rank, I need fomula for further Ranks
Reply
#2

Looks fine, show more code, and how/where you defining "percent"
Reply
#3

pawn Код:
Float:GetPercentage(Float:score, Float:minscore, Float:maxscore)
{
    return (((score - minscore) / (maxscore - minscore)) * 100.0);
}
Sample:
pawn Код:
printf("%0.0f%%", GetPercentage(20, 20, 25));

// Result: 0%
Reply
#4

Quote:
Originally Posted by Gammix
Посмотреть сообщение
pawn Код:
Float:GetPercentage(Float:score, Float:minscore, Float:maxscore)
{
    return (((score - minscore) / (maxscore - minscore)) * 100.0);
}
Sample:
pawn Код:
printf("%0.0f%%", GetPercentage(20, 20, 25));

// Result: 0%
Thanksss
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)