04.05.2014, 10:39
(
Last edited by Nero_3D; 04/05/2014 at 11:34 AM.
)
Use md-sort = Sort multi-dimensional arrays (enums supported)
You need to sort your array descending by score and than you can extract the first three
Because you want to return more than one result we need to pass an array to it
You need to sort your array descending by score and than you can extract the first three
pawn Code:
GetHighScorePlayers(array[MAX_PLAYERS][2]) {
// and we store the playerid and the score in the array
foreach(new i : Player) {
array[i][0] = i;
array[i][1] = PlayerInfo[i][pScore];
}
// now we just sort the whole array descending by the value stored in [1] (the score)
SortDeepArray(array, 1, .order = SORT_DESC);
}
pawn Code:
// example
new
tPlayer[MAX_PLAYERS][2]
;
GetHighScorePlayers(tPlayer);
printf("1. %d Score: %d", tPlayer[0][0], tPlayer[0][1]);
printf("2. %d Score: %d", tPlayer[1][0], tPlayer[1][1]);
printf("3. %d Score: %d", tPlayer[2][0], tPlayer[2][1]);
printf("4. %d Score: %d", tPlayer[3][0], tPlayer[3][1]);
printf("5. %d Score: %d", tPlayer[4][0], tPlayer[4][1]);
// and so on

