check player online
#1

Hi can you please help me how to make check player online every 15 minutes? its not a command but automatically sendclientmessagetoall sample: Online Player: 32

Thanks looking forward.
Reply
#2

To get online players you can use this:

pawn Код:
GetOnlinePlayers()
{
    new count;

    for ( new i; i < MAX_PLAYERS; ++ i)
        if (IsPlayerConnected(i)
            ++ count;

    return count;
}
You can use a SetTimer in OnGameModeInit to do the 15 minutes interval.
Reply
#3

pawn Код:
public OnGameModeInit()
{
    SetTimer("OnlineCheck",60000 * 15,1);
    return 1;
}

forward OnlineCheck();
public OnlineCheck()
{
    new count,string[124];
    for(new i = 0; i < MAX_PLAYERS; i++) { if(IsPlayerConnected(i)) { count ++; } }
    format(string,sizeof(string),"Online players: %d",count);
    SendClientMessageToAll(-1,string);
    return 1;
}
Reply
#4

Try this.

pawn Код:
public OnGameModeInit()
{
    SetTimer("OnlinePlayers",900000, true);
        return 1;
}

forward OnlinePlayers();
public OnlinePlayers()
{
    new string[50],totalplayers;
   
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(IsPlayerConnected(i)) totalplayers++;
   
    }
    format(string,sizeof(string),"Online Player: %i.",totalplayers);
    SendClientMessageToAll(-1,string);
    return 1;
}
Reply
#5

thanks guys for answering +rep to all. But I want to ask if its okay to put it in filterscript? and also I want to know if its okay to kill the timer on ongamemodeinit or onfiliterscriptinit?
Reply
#6

Quote:
Originally Posted by kbalor
Посмотреть сообщение
thanks guys for answering +rep to all. But I want to ask if its okay to put it in filterscript? and also I want to know if its okay to kill the timer on ongamemodeinit or onfiliterscriptinit?
It's okay to put it in a filterscript + you can kill the timer under OnGameMode/FilterScriptExit().

EDIT: You -repped me. Oh well.
Reply
#7

You can use OnPlayerDisconnect and OnPlayerConnect to update your variable, and then use the timer just to show the sendclientmessage.

Код:
new on‌linePlayers = 0;

public OnPlayerConnect(playerid) { onlinePlayers++; }
public OnPlayerDisconnect(playerid, reason) { onlinePlayers--; }
public Timer() { new str [ 30 ]; format(str, sizeof str, "Online players: %d", onlinePlayers); SendClientMessageToAll(-1, onlinePlayers); }
Much better than count players every 15 mins
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)