[Question] Connections
#1

Hey everyone.

I just have a simple question, do anyone know how i can create a command so if i type /count the server counts how many players there are online.

I know how to make a command but not to know how many players there are online
Reply
#2

Code:
if(!strcmp(cmdtext,"/count",true))
{
	new count,string[128];

	for(new i=0;i<GetMaxPlayers();i++)
	{
		if(IsPlayerConnected(i)) count ++;
	}
	
	format(string,128,"%d players are currently online.",count);
	SendClientMessage(playerid,0xffff00aa,string);
	
	return 1;
}
The easy way would be to press "Tab" and see the number of players online.
Reply
#3

pawn Code:
//This can be used in any command or any function.
    new PlayerCount;
    for(new i; i <= MAX_PLAYERS; i++) {
        if(IsPlayerConnected(i) && !IsPlayerNPC(i)) {
            PlayerCount++;
        }
    }
/*
Then use PlayerCount in a formatted string.
You can also do this for the amount of admins online by using:
if(IsPlayerConnected(i) && !IsPlayerNPC(i) && IsPlayerAdmin(playerid)) {
*/
EDIT: Beat me to it. ^^
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)