SA-MP Forums Archive
Help with sorting - 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: Help with sorting (/showthread.php?tid=159108)



Help with sorting - cloud9 - 12.07.2010

Hi i am making a DM, were at a end of a round i need the players with top 3 amount of kills to be declared as winners. I am having a bit of trouble with sorting those value, i store them in a variable like KILLS[playerid] = 2; some thing of that sort so how do i find who has the top 3 amount of kills. I used some sorting fucntion before but it didnt work good


Re: Help with sorting - (SF)Noobanatior - 12.07.2010

pawn Код:
new winners[3] ={INVALID_PLAYER_ID,INVALID_PLAYER_ID,INVALID_PLAYER_ID};
for(new i=0;i<MAX_PLAYERS;i++){
    if(!IsPlayerConnected(i))continue;
    if(KILLS[i] > KILLS[winners[0]])winners[0]=i;
}
for(new i=0;i<MAX_PLAYERS;i++){
    if(winners[0] == INVALID_PLAYER_ID)break;
    if(!IsPlayerConnected(i))continue;
    if(i == winners[0])continue;
    if(KILLS[i] > KILLS[winners[1]])winners[1]=i;
}
for(new i=0;i<MAX_PLAYERS;i++){
    if(winners[0] == INVALID_PLAYER_ID || winners[1] == INVALID_PLAYER_ID)break;
    if(!IsPlayerConnected(i))continue;
    if(i == winners[0] || i == winners[1])continue;
    if(KILLS[i] > KILLS[winners[2]])winners[2]=i;
}
if(winners[0] == INVALID_PLAYER_ID)print("no winners");
else if(winners[1] == INVALID_PLAYER_ID)printf("1st = %d",winners[0];
else if(winners[2] == INVALID_PLAYER_ID)printf("1st = %d : 2nd = %d",winners[0],winners[1];
else printf("1st = %d : 2nd = %d : 3rd = %d",winners[0],winners[1],winners[2]);//playerid of winner
try this i dont have heaps of players to try it


Re: Help with sorting - cloud9 - 12.07.2010

It didnt work, it didnt even print any stuff in logs


Re: Help with sorting - Donny_k - 12.07.2010

Use QSort or something like it, you can find it in YSI_misc.own IIRC, check the YSI topic or the usefull functions topic.