#define for2(%0,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))
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;
}
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;
}
}
new counter = 0;
//under OnPlayerConnect
counter++;
//under OnPlayerDisconnect
counter--;
#define for2(%0,%1) for(new %1=0;%1<MAX_PLAYERS;%1++) if(IsPlayerConnected(%1))
#define for2(%0,%1) for(new %1=0;%1<%0;%1++) if(IsPlayerConnected(%1))
I think this is not good:
pawn Код:
pawn Код:
|
Why the hell do you need such a complicated code for this... it can be done with just 3 lines.
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");
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);
Why the hell do you need such a complicated code for this... it can be done with just 3 lines.
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);