28.10.2012, 06:40
pawn Код:
#include <zcmd> //Zcmd include is required.
new oPlayers; //Creating a variable to execute it on connect/disconnect to get the no: of players.
public OnPlayerConnect(playerid)
{
oPlayers++; //When a player connects, the variable increases +1. ('++' = +1)
//Your other stuffs.
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
oPlayers--; //The variable gets decreased -1. ('--' = -1)
//Your stuffs here.
return 1;
}
CMD:oplayers(playerid,params[])
{
new str[128];
format(str, sizeof(str), "There are currently %d players online.", oPlayers);
SendClientMessage(playerid, 0xFF0000, str);
return 1;
}
CMD:onlineplayersname(playerid,params[]) //A cmd to get online player's name. Won't show all if many players are connected.
{
new str[128];
new Lname[MAX_PLAYER_NAME]; //Creating a name variable to get players's name.
for(new i; i< MAX_PLAYERS; i++) //Looping through max players.
{
if(IsPlayerConnected(i))
{
GetPlayerName(i,Lname,sizeof(Lname));
format(str,sizeof(str),"%s is online\r\n", Lname);
SendClientMessage(playerid, 0xFF0000, str);
}
}
return 1;
}