[FilterScript] Fast One-Second-Timer
#1

Fast One-Second-Timer
Credits: See pastebin link

What does it do?

Basically, I made a tiny script for one-second-timers.
It is very useful for eg. countdowns and similar stuff, because it's faster than just looping a timer each "millisecond".

How can you prove that this is actually faster?

Easy.

By using this line - SetTimer("OneSecTimer", 1000, true);
I got this output for 10 seconds:

Код:
[12:29:47] 1 - Ticks: 1092
[12:29:48] 2 - Ticks: 1090
[12:29:49] 3 - Ticks: 1090
[12:29:50] 4 - Ticks: 1080
[12:29:51] 5 - Ticks: 1100
[12:29:52] 6 - Ticks: 1090
[12:29:54] 7 - Ticks: 1080
[12:29:55] 8 - Ticks: 1085
[12:29:56] 9 - Ticks: 1085
[12:29:57] 10 - Ticks: 1095
And as you can see, it even skips a second, so this takes about 11 seconds
But with my easy script, I got this output:

Код:
[11:00:11] 1 - Ticks: 1002
[11:00:12] 2 - Ticks: 1002
[11:00:13] 3 - Ticks: 1002
[11:00:14] 4 - Ticks: 1001
[11:00:15] 5 - Ticks: 1001
[11:00:16] 6 - Ticks: 1001
[11:00:17] 7 - Ticks: 1001
[11:00:18] 8 - Ticks: 1002
[11:00:19] 9 - Ticks: 1002
[11:00:20] 10 - Ticks: 1002
About 80 less milliseconds for "each second", and it doesn't skip any seconds.

How can I take advantage of this script?
Well, basically, you just edit the piece of code inside the tickcount check.
I thought about just posting this up in Script Tutorials, since this isn't really such a big script, and you have to edit it for your usage, but I figured out it probably fitted better in here.. Idk.

Download:

Pastebin: - ***
UPDATE
Pastebin: - http://pastebin.com/925qYdxw

And if you wanted to see the script for the first output, here it is:
http://pastebin.com/4yDsR2UW

ENJOY!
Reply
#2

A good idea, Larzi,
but doesnt this take much more cpu work than the unaccurate single timer?
It calls a timer like 500-600 times and checks for a variable, instead of just calling it once.

Nevertheless this is a good solution, if you need a high-precision timer. E.g. clocks seem to be quite f***ed up with the almost 10% tolerance of the normal timers.
Reply
#3

Offtopic: Why do people steal ******' font lol?


Ontopic: wow a 1ms timer, thats gnarly .



Edit: Why dont you set the interval higher, and just rely on GetTickCount if you need your timer to be that accurate? I mean no matter how often you get the ticks, the result will be the same, so why not use a 500ms timer and use GetTickCount?

also why use static if your variables have a global scope?
Reply
#4

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
Offtopic: Why do people steal ******' font lol?


Ontopic: wow a 1ms timer, thats gnarly .
OT: Because it's awesome. And it's not stealing


Yeah I know.. :P
Still accurate though.
Mostly useful for small countdowns (1-10 seconds)
Reply
#5

Quote:
Originally Posted by LarzI
Посмотреть сообщение
OT: Because it's awesome. And it's not stealing


Yeah I know.. :P
Still accurate though.
Mostly useful for small countdowns (1-10 seconds)
It may be because i am dead tired (4 am here lol), but i still dont see why you need a timer THAT fast or accurate for anything. To me its just not worth the strain of this timer, especially if it can be done using a less harsh interval.
Reply
#6

Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
It may be because i am dead tired (4 am here lol), but i still dont see why you need a timer THAT fast or accurate for anything. To me its just not worth the strain of this timer, especially if it can be done using a less harsh interval.
True, but what if someone want a that accurate timer.. Who knows, lol.
I was just bored and tried something out.. :P
Reply
#7

it very stupid to create 1 ms timer!!!
it disoptimized. LarzI die!
Reply
#8

Quote:
Originally Posted by YmOn
Посмотреть сообщение
it very stupid to create 1 ms timer!!!
it disoptimized. LarzI die!
Then increase the timer, lmao.
Relax or gtfo from these forums
Reply
#9

Since that code is being executed every 3rd, or 4th ms. I'd suggest just a slight change.

I re-wrote it, check it out: http://pastebin.com/5MJccWt3

This is what I get in server_log.txt:
Код:
[11:00:11] 1 - Ticks: 1002
[11:00:12] 2 - Ticks: 1002
[11:00:13] 3 - Ticks: 1002
[11:00:14] 4 - Ticks: 1001
[11:00:15] 5 - Ticks: 1001
[11:00:16] 6 - Ticks: 1001
[11:00:17] 7 - Ticks: 1001
[11:00:18] 8 - Ticks: 1002
[11:00:19] 9 - Ticks: 1002
[11:00:20] 10 - Ticks: 1002
Reply
#10

Quote:
Originally Posted by g_aSlice
Посмотреть сообщение
Since that code is being executed every 3rd, or 4th ms. I'd suggest just a slight change.

I re-wrote it, check it out: http://pastebin.com/5MJccWt3

This is what I get in server_log.txt:
Код:
[11:00:11] 1 - Ticks: 1002
[11:00:12] 2 - Ticks: 1002
[11:00:13] 3 - Ticks: 1002
[11:00:14] 4 - Ticks: 1001
[11:00:15] 5 - Ticks: 1001
[11:00:16] 6 - Ticks: 1001
[11:00:17] 7 - Ticks: 1001
[11:00:18] 8 - Ticks: 1002
[11:00:19] 9 - Ticks: 1002
[11:00:20] 10 - Ticks: 1002
Hmm, nicely done.
I'll update the first post with this link, giving you all the credits.
Cheers
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)