24.08.2012, 10:01
Hello,
i have problem with Top Score.
It mess up when the player reach to 5 players.
Note: This is edited version of RyDer's Top Score
i have problem with Top Score.
It mess up when the player reach to 5 players.
Note: This is edited version of RyDer's Top Score
pawn Код:
CMD:topscore(playerid, params[])
{
new
playerScores[MAX_PLAYERS][rankingEnum],
index,
str[256] = "Awesome™ GamerX© (0.3e) - Unlimited Stuntings Top 5 Score",
player_Name[20]
;
foreach(Player, i)
{
if(IsPlayerConnected(i) && !IsPlayerNPC(i))
{
playerScores[index][player_Score] = GetPlayerScore(i);
playerScores[index++][player_ID] = i;
}
}
GetPlayerHighestScores(playerScores, 0, index);
foreach(Player, i)
{
if(i < index)
{
GetPlayerName(playerScores[i][player_ID], player_Name, sizeof(player_Name));
format(str, sizeof(str), ""white"%s\n%d. %s - "yellow"%d"white"", str, i + 1, player_Name, playerScores[i][player_Score]);
}
else
format(str, sizeof(str), ""white"%s\n%d. "red"N/A"white"", str, i + 1);
}
SendClientMessage(playerid, COLOR_YELLOW, "*** Awesome™ GamerX© (0.3e) - Unlimited Stuntings - Top 5 Scores ***");
ShowPlayerDialog(playerid, TOP5SCORE, DIALOG_STYLE_MSGBOX, "[AGX] Top 5 Score:", str, "OK", "");
return 1;
}
GetPlayerHighestScores(array[][rankingEnum], left, right)
{
new
tempLeft = left,
tempRight = right,
pivot = array[(left + right) / 2][player_Score],
tempVar
;
while(tempLeft <= tempRight)
{
while(array[tempLeft][player_Score] > pivot) tempLeft++;
while(array[tempRight][player_Score] < pivot) tempRight--;
if(tempLeft <= tempRight)
{
tempVar = array[tempLeft][player_Score], array[tempLeft][player_Score] = array[tempRight][player_Score], array[tempRight][player_Score] = tempVar;
tempVar = array[tempLeft][player_ID], array[tempLeft][player_ID] = array[tempRight][player_ID], array[tempRight][player_ID] = tempVar;
tempLeft++, tempRight--;
}
}
if(left < tempRight) GetPlayerHighestScores(array, left, tempRight);
if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right);
}