SA-MP Forums Archive
Counting Players Problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Counting Players Problem (/showthread.php?tid=299979)



Counting Players Problem - GAMER_PS2 - 28.11.2011

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


Re: Counting Players Problem - System64 - 28.11.2011

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?


Re: Counting Players Problem - [MWR]Blood - 28.11.2011

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--;



Re: Counting Players Problem - Michael@Belgium - 28.11.2011

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))



Re: Counting Players Problem - System64 - 28.11.2011

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!


Re: Counting Players Problem - Michael@Belgium - 28.11.2011

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--;



Re: Counting Players Problem - GAMER_PS2 - 28.11.2011

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"


Re: Counting Players Problem - [L3th4l] - 28.11.2011

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


Re: Counting Players Problem - System64 - 28.11.2011

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);



Re: Counting Players Problem - Sinc - 28.11.2011

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);