07.10.2015, 16:50
here u go:
example of usage:
and give money to the first player:
source: https://sampforum.blast.hk/showthread.php?pid=1092420#pid1092420
Код:
enum rankingEnum { player_Score, player_ID } stock 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); }
Код:
new playerScores[MAX_PLAYERS][rankingEnum], index ; for(new i; i != MAX_PLAYERS; ++i) { if(IsPlayerConnected(i) && !IsPlayerNPC(i)) { playerScores[index][player_Score] = GetPlayerScore(i); playerScores[index][player_ID] = i; ++index; } } GetPlayerHighestScores(playerScores, 0, index);
Код:
printf("Player %d with %d kills got 9999$", playerScores[0][player_ID], playerScores[0][player_Score], 0);