Timers - 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: Timers (
/showthread.php?tid=562016)
Timers -
Alvin007 - 06.02.2015
Hello all i searched everywhere around the forums and could not find any Tutorial about Timers and their usage in Pawno .. Any links maybe?
Respuesta: Timers -
Zume - 06.02.2015
and the wiki?
https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
https://sampwiki.blast.hk/wiki/KillTimer
Re: Timers -
HazardouS - 06.02.2015
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
Re: Timers -
Schneider - 06.02.2015
@HazardouS: If you're going to write a 'tutorial', do it right and don't make errors. You have no idea what you are doing...
Re: Timers -
HazardouS - 06.02.2015
Thanks for pointing that out, I actually didn't realize the errors. By the way, that's not really a tutorial, but a small code that explains mostly the syntax and stuff like that.