Score update problem
#1

Hi, im having a problem with this very simple feature that should check for the highest score on the server.
The problem is that who ever on the server has a higher score than 0 it states him also as the player
with the highest score. (now imagine the spam with like 50 people on the server)

Can anyone please take a look at the code and tell me what could be wrong?

pawn Код:
public ScoreUpdate()
{
    new string[128];
    new highest = -1;
    new name[MAX_PLAYER_NAME];
    for(new slots = GetMaxPlayers(), i; i < slots; i++)
    {
        if(!IsPlayerConnected(i))
            continue;
        if(GetPlayerScore(i) > highest)
        {
            highest = GetPlayerScore(i);
            GetPlayerName(i, name, sizeof(name));
            format(string, sizeof(string), "Player %s is currently the top killer with a score of %d kills!", name, highest);
            SendClientMessageToAll(COLOR_ORANGE, string);
        }
    }
    return 1;
}
Thanks, regards.
Reply
#2

You're calling the SendClientMessageToAll function inside the loop. A for loop starts by a designated number and reaches up to its destination. Imagine in your server, your players had the score of their playerid (Ex: I'm playerid 9, my score is 9), it will just keep spamming every name that is bigger.

pawn Код:
public ScoreUpdate()
{
    new string[128];
    new highest = -1;
    new highestPlayer;
    new name[MAX_PLAYER_NAME];
    for(new slots = GetMaxPlayers(), i; i < slots; i++)
    {
        if(!IsPlayerConnected(i))
            continue;
        if(GetPlayerScore(i) > highest)
        {
            highest = GetPlayerScore(i);
            highestPlayer = i;
        }
    }
    GetPlayerName(highestPlayer, name, sizeof(name));
    format(string, sizeof(string), "Player %s is currently the top killer with a score of %d kills!", name, highest);
    SendClientMessageToAll(COLOR_ORANGE, string);
    return 1;
}
Reply
#3

Thanks alot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)