SA-MP Forums Archive
Funtion ignoring playerid 0 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Funtion ignoring playerid 0 (/showthread.php?tid=95562)



Funtion ignoring playerid 0 - yeswecanchange09 - 04.09.2009

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?


Re: Funtion ignoring playerid 0 - yeswecanchange09 - 04.09.2009

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


Re: Funtion ignoring playerid 0 - yeswecanchange09 - 04.09.2009

Deleted.

Never mind, I found the problem.