Counting Players Problem
#1

Hey now synic reply on my problem in counting players in the server (not include yourself)

now i have problem i want not to include myself in counting but it keeps including me in counting

heres the code:

pawn Код:
#define for2(%0,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))
pawn Код:
new
        str[156],
        counter
    ;
    for2(MAX_PLAYERS,i)
    counter++;
    format(str, sizeof(str), "There is current %d players online in the server", counter);
    SendClientMessage(playerid,COLOR_WHITE, str);
    if(counter != playerid)
    {
        counter--;
        return 1;
    }
    if(counter == 0)
    {
        SendClientMessage(playerid,COLOR_RED,"There is current no players online in the server");
        return 1;
    }
Please help me
Reply
#2

remove that macro!
pawn Код:
new
        str[156],
        counter
    ;
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(!IsPlayerConnected(i)) return 0;
        if(i == playerid) return 0;
        counter++;
        format(str, sizeof(str), "There is current %d players online in the server", counter);
        SendClientMessage(playerid,COLOR_WHITE, str);
        if(counter != playerid)
        {
            counter--;
            return 1;
        }
        if(counter == 0)
        {
            SendClientMessage(playerid,COLOR_RED,"There is current no players online in the server");
            return 1;
        }
    }
or maybe just add in the format counter - 1?
Reply
#3

Why the hell do you need such a complicated code for this... it can be done with just 3 lines.
pawn Код:
new counter = 0;

//under OnPlayerConnect
counter++;

//under OnPlayerDisconnect
counter--;
Reply
#4

I think this is not good:

pawn Код:
#define for2(%0,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))
It must be:

pawn Код:
#define for2(%0,%1) for(new %1=0;%1<%0;%1++) if(IsPlayerConnected(%1))
Reply
#5

Quote:
Originally Posted by Michael@Belgium
Посмотреть сообщение
I think this is not good:

pawn Код:
#define for2(%0,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))
It must be:

pawn Код:
#define for2(%0,%1) for(new %1=0;%1<%0;%1++) if(IsPlayerConnected(%1))
yeah but that's not ptoblem!
Reply
#6

Quote:
Originally Posted by System64
Посмотреть сообщение
yeah but that's not ptoblem!
This is the solution:

Quote:
Originally Posted by [MWR]Blood
Посмотреть сообщение
Why the hell do you need such a complicated code for this... it can be done with just 3 lines.
pawn Код:
new counter = 0;

//under OnPlayerConnect
counter++;

//under OnPlayerDisconnect
counter--;
Reply
#7

Guys i just need to know how to not include my self incounting and if theres no players
it should be "Theres no currently players online in this server"
Reply
#8

pawn Код:
new
    iString[50],
    iCount;

for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        if(i == playerid) continue;

        iCount ++;
    }
}

if(iCount > 0) format(iString, sizeof(iString), "There are %d players connected", iCount), SendClientMessage(playerid, COLOR_WHITE, iString);
else SendClientMessage(playerid, COLOR_RED, "There are no players connected");
Something like that should work
Reply
#9

pawn Код:
new TotalPlayers = 0;

public OnPlayerConnect(playerid)
{
    TotalPlayers ++;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    TotalPlayer --;
    return 1;
}

//somewhere in cmd or...
format(string, sizeof(string), "Total players connected: %d", TotalPlayers);
if(TotalPlayers > 0) return SendClientMessage(playerid, -1, "There are no players online!");
else SendClientMessage(playerid, -1, string);
Reply
#10

Quote:
Originally Posted by [MWR]Blood
Посмотреть сообщение
Why the hell do you need such a complicated code for this... it can be done with just 3 lines.
pawn Код:
new counter = 0;

//under OnPlayerConnect
counter++;

//under OnPlayerDisconnect
counter--;
The code isn't complicated.

pawn Код:
#define for2(MAX_PLAYERS,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))

new
    str[156],
    counter
;
    for2(MAX_PLAYERS,i) counter++;
    if(counter <= 2) return SendClientMessage(playerid, -1, "There are currently no players in the server!");
    format(str, sizeof(str), "There is current %d players online in the server", counter-1);
    SendClientMessage(playerid,-1, str);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)