Help with sorting
#1

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
Reply
#2

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
Reply
#3

It didnt work, it didnt even print any stuff in logs
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)