Showing players online?
#5

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


Messages In This Thread
Showing players online? - by RLGaming - 28.10.2012, 05:59
Respuesta: Showing players online? - by ThePhenix - 28.10.2012, 06:12
Re: Showing players online? - by RLGaming - 28.10.2012, 06:16
Respuesta: Showing players online? - by ThePhenix - 28.10.2012, 06:25
Re: Showing players online? - by Lordzy - 28.10.2012, 06:40

Forum Jump:


Users browsing this thread: 1 Guest(s)