PDA

View Full Version : Check only for real clients


Ellie
11-14-2014, 12:33
I'm trying to do a small plugin that will run a server command on map start. However, I'd like it to only run if there is at least 1 human player connected and in game. I don't want it to run if there are no players connected at all.

I had this below, which seem to work some of the time, but I see in console it that is also sometimes runs it even before human players join.

public OnMapStart()
{
ServerCommand("wait 1000; exec waitforit.cfg");
}Then I tried this but it doesn't quite work.


public OnMapStart()
{
for( new i=1; i <= MaxClients; i++ )
{
if(IsClientConnected(i) && IsClientInGame(i) && !IsFakeClient( i ) )
{
ServerCommand("wait 1000; exec waitforit.cfg");
}
}
}Any suggestion on a better way to do this?

Bacardi
11-14-2014, 17:34
smthing like this


new Handle:my_timer; // Store timer

public OnMapStart()
{
// there is my timer currently running ?? stop it
if(my_timer != INVALID_HANDLE)
{
KillTimer(my_timer);
my_timer = INVALID_HANDLE;
}

// my timer
my_timer = CreateTimer(20.0, timer_delay);
}

public Action:timer_delay(Handle:timer)
{
my_timer = INVALID_HANDLE; // Timer works, clear handle for this.

for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
// Do server command here
//


break; // stop loop if one real player found
}
}

return Plugin_Continue;
}