#include<a_samp>
new onlineplayers=0;
onlineplayers++;
new str[128];
format(str,sizeof(str),"SERVER STATUS: %i players are currently online.",onlineplayers);
SendClientMessageToAll(0xED5F07FF,str);
onlineplayers++;
new str[128];
format(str,sizeof(str),"SERVER STATUS: %i players are currently online.",onlineplayers);
"SERVER STATUS: %i players are currently online.,onlineplayers)"
SendClientMessageToAll(0xED5F07FF,str);
'new' is the variable |
new onlineplayers=0;
new onlineplayers;
public OnPlayerDisconnect(playerid, reason)
{
onlineplayers--;
new str[128];
format(str,sizeof(str),"SERVER STATUS: %i players are currently online.",onlineplayers);
SendClientMessageToAll(0xED5F07FF,str);
return 1;
}
#include <a_samp>
#if defined MAX_PLAYERS // Check if MAX_PLAYERS it's defined
#undef MAX_PLAYERS // If yes , we will undefine it
#endif // if we have an #if , we need #endif ..
#define MAX_PLAYERS 50 // Define server slots | Modify there .
public OnPlayerConnect(playerid) // Public OnPlayerConnect
{ // Open bracket
new count, String[46]; // We create an initialiser (count) and a string with the cellsize 46 (String)
for(new i; i<MAX_PLAYERS; i++) if(IsPlayerConnected(i)) count++; // Make a loop across all server ids (slots ...) , check if any it's connected . If a player it's connected we will give count += 1 (Or count++)
// count = players connected .
format(String, sizeof(String), "SERVER INFO:There are %i players online.", count); // Format our string with the text from " "
SendClientMessage(playerid, -1, String); // Print the message to player who connected in white color .
} // Close the bracket ~~~~ Much simplest , i think
- You don't need to use OnPlayerConnect() or OnPlayerDisconnect() to increment or decrement any specific variable, you could simply check current players with a simple for() loop.
|