SA-MP Forums Archive
SetTimer have delay - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetTimer have delay (/showthread.php?tid=510260)



SetTimer have delay - Koala818 - 30.04.2014

Hi and thanks that you wasted your time and looked at my thread first of all .

Ok, so i'm tryin' to make a RP gamemode and i have a problem with the PayDay system. I made a timer, that activates another timer at the next minute:00 and the last activated timer is set on repeat, so basically it should call my function at every minute:00. Here is my code:
Код:
public OnGameModeInit()
{
	new h,mi,s;
	gettime(h,mi,s);
	SetTimer("setminutetime", 60000-(s*1000), 0);
}
public setminutetime()
{
	MinuteTime();
    MinuteTimer = 		SetTimer ( "MinuteTime" , 60000 , 1 ) ;
    return 1;
}
public MinuteTime()
{
    print("peleme");
    new Ora, Minut, Secunde;
    gettime ( Ora , Minut , Secunde );
    if(Minut == 0){
    		foreach (Player , i) {
			if ( IsPlayerConnected(i) == 1 ) PayDay ( i ) ;
		}
	}
}
It should give the PayDay to players at all hours:00:00, but the problems is that i've got a delay. I know that Timers use resources but i don't know how else could i give the payday to players at all :00 hours.

Here's the serverlog:
Quote:

[16:41:35] Number of vehicle models: 0
[16:41:57] peleme
[16:43:03] peleme
[16:44:09] peleme
[16:45:16] peleme
[16:46:22] peleme
[16:47:28] peleme
[16:48:33] peleme
[16:49:39] peleme

As you can see the function gets called after more than a minute every time. Some ideas? :-s


Re: SetTimer have delay - RajatPawar - 30.04.2014

Timers have a delay offset of about 25%. You can use Slice's timer fix or the fixes2 plugin to get better accuracy.


Re: SetTimer have delay - Koala818 - 30.04.2014

Quote:
Originally Posted by RajatPawar
Посмотреть сообщение
Timers have a delay offset of about 25%.
Woah, they should really specify this on wiki.sa-mp.com. I investigated this for some time and i tought that my code was consuming too many resources, so that's why it has an offset. After i included Slice's timerfix i've got exactly what i wanted:
Quote:

[17:25:53] Number of vehicle models: 0
[17:26:00] peleme
[17:27:00] peleme
[17:28:00] peleme
[17:29:00] peleme
[17:30:00] peleme
[17:31:00] peleme
[17:32:00] peleme

Thanks for helping me!