[Tutorial] [TuT]The function "SetTimer"
#1

[Tutorial] SetTimer
* I decided to rewrite my tutorial, as it was all wrong before! (I was a really new scripter back then.)

What this tutorial will cover
* Explanation for the function SetTimer + example.
* Explanation for the function KillTimer + example

The function SetTimer

The function with parameters looks like this:
Код:
SetTimer(funcname[], interval, repeating)
Let me explain the parameters in bits:

"funcname[]" Name of the function to call as a string("name"), and it needs to be a public(I explain later how to make it public.)

"interval" time in milliseconds, e.g 1 sec will be 1000 milliseconds.

"repeating" Should it keep repeating it self or just occur once? 0 = Will only occur once | 1 = Will repeat it self.

Now that we know what the parameters is/means we need to make the timer.
As i wrote in the parameter "funcname[]" it has to be a public, which means we have to forward it.

All you have to add is "forward funcname();"

e.g
pawn Код:
forward MyTimer();
* Note: I usually make all my forwards at the top of my script, but it can be anywhere as long as it's outside the publics.

Now we need to use the function SetTimer to set the interval and if repeated or not.
This HAS to be under a public like OnGameModeInnit.

Код:
SetTimer(funcname[],interval,repeating);
e.g
pawn Код:
public OnGameModeInnit()
{
   SetTimer("MyTimer",10000,0);
}
The fact it under "OnGameModeInnit" it will start when the gamemode starts.

"MyTimer" - The name called as a string (" ").
10000 - Time in milliseconds (10 seconds).
0 - Non-repeating.


Now we forward and made the timer to occur once, 10 seconds after the gamemode has been started.
Now we need to make the "public" to tell the timer what it should do after those 10 seconds.


You make the public simply with "public TimerName()" - I usually make this a the bottom of my script, but it just have to be outside the other publics.

e.g
pawn Код:
public MyTimer()
But we still need to tell it what to do. It kinda work just like a normal public.

e.g
pawn Код:
public MyTimer()
{
   SendClientMessageToAll(0xFFFF00AA,"10 seconds has passed");
}
This would send the message "10 seconds has passed" after 10 seconds, and only once.
Because we used
Код:
SetTimer("MyTimer",10000,0);
and told it to occur after 10 seconds and once.

this is how it should look like - Click me

another example with a repeating timer would be this

The little change of af "0" to a "1" and "10000" to "60000" will make this timer to send the message "1 min has passed" every single minute.

You can read the wiki page here




The function KillTimer

This is exactly what it sounds like, it kills a running timer.

The function with parameter:
Код:
KillTimer(timerid)
but to be able to kill a timer you need to give it a timerid.

You do that by simply add e.g:
Код:
new timer1;
- "timer1" is just an example can be anything.

and add the name "timer1" to the "SetTimer" function like this:

pawn Код:
public OnGameModeInnit()
{
   timer1 = SetTimer("MyTimer",10000,0);
}
by doing like that you assigned "timer1" as the timerid to that timer.
now you will be able to use:

Код:
KillTimer(timer1);
under a public.

Like the example i used with the timer keep sending the msg "1 min has passed"

you can use it like this

That would kill the timer the first time it occurs.


I hope you learn something about timers.

Regards Naxix

* The reason why "SetTimerEx" isn't included is, that it would be able to confuse new scripters. And when you learned the function SetTimer, SetTimerEx aren't that hard anymore.
Reply
#2

SetTimerEx is what you need in the minigun example.
Reply
#3

SetTimer("tutorial",10000,0);

will only show it once.

this is a pointless topic really, you should learn yourself https://sampwiki.blast.hk/
Reply
#4

Quote:
Originally Posted by Shady91
SetTimer("tutorial",10000,0);

will only show it once.

this is a pointless topic really, you should learn yourself https://sampwiki.blast.hk/
And its just like he said? -.-
+
"So i thought i would share the experience i got, to other new scripters!"
Reply
#5

Quote:
Originally Posted by Assyria
Quote:
Originally Posted by Shady91
SetTimer("tutorial",10000,0);

will only show it once.

this is a pointless topic really, you should learn yourself https://sampwiki.blast.hk/
And its just like he said? -.-
+
"So i thought i would share the experience i got, to other new scripters!"
Why are you taking that so serious? You didn't create this tutorial so you have nothing shared as you say in your post
Reply
#6

this isn't a tutorial this is something that will confuse new scripter's this should be deleted.
Reply
#7

Well, whats your point commenting on me?
And whats the point to come complaining "This is worthless", when you cant see the view from desprate beginner searching goodly explained tutorial for using basic timer?
Reply
#8

I DON'T want to see that view because the tutorial is WRONG! So this isn't explained "goodly" neither is it worth using it as a beginner
Reply
#9

well, which part is wrong?
Reply
#10

Quote:
Originally Posted by Shady91
SetTimer("tutorial",10000,0);

will only show it once.

this is a pointless topic really, you should learn yourself https://sampwiki.blast.hk/
Quote:
Originally Posted by FUNExtreme
SetTimerEx is what you need in the minigun example.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)