Timers
#1

Hello all i searched everywhere around the forums and could not find any Tutorial about Timers and their usage in Pawno .. Any links maybe?
Reply
#2

and the wiki?

https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
https://sampwiki.blast.hk/wiki/KillTimer
Reply
#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
#4

@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...
Reply
#5

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)