How to check if anyone is 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: How to check if anyone is online? (
/showthread.php?tid=371441)
How to check if anyone is online? -
ValentinLaw - 23.08.2012
This is the code:
PHP код:
public OnPlayerSpawn(playerid)
{
if(IsPlayerConnected(0)) // <-- This
{
SetTimer("startgm",100,false);
}
else
{
return 0;
}
}
Instead of "ID0", it will check if any play is online, it doesn't matter who. Just if any player is connected it will work. Can anyone help me with it?
Re: How to check if anyone is online? -
Roko_foko - 23.08.2012
Use this function
pawn Код:
//on top of the script
bool:IsAnyPlayerOnline()
{
for(new i=0;i<MAX_PLAYERS;i++)if(IsPlayerConnected(i))return true;
return false;
}
//_________________________________________
//example how to use it
public OnPlayerSpawn(playerid)
{
if(IsAnyPlayerOnline())
{
SetTimer("startgm",100,false);
}
else
{
return 0;
}
}
Re: How to check if anyone is online? -
scottyishere - 23.08.2012
pawn Код:
stock IsAnyPlayerOnline()
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i)) return 1;
}
return 0;
}
IsAnyPlayerOnline will return 1 if there is a player connected and 0 if none is connected.
EDIT: User above was quicker.
Re: How to check if anyone is online? -
FalconX - 23.08.2012
if you want to check if someone is in the server or not you can just use a loop to check if anyone is online:
pawn Код:
new iCountPlayers = 0;
for( new f = 0; f < MAX_PLAYERS; f++ )
{
if( IsPlayerConnected( f ) )
{
iCountPlayers++;
}
}
if( iCountPlayers > 0 )
{
// your code
}
or alternatively
pawn Код:
stock IsAnyPlayerOnline( )
{
new iCountPlayers = 0;
for( new f = 0; f < MAX_PLAYERS; f++ )
{
if( IsPlayerConnected( f ) )
{
iCountPlayers++;
}
}
if( iCountPlayers > 0 )
{
return 1;
}
else
{
return 0;
}
}