SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 05/03/2018, 05:13 PM   #1
KashCherry
Big Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 50
Reputation: 24
Default Timer Fix

Timer Fix v1.0.7


Description
This plugin makes timers more accurate


Natives
PHP Code:
native SetTimer(funcname[], intervalbool:repeat);
native SetTimerEx(funcname[], intervalbool:repeat, const format[], {Float,_}:...);
native KillTimer(const id);
native KillAllTimers();
native IsValidTimer(timerid);
native GetTimerInterval(timerid);
native SetTimerInterval(timeridinterval); 

Example
PHP Code:
#include <timerfix>

new num 0;
new 
timer;

main() {
  
timer SetTimer("callback",1000,true)
}

forward callback();
public 
callback() {
  if(++
num >= 5) {
    if(
IsValidTimer(timer)) KillTimer(timer);
    
SetTimerEx("callbackEx",1000,false,"d",num);
  }
}

forward callbackEx(num);
public 
callbackEx(num) {
  
printf("Num: %d",num);
  
KillAllTimers();


Download
Binaries(Windows, Linux)
Source code

Last edited by KashCherry; 19/11/2018 at 04:13 PM.
KashCherry is online now   Reply With Quote
Old 05/03/2018, 06:22 PM   #2
Sting.
Gangsta
 
Sting.'s Avatar
 
Join Date: May 2011
Location: Malaysia
Posts: 867
Reputation: 122
Default Re: Timer Fix - Do not miss a one second

Looks nice. Have you tested it out? Is it very accurate?
Sting. is offline   Reply With Quote
Old 05/03/2018, 06:31 PM   #3
KashCherry
Big Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 50
Reputation: 24
Default Re: Timer Fix - Do not miss a one second

Quote:
Originally Posted by Sting. View Post
Looks nice. Have you tested it out? Is it very accurate?
+- 5ms.

Last edited by KashCherry; 20/08/2018 at 07:25 PM.
KashCherry is online now   Reply With Quote
Old 05/03/2018, 07:28 PM   #4
iKarim
Gangsta
 
iKarim's Avatar
 
Join Date: Oct 2015
Posts: 583
Reputation: 139
Default Re: Timer Fix - Do not miss a one second

I'd suggest hooking the SetTimer functions and call the plugin's instead in the include, and provide an option to disable that as it's either to use as a plug-play instead of replacing function names, ...

Other than that, good job!
iKarim is online now   Reply With Quote
Old 05/03/2018, 08:17 PM   #5
KashCherry
Big Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 50
Reputation: 24
Default Re: Timer Fix - Do not miss a one second

Plugin updated to version 0.6

- Added hook Timer's natives
KashCherry is online now   Reply With Quote
Old 06/03/2018, 02:09 PM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,241
Reputation: 3185
Default Re: Timer Fix - Do not miss a one second

What's the advantage of this version over udan's, YSF's, Slice's, or any other?

I had a quick look at the code:

1) Strings are not done properly. You need to copy them to storage entirely, you can't just store the address, which may be inaccurate or have expired.

2) Arrays aren't handled at all.

3) There's no error checking on any of the `amx_` functions - what if `amx_Push` fails?

4) Public functions can actually change their index with some includes. Caching that may call the wrong function in some cases.

5) Why `end_time - 5`? That seems to be introducing artificial inaccuracies.

6) You can't call `_timer_map.erase(iter);` inside a loop using that iterator. That call invalidates the iterator, thus meaning that trying to move on to the next item is undefined behaviour. The common solution is:

PHP Code:
for (auto it _timer_map.begin(); it != _timer_map.end(); )
{
    if (
done)
        
_timer_map.erase(it++);
    else
        
it++;

Y_Less is online now   Reply With Quote
Old 06/03/2018, 08:07 PM   #7
KashCherry
Big Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 50
Reputation: 24
Default Re: Timer Fix - Do not miss a one second

Quote:
Originally Posted by Y_Less
What's the advantage of this version over udan's, YSF's, Slice's, or any other?
As I saw Slice deleted his fix?

Comparisons with this plugin & udan's plugin (5 seconds, Windows x64):
PHP Code:
// this plugin (v0.7)
5000ms
5000ms
5000ms
5000ms
5000ms

// udan's plugin (v1.5)
5004ms
4997ms
5000ms
5004ms
5000ms 
About YSF: I don't know how to test this, can you please do it?

1.) Fixed
2.) Fixed
3.) Fixed
4.) Fixed
5.) Fixed
6.) Fixed

Plugin updated to version 0.7

- Fixed some bugs
- Improved accuracy

Last edited by KashCherry; 06/06/2018 at 09:49 PM.
KashCherry is online now   Reply With Quote
Old 16/03/2018, 03:39 PM   #8
Dim4Shift
Banned
 
Join Date: Mar 2018
Location: Moldova of Republic
Posts: 2
Reputation: 0
Default Re: Timer Fix - Do not miss a one second

Quote:
Originally Posted by KashCherry View Post
Timer Fix v0.7


Description
This plugin makes timers more accurate


Natives
PHP Code:
native SetTimer(funcname[], intervalbool:repeat);
native SetTimerEx(funcname[], intervalbool:repeat, const format[], {Float,_}:...);
native KillTimer(const id);
native KillAllTimers(); 

Example
PHP Code:
#include <timerfix>

new num 0;
new 
timer;

main() {
  
timer SetTimer("callback",1000,true)
}

forward callback();
public 
callback() {
  if(++
num >= 5) {
    
KillTimer(timer);
    
SetTimerEx("callbackEx",1000,false,"d",num);
  }
}

forward callbackEx(num);
public 
callbackEx(num) {
  
printf("Num: %d",num);
  
KillAllTimers();


Download
Binaries(Windows, Linux)
Source code
the idea is good ... but when I put this plugin the server blocks the players from connecting.

Code:
[10:57:29]  Loading plugin: timerfix.so
[10:57:29]   Timer Fix plugin v0.7 by KashCherry loaded
[10:57:29]   Loaded.
[10:57:29]  Loaded 9 plugins.

[10:57:29] 
[10:57:29] Filterscripts
[10:57:29] ---------------
[10:57:29]   Loaded 0 filterscripts.

[10:57:30] MySQL baza, a fost conectata!
[10:57:30] 
-----------
Vehicle: 156
MaterialObjects: 112
Objects: 750
DynamicObjects: 2424
Pickps: 20
-----------
[10:57:30] Number of vehicle models: 46
[10:58:24] Kicking 92.119.39.147 because they didn't logon to the game.
[10:58:24] Kicking 200.53.203.103 because they didn't logon to the game.
[10:58:30] [connection] incoming connection: 200.53.203.103:29209 id: 0
[10:58:30] Invalid client connecting from 200.53.203.103
[10:58:30] [connection] incoming connection: 92.119.39.147:54599 id: 1
[10:58:30] [connection] incoming connection: 200.53.203.103:29217 id: 2
[10:58:30] Invalid client connecting from 92.119.39.147
[10:58:30] Invalid client connecting from 200.53.203.103
Dim4Shift is offline   Reply With Quote
Old 16/03/2018, 05:06 PM   #9
KashCherry
Big Clucker
 
KashCherry's Avatar
 
Join Date: Feb 2018
Location: Estonia
Posts: 50
Reputation: 24
Default Re: Timer Fix - Do not miss a one second

Quote:
Originally Posted by Dim4Shift View Post
the idea is good ... but when I put this plugin the server blocks the players from connecting.

Code:
[10:57:29]  Loading plugin: timerfix.so
[10:57:29]   Timer Fix plugin v0.7 by KashCherry loaded
[10:57:29]   Loaded.
[10:57:29]  Loaded 9 plugins.

[10:57:29] 
[10:57:29] Filterscripts
[10:57:29] ---------------
[10:57:29]   Loaded 0 filterscripts.

[10:57:30] MySQL baza, a fost conectata!
[10:57:30] 
-----------
Vehicle: 156
MaterialObjects: 112
Objects: 750
DynamicObjects: 2424
Pickps: 20
-----------
[10:57:30] Number of vehicle models: 46
[10:58:24] Kicking 92.119.39.147 because they didn't logon to the game.
[10:58:24] Kicking 200.53.203.103 because they didn't logon to the game.
[10:58:30] [connection] incoming connection: 200.53.203.103:29209 id: 0
[10:58:30] Invalid client connecting from 200.53.203.103
[10:58:30] [connection] incoming connection: 92.119.39.147:54599 id: 1
[10:58:30] [connection] incoming connection: 200.53.203.103:29217 id: 2
[10:58:30] Invalid client connecting from 92.119.39.147
[10:58:30] Invalid client connecting from 200.53.203.103
Fixed, download from here.
KashCherry is online now   Reply With Quote
Old 16/03/2018, 05:22 PM   #10
Dim4Shift
Banned
 
Join Date: Mar 2018
Location: Moldova of Republic
Posts: 2
Reputation: 0
Default Re: Timer Fix - Do not miss a one second

Quote:
Originally Posted by KashCherry View Post
Fixed, download from here.
WOW nice ++! is posible add native IsValidTimer(timerid); ? to bypass this error:

Code:
[12:15:08] [Timer Fix] KillTimer: cannot find timer with id 0
exemple pawn code:
Code:
#define INVALID_TIMER_ID    (0xFFFF)

stock IsValidTimer(timerid) {
	if(timerid != INVALID_TIMER_ID) return true;
	return false;
}

Last edited by Dim4Shift; 16/03/2018 at 06:01 PM.
Dim4Shift is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timer ID stored in a variable gets wiped when timer hits ? NeXoR Scripting Help 2 25/03/2017 08:22 PM
Performance Question , Per Player Timer vs Timer that loops through all players BiosMarcel Scripting Help 14 12/12/2016 10:50 AM
If /foodsearch doesn't find item, set wait timer (TIMER HELP) Josh_Main Scripting Help 7 14/09/2016 05:13 PM
Which is better Per Player Timer or Global timer? (issue with timer) Dokins Scripting Help 4 07/06/2016 10:50 AM
Slice's Timer Fix include --> timer public function isn't getting called Riwerry Scripting Help 0 02/01/2016 04:50 PM


All times are GMT. The time now is 02:33 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.