[FilterScript] Top 5 Player Score's List
#7

Scripted very inefficient. Take a look at the example with quickSort or with bubblesort in just one command (slower than quickSort).
Written over a month ago without real testing:
pawn Код:
if(!strcmp(cmdtext, "/top5", true))
{
    new
        players_Data[MAX_PLAYERS][2],
        tempString[128],
        tempVar,
        i,
        j,
        k
    ;
    for(i = 0, j = GetMaxPlayers(); i < j; ++i)
    {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i))
        {
            players_Data[tempVar][0] = GetPlayerScore(i);
            players_Data[tempVar++][1] = i;
        }
    }
    for(i = 0, j = 0; i < tempVar; ++i)
    {
        j = players_Data[i][0];
               
        for(k = i - 1; k > -1; --k)
        {
            if(j > players_Data[k][0])
            {
                players_Data[k][0] ^= players_Data[k + 1][0], players_Data[k + 1][0] ^= players_Data[k][0], players_Data[k][0] ^= players_Data[k + 1][0];
                players_Data[k][1] ^= players_Data[k + 1][1], players_Data[k + 1][1] ^= players_Data[k][1], players_Data[k][1] ^= players_Data[k + 1][1];
            }
        }
    }
   
    SendClientMessage(playerid, 0xFF0000FF, "» Top 5 players:");
           
    for(i = 0; i < 5; ++i)
    {
        if(tempVar < i)
            break;
               
        GetPlayerName(players_Data[i][1], tempString, 20);
           
        format(tempString, sizeof(tempString), "» %d. Player: %s [%d] - Score: %d", i, tempString, players_Data[i][1], players_Data[i][0]);
        SendClientMessage(playerid, 0xFFFFFFFF, tempString);
    }
    return 1;
}
NOTE: Tell me if you want me to delete this piece of code, I'm just trying to help.

Thanks for the effort though.
Reply


Messages In This Thread
- Remove Please - - by Kwarde - 23.04.2011, 20:26
Re: Top 5 Player Score's List - by IvanCroatiaCopy - 23.04.2011, 20:30
Respuesta: Top 5 Player Score's List - by Host-samp - 23.04.2011, 20:39
Re: Top 5 Player Score's List - by Leroytjuh - 23.04.2011, 21:17
Re: Top 5 Player Score's List - by Red_Devils - 23.04.2011, 21:22
Re: Top 5 Player Score's List - by Kwarde - 23.04.2011, 21:24
Re: Top 5 Player Score's List - by RyDeR` - 23.04.2011, 22:02
Re: Top 5 Player Score's List - by Kwarde - 23.04.2011, 22:11
Re: Top 5 Player Score's List - by Unknown1234 - 23.04.2011, 22:33
Re: Top 5 Player Score's List - by Kwarde - 23.04.2011, 22:40

Forum Jump:


Users browsing this thread: 1 Guest(s)