Most accurate way to make a stopwatch/timer?
What's the most accurate method to make a stopwatch/timer? I am looking to update my KZ plugin.
For example, make a set_task and increment something every .1 seconds and have the results of that be your time? Or maybe do a start = get_gametime() then a finish = (get_gametime() - start)? (keep in mind i will have to use a set_task to keep a live display of a player's running time) Additional question: Do timerbugs affect plugins or only map timers for KZ maps? If you don't know what a timerbug is, here's it's definition from xtreme-jumps: "The KZ Timer isnt 100% exact, there are time shifts of 0,1-1 seconds on small maps (under 2 min) and shifts about 2-3 seconds on bigger maps (under 5 minutes) and time shifts up to 6 seconds on really big maps (5-15 minutes). A timerbug occurs with a probability of 90% if the server is running longer than 60 minutes: The timer will show a better time than you actually achieved. (about 5-15 seconds better). The probablity that a timerbug will occur if your server is running for less than 60 minutes is 0,0%." Thanks, --MALON |
Re: Most accurate way to make a stopwatch/timer?
I think the accurate methode to make a KZ plugin is with get_gametime() for start/finish. For live timer display you don't need a task, just make get_gametime() - start and show it as a float. I think that timerbug is occuring when server works on low FPS, but dunno shure.
|
Re: Most accurate way to make a stopwatch/timer?
Thank you for the reply, but I didn't quite follow how I won't need a set_task to use the get_gametime() method of a stopwatch.
The goal is to have a HUD display that shows in real time what their elapsed time is since hitting the start button during the run, which of course would need to be updated at least once a second. I'm not understanding how to get away with updating it without a set_task. Sorry, --MALON |
Re: Most accurate way to make a stopwatch/timer?
Oh, in this case have a look on this tutorial -> http://forums.alliedmods.net/showthr...highlight=task
All you have to do is to make an ent, hook the Think forward, check for that ent, and set its next_think to 0.1 for best results. |
Re: Most accurate way to make a stopwatch/timer?
PHP Code:
So I made what I thought would be a 1 second counter, but it's far from it. I must not be understanding how to use the think forwards properly. Any help would be awesome. Thanks for you help so far, Alka. You've really put me on the right track at least. --MALON |
Re: Most accurate way to make a stopwatch/timer?
Actually, come to realize, I think it's a bad idea to use prethink to calculate a timer, because then the timer is based off of the client's FPS. Please correct me if I'm wrong. I think that doing a get_gametime() method might be best.
Thanks, --MALON |
Re: Most accurate way to make a stopwatch/timer?
1 Attachment(s)
No. That is not based on player FPS, that is a ent think on server side, not player...and yes get_gametime() is the best solution.
I maked this plugin for test.Show actual time elipsed since you typed /start . Also you can stop and reset timer with /reset command.Try it and tell me if is good. |
Re: Most accurate way to make a stopwatch/timer?
Part of the code from the KZ Plugin i was working on:
PHP Code:
|
Re: Most accurate way to make a stopwatch/timer?
Your current methods should work fine.
Under no circumstance should you use set_task for this kind of project. AMXX team broke this native a very long time ago when they didn't know what they were doing, it is still broke now funny enough :avast: |
| All times are GMT -4. The time now is 03:12. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.