top 5 code sometimes crashes my server!!
#1

hi,
like the title says.
this code i dont know why, sometimes crashes my server.
Only if there is only 1 player in the server it never crashes.
This is comparing the kills of a player and then it shows the top 5 players currently playing on the server.

pawn Код:
//kills are counted like this:
kills[killerid]++; //under OnPlayerDeath




new TotalScores[6];
new TotalPlayers[6];
new PlayerScore[2];
new PlayerID[2];
for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        PlayerScore[0] = kills[i]; //kills
        PlayerID[0] = i;
        for(new place; place < sizeof(TotalScores); place++)
        {
            if(PlayerScore[0] > TotalScores[place])
            {
                strins(TotalScores, PlayerScore, place);
                strins(TotalPlayers, PlayerID, place);
                place = sizeof(TotalScores);
            }
        }
    }
}
hope someone can help me cause i just dont know what to do.

regards...
Reply
#2

Something I made in 5 mins:

pawn Код:
new Score[6];
new Player[6];
for(new i; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        for(new p=5; p>0; p--)
        {
            if(kills[i]>Score[p])
            {
                Score[p+1]=Score[p];
                Player[p+1]=Player[p];
                Score[p]=kills[i];
                Player[p]=i;
            }
        }
    }
}
for(new p=0; p<6; p++)
{
    if(Score[p]>0)
    {
        new string[128];
        format(string, 128, "%d) %s with %d score", p, pName(playerid), Score[p]);
        SendClientMessage(playerid, WHITE, string);
    }
}
Not sure if it works, but you could give it a shot.

Jeffry
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)