Killing a timer on repeat.
#10

I found a better way that actually works using a PlayerCount variable. (duh)
pawn Code:
new Timer,PlayerCount;
public OnGameModeInit()
{
    PlayerCount = 0; // Whenever the server is executed, player count will be zero
    return 1;
}
public OnPlayerConnect(playerid)
{
    Timer = SetTimer("YourFunction",5000,true); // Repeats a timer of 5 seconds
    PlayerCount++; // Whenever a player connects player count will inscrease by 1.
    return 1;
}
public OnPlayerDisconnect(playerid)
{
    PlayerCount--; // When a player disconnects player count will decrease by 1.
    return 1;
}
forward YourFunction();
public YourFunction() // Every 5 seconds....
{
    // Object Code here
    if(PlayerCount == 0) // If no players are on then....
    {
        KillTimer(Timer); // kill the timer.
    }
    return 1;
}
Reply


Messages In This Thread
Killing a timer on repeat. - by Robert_Crawford - 01.03.2012, 17:06
Re: Killing a timer on repeat. - by [XST]O_x - 01.03.2012, 17:19
Re: Killing a timer on repeat. - by Robert_Crawford - 01.03.2012, 17:28
Re: Killing a timer on repeat. - by aco_SRBIJA - 01.03.2012, 17:32
Re: Killing a timer on repeat. - by Robert_Crawford - 02.03.2012, 01:21
Re: Killing a timer on repeat. - by Walsh - 02.03.2012, 01:28
Re: Killing a timer on repeat. - by Robert_Crawford - 02.03.2012, 02:15
Re: Killing a timer on repeat. - by Walsh - 02.03.2012, 02:43
Re: Killing a timer on repeat. - by Robert_Crawford - 02.03.2012, 03:55
Re: Killing a timer on repeat. - by Walsh - 02.03.2012, 04:05

Forum Jump:


Users browsing this thread: 1 Guest(s)