Showing players online? - 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: Showing players online? (
/showthread.php?tid=388268)
Showing players online? -
RLGaming - 28.10.2012
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?
Respuesta: Showing players online? -
ThePhenix - 28.10.2012
PHP код:
#include <a_samp>
#define ORANGE 0xF97804FF
new Players;
public OnPlayerConnect(playerid)
{
Players++;
new string[128];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "*** %s has joined the server. Total Players: %d", pName, Players);
SendClientMessageToAll(ORANGE, string);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
Players--;
new string[128];
new pName[MAX_PLAYER_NAME];
GetPlayerName(playerid, pName, sizeof(pName));
format(string, sizeof(string), "*** %s has left the server. Total Players: %d", pName, Players);
SendClientMessageToAll(ORANGE, string);
return 1;
}
Re: Showing players online? -
RLGaming - 28.10.2012
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?
Respuesta: Showing players online? -
ThePhenix - 28.10.2012
PHP код:
#include <a_samp>
new Text:players;
public OnGameModeInit()
{
players = TextDrawCreate(319.000000, 391.000000, "_");
TextDrawAlignment(players, 2);
TextDrawBackgroundColor(players, 255);
TextDrawFont(players, 2);
TextDrawLetterSize(players, 0.450000, 2.00000);
TextDrawColor(players, 0xEDA200FF);
TextDrawSetOutline(players, 1);
TextDrawSetProportional(players, 0);
for(new i; i < MAX_PLAYERS; i ++)
{
if(IsPlayerConnected(i))
{
TextDrawShowForPlayer(i, players);
}
}
return 1;
}
public OnGameModeExit()
{
TextDrawHideForAll(players);
TextDrawDestroy(players);
return 1;
}
public OnPlayerConnect(playerid)
{
new string[15];
format(string, 15, "%d/100",GetPlayersOnline());
TextDrawSetString(players, string);
TextDrawShowForPlayer(playerid, players);
return 1;
}
stock GetPlayersOnline()
{
new Players;
for(new i, g = GetMaxPlayers(); i < g; i++)
if(IsPlayerConnected(i))
Players++;
return Players;
}
Re: Showing players online? -
Lordzy - 28.10.2012
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;
}