Author Topic: Timer Functions.  (Read 1544 times)

VetalYA

  • Guest
Timer Functions.
« on: November 01, 2011, 08: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

Gudio

  • Newbie
  • *
  • Posts: 18
  • Karma: +4/-0
    • View Profile
Re: Timer Functions.
« Reply #1 on: November 01, 2011, 08:21:51 pm »
Code: [Select]
local timer = NewTimer( "Message", 5000, 3, "BOO!" );
timer.Stop();
timer.Start();
timer.Delete();

VetalYA

  • Guest
Re: Timer Functions.
« Reply #2 on: November 01, 2011, 08: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.

VetalYA

  • Guest
Re: Timer Functions.
« Reply #3 on: November 01, 2011, 08:42:26 pm »
O Yeah, it works. Big thank  to both of You..

Vortrex

  • Full Member
  • ***
  • Posts: 267
  • Karma: +54/-73
    • View Profile
Re: Timer Functions.
« Reply #4 on: November 01, 2011, 08: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

VetalYA

  • Guest
Re: Timer Functions.
« Reply #5 on: November 01, 2011, 09: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 !
« Last Edit: November 01, 2011, 10:09:26 pm by VetalYA »

 

© Liberty Unleashed Team.