Scripted very inefficient. Take a look at the
example with quickSort or with bubblesort in just one command (slower than quickSort).
Written over a month ago without real testing:
pawn Код:
if(!strcmp(cmdtext, "/top5", true))
{
new
players_Data[MAX_PLAYERS][2],
tempString[128],
tempVar,
i,
j,
k
;
for(i = 0, j = GetMaxPlayers(); i < j; ++i)
{
if(IsPlayerConnected(i) && !IsPlayerNPC(i))
{
players_Data[tempVar][0] = GetPlayerScore(i);
players_Data[tempVar++][1] = i;
}
}
for(i = 0, j = 0; i < tempVar; ++i)
{
j = players_Data[i][0];
for(k = i - 1; k > -1; --k)
{
if(j > players_Data[k][0])
{
players_Data[k][0] ^= players_Data[k + 1][0], players_Data[k + 1][0] ^= players_Data[k][0], players_Data[k][0] ^= players_Data[k + 1][0];
players_Data[k][1] ^= players_Data[k + 1][1], players_Data[k + 1][1] ^= players_Data[k][1], players_Data[k][1] ^= players_Data[k + 1][1];
}
}
}
SendClientMessage(playerid, 0xFF0000FF, "» Top 5 players:");
for(i = 0; i < 5; ++i)
{
if(tempVar < i)
break;
GetPlayerName(players_Data[i][1], tempString, 20);
format(tempString, sizeof(tempString), "» %d. Player: %s [%d] - Score: %d", i, tempString, players_Data[i][1], players_Data[i][0]);
SendClientMessage(playerid, 0xFFFFFFFF, tempString);
}
return 1;
}
NOTE: Tell me if you want me to delete this piece of code, I'm just trying to help.
Thanks for the effort though.