Showing players online?
#1

How can I show how many players are online

Since im doing a simple cmd(i.e. /playersonline)

How can I make it display current players online?
Reply
#2

PHP код:
#include <a_samp>
#define ORANGE      0xF97804FF
new Players;
public 
OnPlayerConnect(playerid)
{
Players++;
new 
string[128];
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNamesizeof(pName));
    
format(stringsizeof(string), "*** %s has joined the server. Total Players: %d"pNamePlayers);
    
SendClientMessageToAll(ORANGEstring);
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
Players--;
new 
string[128];
    new 
pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNamesizeof(pName));
    
format(stringsizeof(string), "*** %s has left the server. Total Players: %d"pNamePlayers);
    
SendClientMessageToAll(ORANGEstring);
   return 
1;

Reply
#3

pawn Код:
MainTxtdraw[5] = TextDrawCreate(319.000000, 391.000000, "Players Online:"players");
    TextDrawAlignment(MainTxtdraw[5], 2);
    TextDrawBackgroundColor(MainTxtdraw[5], 255);
    TextDrawFont(MainTxtdraw[5], 2);
    TextDrawLetterSize(MainTxtdraw[5], 0.450000, 2.00000);
    TextDrawColor(MainTxtdraw[5], 0xEDA200FF);
    TextDrawSetOutline(MainTxtdraw[5], 0);
    TextDrawSetProportional(MainTxtdraw[5], 1);
    TextDrawSetShadow(MainTxtdraw[5], 1);
How would I display it in a textdraw?
Reply
#4

PHP код:
#include <a_samp>
new Text:players;
public 
OnGameModeInit()
{
players TextDrawCreate(319.000000391.000000"_");
    
TextDrawAlignment(players2);
        
TextDrawBackgroundColor(players255);
    
TextDrawFont(players2);
    
TextDrawLetterSize(players0.4500002.00000);
    
TextDrawColor(players0xEDA200FF);
    
TextDrawSetOutline(players1);
    
TextDrawSetProportional(players0);
    
    for(new 
iMAX_PLAYERS++)
    {
        if(
IsPlayerConnected(i))
        {
            
TextDrawShowForPlayer(iplayers);
        }
    }
    return 
1;
}
public 
OnGameModeExit()
{
        
TextDrawHideForAll(players);
    
TextDrawDestroy(players);
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
     new 
string[15];
    
format(string15"%d/100",GetPlayersOnline());
    
TextDrawSetString(playersstring);
    
TextDrawShowForPlayer(playeridplayers);
    return 
1;
}
stock GetPlayersOnline()
{
    new 
Players;
    for(new 
iGetMaxPlayers(); gi++)
        if(
IsPlayerConnected(i))
            
Players++;
    return 
Players;

Reply
#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


Forum Jump:


Users browsing this thread: 1 Guest(s)