Can someone explain Timers in an easy way.
#1

The title says all, i'm still not entirely sure of the usage of them, can someone show and explain please?
preferably something linked to hospitals as its easier to understand.
Reply
#2

well the timers can be used by lot ways..we can use them for a textdraw or to use a fuction to load objects(for a dm or stunts server) or you can use for map change or to restart a server at a specific time..etc
Timer actuallly are a way to do something which will start/end something in the specific time you want to script
pawn Код:
SetTimer("fuction",miliseconds,1 or0);
SetTimer-the fuction
"fuction"-write the fuction which wou will use the timer
miliseconds - write the specific time you want the time to do the thing you want
1 - to do it repeatively
0 - do it only once
I Hope i helped
Reply
#3

Could you show me an example, even a simple one? That's actually made a difference but I want to make sure!
Reply
#4

Timers are used to call a custom callback after the inputted amount of milliseconds.

For example:

pawn Код:
main()
{
    print("Incoming message in 5 seconds!");
    SetTimer("OurFunction", 5000, false);
}

forward OurFunction();
public OurFunction()
{
    print("I told you!");
    return 1;
}
After "OurFunction", you might notice the 5000. Those are milliseconds.

One second is equivalent to 1000 milliseconds.
Twenty-two seconds is equivalent to 22000 milliseconds.

Basically, it's seconds x 1000.

Function: SetTimer(funcname[], ms, bool:repeat);
funcname[] - Name of the function (must be a public defined in the script)
ms - Milliseconds funcname will be called in (example: 2000 for 2 seconds)
bool:repeat - Can be boolean (false/true) or integer (0/1). If set to true or 1, the timer will repeat every time for the amount of ms entered.
However, if you wish to create a timer that will repeat 5 times then stop, try this:

pawn Код:
new spamtimer;
new times;

main()
{
    print("Incoming spam!");
    spamtimer = SetTimer("Spam", 1000, true);
}

forward Spam();
public Spam()
{
    times++;
    if(times >= 5) return KillTimer(spamtimer);
    return print("SPAM");
}
There is a function too, called SetTimerEx, that will call a function & it's parameters after the amount of ms entered (similar to SetTimer).

More can be read here:

SetTimer
SetTimerEx
Reply
#5

Thanks very much, that helped so much!

+ rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)