check player 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: check player online (
/showthread.php?tid=468093)
check player online -
kbalor - 06.10.2013
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.
Re: check player online -
Juniiro3 - 06.10.2013
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.
Re: check player online -
xXShadowXx - 06.10.2013
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;
}
Re: check player online -
EiresJason - 06.10.2013
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;
}
Re: check player online -
kbalor - 06.10.2013
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?
Re: check player online -
xXShadowXx - 06.10.2013
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.
Re: check player online -
ReVo_ - 06.10.2013
You can use OnPlayerDisconnect and OnPlayerConnect to update your variable, and then use the timer just to show the sendclientmessage.
Код:
new onlinePlayers = 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