Funtion ignoring playerid 0
#1

pawn Код:
#define GetHighestScores(%1,%2) \
    new %1[2][%2]; \
    GetHighestScoresEx(%1, %2)
pawn Код:
enum { GS_score, GS_playerid }; //To give them a name instead of using 0 and 1
pawn Код:
stock GetHighestScoresEx(array[][], maxposition)
    for(new i, m = GetMaxPlayers(), y, j, score; i < m; score = GetPlayerScore(++i))
        for(y = 0; y < maxposition; y++)
            if(score > array[0][y])
            {
                for(j = maxposition - 2; j >= y; j--)
                    array[0][j + 1] = array[0][j],
                    array[1][j + 1] = array[1][j];
                array[0][y] = score;
                array[1][y] = i;
                break;
            }
pawn Код:
GetHighestScores(Scores, 5);
printf("1st Place - ID: %i Score: %i",Scores[GS_playerid][0],Scores[GS_score][0]);
printf("2nd Place - ID: %i Score: %i",Scores[GS_playerid][1],Scores[GS_score][1]);
printf("3rd Place - ID: %i Score: %i",Scores[GS_playerid][2],Scores[GS_score][2]);
Code came from: http://forum.sa-mp.com/index.php?topic=85645.0

It works great except that it ignores playerid 0, if I have three folks on the server, ID 0 has score 30, ID 1 has 20, ID 2 has 10,

it will print out something like:

Highest - Score 20 - ID 1
Second - Score 10 - ID 2
Third - Score 0 - 0

Anyone know why?
Reply
#2

Quote:
Originally Posted by ssǝן‾ʎ
It's because you do "++i" instead of "i++".
Thank you very much!
Reply
#3

Deleted.

Never mind, I found the problem.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)