[Plugin] Timerfix plugin - A fix for every ttime related issue
#1


Timerfix
Timerfix provides an improvement (increases the accuracy) to the timers system existent in SA-MP server.

Building
  • Windows: Open the samp-plugin-timerfix.sln and hit the `Build` button. Binaries will be located in the bin/ folder and will have the name timerfix.dll.
  • Linux: Type in terminal make. Binaries will be located in the bin/ folder and will have the name timerfix.so.
Installing
  1. Move the binaries in the plugins/ folder.
  2. Write timerfix (Windows) or timerfix.so (Linux) in the server.cfg at the end of the line containing plugins.
  3. Add the #include <timerfix> at the top of the script only if you want to use additional methods added.
Notes
  1. This plugin fixes the basic timer system existent in SA:MP (SetTimer, SetTimerEx, KillTimer) and GetTickCount.
  2. This plugin also adds new natives (player timers, which are automatically killed when the player disconnects; there is a hook in the include file), which require `timerfix` include file.
Benchmarks
I haven't done any yet.

For downloads please check the downloads branch for anything else check the project on Github.com
Reply
#2

Change
Code:
#if defined TIMERFIX_OnPlayerDisconnect
		return TIMERFIX_OnPlayerDisconnect(playerid);
to
Code:
#if defined TIMERFIX_OnPlayerDisconnect
		return TIMERFIX_OnPlayerDisconnect(playerid, reason);
EDIT: + Add something like "KillPlayerTimer(timerid)", because I don't want to define for every PlayerTimer the delay untill the PlayerTimer is deleted. KillPlayerTimers delete all PlayerTimers, that's useless for me.
Reply
#3

Looks good! Might actually consider using it, I want to see some benchmarks first
Reply
#4

Definitely will try
Reply
#5

I'm waiting for some benchmarking against fixes2.
Reply
#6

May I ask what this thing does?
Reply
#7

Quote:
Originally Posted by SA-MP Wiki
Timer intervals are not accurate (roughly 25% off). There are fixes available for this on the SA-MP forums.
Apparently, this is one of the fixes.
Reply
#8

Quote:
Originally Posted by [DFE]Ike
View Post
Change
Code:
#if defined TIMERFIX_OnPlayerDisconnect
		return TIMERFIX_OnPlayerDisconnect(playerid);
to
Code:
#if defined TIMERFIX_OnPlayerDisconnect
		return TIMERFIX_OnPlayerDisconnect(playerid, reason);
EDIT: + Add something like "KillPlayerTimer(timerid)", because I don't want to define for every PlayerTimer the delay untill the PlayerTimer is deleted. KillPlayerTimers delete all PlayerTimers, that's useless for me.
KillTimer(timerid) works for player timers too!

Quote:
Originally Posted by Bicentric
View Post
Looks good! Might actually consider using it, I want to see some benchmarks first
Quote:
Originally Posted by Rockk
View Post
I'm waiting for some benchmarking against fixes2.
Why? This is as fast as the basic timer system and ******'s plugin.

Quote:
Originally Posted by OpticKiller
View Post
May I ask what this thing does?
SA-MP timers and all time related functions aren't as accurate as you may think. This fixes them.
Reply
#9

I am pretty content with Slice's include: https://sampforum.blast.hk/showthread.php?tid=289675 . Why should I use this over that include, if you can please explain?
Reply
#10

Quote:
Originally Posted by Cell_
View Post
I am pretty content with Slice's include: https://sampforum.blast.hk/showthread.php?tid=289675 . Why should I use this over that include, if you can please explain?
It is faster, uses less resources, fixes more issues, adds new features.
Reply
#11

I've released v1.2. This fixes all player timers related issues. If you use them, please update!

Quote:
Originally Posted by Rajat_Pawar
View Post
Thanks, it's good. I don't know if it matters to you, but some reputation, you have earned! Cheers. Also, could you mind PMing me and sharing a few pointers with me about plugins? Writing them? Seeing that you are a plugin guy! (No, I don't want a link to the plugin tutorial.)
Well.. I started reading that plugin tutorial. I really don't know any better learning material.

Quote:
Originally Posted by Luis-
View Post
What would I do if I was too repeat the timer? I see nothing related to repeating.
Please read the documentation. There is a "repeating" paramter.
Reply
#12

Ah, thanks!
Reply
#13

Quote:
Originally Posted by Dan..
View Post
* This plugin also adds new natives (player timers, which are automatically killed when the player disconnects; there is a hook in the include file), which require `timerfix` include file.
This per-player timers are very useful (i think i will use they in the future). I know per-player timers are scriptable, but in my opinion, everything made in C++(plugin, like these functions) are more accurately than in pawn. Good Job !
Reply
#14

I just updated to v1.2 to find I couldn't connect to my server, reverted back to v1.1 and could connect.
Reply
#15

Quote:
Originally Posted by Luis-
View Post
I just updated to v1.2 to find I couldn't connect to my server, reverted back to v1.1 and could connect.
Can you post your server_log.txt? I tested on multiple servers and it works fine.
Reply
#16

I tested the timers with a 1000ms interval without this plugin and they are executed at a interval of ~1050ms, with this plugin they are at 1000ms +- 5ms (very accurate).

I have a suggestion, this could be useful (at least for me):
pawn Code:
native GetTimerCountLeft( timerid );
/*
    Returns:
-1: infinite timer (basic timers with repeating at 1 or improved timers with count at -1)
0: inexistent timers (timers with execution finished, or which didn't existed at all)
number of counts left: if there are counts left (improved timers)
*/
Reply
#17

Pretty much a month has passed since the last post, but it's a really great and useful plugin.
I tested it on 1000 milliseconds timer with parameters and it was executed at 995-1005.

I'd like to learn though, how can I use the delay parameter. On the test, I set it to 1000, just like the interval.

Thanks and very good job!

EDIT: On a test at 5000 milliseconds, here's the results:

pawn Code:
[16:41:59] OnServerCheckMoney: 5006
[16:42:04] OnServerCheckMoney: 4773 // Ouch
[16:42:09] OnServerCheckMoney: 4999
[16:42:14] OnServerCheckMoney: 5001
[16:42:19] OnServerCheckMoney: 5003
[16:42:24] OnServerCheckMoney: 4998
[16:42:29] OnServerCheckMoney: 4996
[16:42:34] OnServerCheckMoney: 5004
[16:42:39] OnServerCheckMoney: 4997
[16:42:44] OnServerCheckMoney: 4997
[16:42:49] OnServerCheckMoney: 5001
[16:42:54] OnServerCheckMoney: 5002
[16:42:59] OnServerCheckMoney: 4998
[16:43:04] OnServerCheckMoney: 5000
[16:43:09] OnServerCheckMoney: 4997
[16:43:14] OnServerCheckMoney: 5002
[16:43:19] OnServerCheckMoney: 4993
[16:43:24] OnServerCheckMoney: 5004
[16:43:29] OnServerCheckMoney: 4914
[16:43:34] OnServerCheckMoney: 4994
[16:43:39] OnServerCheckMoney: 5000
[16:43:44] OnServerCheckMoney: 5001
[16:43:49] OnServerCheckMoney: 4997
[16:43:54] OnServerCheckMoney: 5000
[16:43:59] OnServerCheckMoney: 5003
[16:44:04] OnServerCheckMoney: 4998
[16:44:09] OnServerCheckMoney: 4996
[16:44:14] OnServerCheckMoney: 5001
[16:44:19] OnServerCheckMoney: 5001
[16:44:24] OnServerCheckMoney: 4996
[16:44:29] OnServerCheckMoney: 5000
[16:44:35] OnServerCheckMoney: 5003
[16:44:39] OnServerCheckMoney: 3703 // OUCH!
[16:44:44] OnServerCheckMoney: 4998
[16:44:49] OnServerCheckMoney: 5001
Excluding these 2 results, the rest of it seems to be good enough!
Reply
#18

The delay should be the time that is required to pass after which the timer will start working.
Example: delay 5 sec, timer 1sec
5 seconds will pass and then a 1 second timer will start working.
Reply
#19

Quote:
Originally Posted by IstuntmanI
View Post
I have a suggestion, this could be useful (at least for me):
pawn Code:
native GetTimerCountLeft( timerid );
/*
    Returns:
-1: infinite timer (basic timers with repeating at 1 or improved timers with count at -1)
0: inexistent timers (timers with execution finished, or which didn't existed at all)
number of counts left: if there are counts left (improved timers)
*/
Also, another one:
pawn Code:
native GetTimerIntervalLeft( timerid );
/*
    Returns:
0: inexistent timers (timers with execution finished, or which didn't existed at all)
interval left: how many milliseconds left until the timer is called again
*/
Well... ?
Reply
#20

I have a problem. I have this in my script:
Code:
mytimer[playerid] = SetPlayerTimerEx(playerid, "FunctionName", 990, true, "i", playerid);
And after, in OnDialogResponse i use:
Code:
KillPlayerTimer(mytimer[playerid]);
to kill the repeating process, but i don't know why, the timer aren't getting destroyed. It still repeats... It's a plugin bug, or i did something wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)