04.02.2014, 16:35
A bit simplified version:
Your pawno was crashing due to the amount of cases.
You could see it as if you were using multiple if-statements:
This would be 100,000 if-statements long, which are compiled one by one.
pawn Код:
static const Ranks[10] = {0, 500, 2000, 4000, 8000, 10000, 15000, 25000, 30000, 40000};
stock SetPlayerRank(playerid)
{
new score = GetPlayerScore(playerid);
// First, set playerrank to 0
PlayerRank[playerid] = 0;
// Loop through the Ranks array
for (new i; i < sizeof(Ranks); i++)
{
// If your score is higher than the value stored in the current index of Ranks
if (score >= Ranks[i])
// Add 1 to the playerrank
PlayerRank[playerid]++;
else // If the score is lower than the value in the current index of Ranks
break; // Exit the loop
}
return 1;
}
You could see it as if you were using multiple if-statements:
pawn Код:
if (score == 0) PlayerRank[playerid] = 1;
if (score == 1) PlayerRank[playerid] = 1;
if (score == 2) PlayerRank[playerid] = 1;
if (score == 3) PlayerRank[playerid] = 1;
if (score == 4) PlayerRank[playerid] = 1;
if (score == 5) PlayerRank[playerid] = 1;
if (score == 6) PlayerRank[playerid] = 1;
if (score == 7) PlayerRank[playerid] = 1;
if (score == 8) PlayerRank[playerid] = 1;
if (score == 9) PlayerRank[playerid] = 1;
.
.
.
if (score == 99997) PlayerRank[playerid] = 10;
if (score == 99998) PlayerRank[playerid] = 10;
if (score == 99999) PlayerRank[playerid] = 10;