Percent calculation - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Percent calculation (
/showthread.php?tid=615387)
Percent calculation -
ax1 - 21.08.2016
Код:
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
Re: Percent calculation -
Shinja - 21.08.2016
Looks fine, show more code, and how/where you defining "percent"
Re: Percent calculation -
Gammix - 21.08.2016
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%
Re: Percent calculation -
ax1 - 22.08.2016
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