Trouble with a looping counter
#1

I have devised a way to count how many players are playing in a level on a server, however the count is always 1 higher than it actually is. Now i know i could just subtract 1 from the count and be done with this but that would not be good practice. I have spent some time modifying the loop, and have even included foreach but nothing will work, here is the code i'm working with.
pawn Код:
for(new i = 0; i < MAX_MODES; i++)
            {
                if(MODES[i][1][0] == 0) format(string, sizeof(string), "%s %s: {FF0000} Inactive\r\n", string, MODES[i][0]);
                else
                {
                    new players = 0;
                    foreach (Player, p)
                    {
                        if(PlayerData[p][MODE] == i) players++;
                        else continue;
                    }
                    format(string, sizeof(string), "%s %s: {00FF00} Active{FFFFFF} - Players: %i\r\n", string, MODES[i][0], players);
                }
            }
Also, there are no errors upon compiling the code
Reply
#2

Maybe this
pawn Код:
for(new i = 0; i < MAX_MODES; i++)
{
    if(MODES[i][1][0] == 0) format(string, sizeof(string), "%s %s: {FF0000} Inactive\r\n", string, MODES[i][0]);
    else
    {
        new players = 0;
        foreach(Player, p)
        {
            if(PlayerData[p][MODE] == i) players++;
        }
        format(string, sizeof(string), "%s %s: {00FF00} Active{FFFFFF} - Players: %i\r\n", string, MODES[i][0], players);
    }
}
Reply
#3

I have just added another column to the array, when a player selects the mode it will bump the count up one, and when they disconnect it subtracts it by one
Though i will try that as it is a better way
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)