15.03.2014, 19:40
Hola a todos, queria saber si hay alguna forma de saber quien tiene mayor score dentro del juego?
Yo encontre esta forma, pero quiero saber si hay alguna mas efectiva u optimizada:
Yo encontre esta forma, pero quiero saber si hay alguna mas efectiva u optimizada:
Код:
enum Ranking{Score, Id} new PlayerScore[MAX_PLAYERS][Ranking]; new MostScore; new NombreMostScore[MAX_PLAYERS]; new IdMostScore; public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp("/vermejorscore", cmdtext, true, 10) == 0) { new n = 0, Rmsg[128]; for (new i = 0; i < MAX_PLAYERS; i++) { if (IsPlayerConnected(i) && !IsPlayerNPC(i)) { PlayerScore[n][Score] = GetPlayerScore(i); PlayerScore[n][Id] = i; n++; } } GetPlayerHighestScores(PlayerScore, 0, n); for (new i = 0; i < 1; i++) { new name[MAX_PLAYER_NAME]; GetPlayerName(PlayerScore[i][Id], name, sizeof(name)); format(Rmsg, sizeof(Rmsg), "[%d]%s Score %d ", i, name, PlayerScore[i][Score]); SendClientMessage(playerid, -1, Rmsg); MostScore = PlayerScore[i][Score]; format(NombreMostScore, sizeof(NombreMostScore), "%s", name); IdMostScore = i; } return 1; } return 0; } stock GetPlayerHighestScores(array[][Ranking], left, right) { new tempLeft = left, tempRight = right, pivot = array[(left + right) / 2][Score], tempVar; while(tempLeft <= tempRight) { while(array[tempLeft][Score] > pivot) tempLeft++; while(array[tempRight][Score] < pivot) tempRight--; if(tempLeft <= tempRight) { tempVar = array[tempLeft][Score], array[tempLeft][Score] = array[tempRight][Score], array[tempRight][Score] = tempVar; tempVar = array[tempLeft][Id], array[tempLeft][Id] = array[tempRight][Id], array[tempRight][Id] = tempVar; tempLeft++, tempRight--; } } if(left < tempRight) GetPlayerHighestScores(array, left, tempRight); if(tempLeft < right) GetPlayerHighestScores(array, tempLeft, right); }