06.02.2015, 14:52
Hello all i searched everywhere around the forums and could not find any Tutorial about Timers and their usage in Pawno .. Any links maybe?
// 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;
}