how to make a top 5
#2

I just recently made this, so I know you didn't do a search for it

pawn Код:
stock GetTopScores(Players[6],Scores[6]) //This is how many numbers you want + 1 (Ex, you want 5 players, place 6)
{
    new tmpscore[2];
    new tmpplayer[2];
    for(new player;player<MAX_PLAYERS;player++)
    {
        if(!IsPlayerConnected(player))continue;
        tmpscore[0]=GetPlayerScore(player);
        tmpplayer[0]=player+1;
        for(new spot;spot<sizeof(Players)-1;spot++)
        {
            if(Scores[spot]<tmpscore[0])
            {
                if(Scores[sizeof(Scores)-2])
                {
                    Scores[sizeof(Scores)-2]=0;
                    Players[sizeof(Players)-2]=0;
                }
                strins(Scores,tmpscore,spot);
                strins(Players,tmpplayer,spot);
                spot=sizeof(Players);
            }
        }
    }
    for(new set;set<sizeof(Players);set++)Players[set]--;
}
If you want to use this, you need to create 2 variables to fill it, example
pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
    if(!strcmp("/bestscores",cmdtext,true))
    {
        new players[6]; //same size as in the function header
        new scores[6];
        new string[32];
        GetTopScores(players,scores);
        for(new player;player<5;player++)//same size as in the function header - 1
        {
            if(players[player]==INVALID_PLAYER_ID)continue;
            GetPlayerName(players[player],string,24);
            format(string,32,"%s  --  %d",string,scores[6]);
            SendClientMessage(playerid,0xFFFF00FF,string);
        }
        return 1;
    }
}
Reply


Messages In This Thread
how to make a top 5 - by Whoop - 07.01.2011, 19:18
Re: how to make a top 5 - by Joe Staff - 07.01.2011, 19:26
Re: how to make a top 5 - by Whoop - 07.01.2011, 21:15

Forum Jump:


Users browsing this thread: 2 Guest(s)