Timers
#3

I'll write a short tutorial for you.
pawn Код:
// SetTimer - useful for functions without parameters
// SetTimerEx - useful for functions with parameters

//global variables
new OneSecondTimer;
new ParamFunctionTimer;

public OnGameModeInit()
{
    OneSecondTimer =  SetTimer("OneSecTick", 1000, true); // 1000 miliseconds equals 1 second, true means it will repeat every second. Set that to false to call "OneSecTick" only once, 1 second after timer creation
   
}

public OnPlayerConnect(playerid)
{
    // [..]
    ParamFunctionTimer = SetTimerEx("TwoMinutesCheck", 120000, false, "d", playerid);
    // [..]
}

forward OneSecTick();
public OneSecTick()
{
    //one second passed, do something here. Let's kill the timer:
    KillTimer(OneSecondTimer); //even if the repeat was set to true, now we stopped it so it doesn't matter
}

forward TwoMinutesCheck(playerid);
public TwoMinutesCheck(playerid)
{
    SendClientMessage(playerid, -1, "Two minutes passed since you connected.");
    //timer repeat was set to false, so it killed itself when it called the function
    return 1;
}
EDIT: global variables
Reply


Messages In This Thread
Timers - by Alvin007 - 06.02.2015, 14:52
Respuesta: Timers - by Zume - 06.02.2015, 14:57
Re: Timers - by HazardouS - 06.02.2015, 15:00
Re: Timers - by Schneider - 06.02.2015, 16:30
Re: Timers - by HazardouS - 06.02.2015, 16:39

Forum Jump:


Users browsing this thread: 1 Guest(s)