Liberty Unleashed

Scripting => Script Help => Topic started by: VetalYA on November 01, 2011, 07:11:49 pm

Title: Timer Functions.
Post by: VetalYA on November 01, 2011, 07:11:49 pm
Ok. I need simple info, how to manage with  timers.

and Wiki contain red link for

Timer.Delete
Timer.Start
Timer.Stop


http://liberty-unleashed.co.uk/LUWiki/Squirrel/Functions/Timers/NewTimer (http://liberty-unleashed.co.uk/LUWiki/Squirrel/Functions/Timers/NewTimer)
Title: Re: Timer Functions.
Post by: Gudio on November 01, 2011, 07:21:51 pm
Code: [Select]
local timer = NewTimer( "Message", 5000, 3, "BOO!" );
timer.Stop();
timer.Start();
timer.Delete();
Title: Re: Timer Functions.
Post by: VetalYA on November 01, 2011, 07:25:17 pm
Code: [Select]
local timer = NewTimer( "Message", 5000, 3, "BOO!" );
timer.Stop();
timer.Start();
timer.Delete();

Thank you Gudio, i will try this now.
Title: Re: Timer Functions.
Post by: VetalYA on November 01, 2011, 07:42:26 pm
O Yeah, it works. Big thank  to both of You..
Title: Re: Timer Functions.
Post by: Vortrex on November 01, 2011, 07:55:00 pm
Timers (from my experience), can lag a server if too many are used. I have a more efficient solution below that is a bit complicated, but I'll try to explain it as best as I can:

My script uses one timer for everything, and utilizes a "tick" based system, that ticks up every time the timer is executed. Whenever the tick reaches a certain point that matches the point of a function that needs to be executed, it executes the function, and moves up the point a certain bit to be executed again at a certain tick.

For example,
I use a timer that executes every 100ms, and every 100ms, it ticks up a global variable up one notch. Every time it reaches 5 minutes more, it executes a function, then the function moves its execution point up another five minutes (300000 ms), so when the timer reaches the next five minute mark, it executes that function again.

Also, if you are (for example), using an in game command that has a check to see if the player waited long enough to use it again, use a timestamp. That way, you can check if enough time has passed by comparing the current timestamp to the old one. This prevents the use of another timer. A couple of functions, which I think are provided in the Squirrel standard library (which is already implemented), are time(), which shows the amount of seconds passed since midnight, January 1, 1970 (I think that's right) ... You can also use clock() to see how much time has passed since the start of the server.

- WtF
Title: Re: Timer Functions.
Post by: VetalYA on November 01, 2011, 08:13:16 pm
Yes, i know it from SA:MP, that Timers:
can lag a server if too many are used.

Big Thank for your  reply.  ;) I found it  useful !