open.mp forum
[Pawn] SetTimer looping through players with gettime() function - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] SetTimer looping through players with gettime() function (/showthread.php?tid=703)



SetTimer looping through players with gettime() function - unix - 2019-07-09

-delete


RE: SetTimer looping through players with gettime() function - Cada - 2019-07-09

1. first Checker call time - second Checker call time != 1.

2. i think the result will be changed as initial value of TickChecker[0].

gettime() | TickChecker[0]
[23:08:45] 1562681325 1562681327
[23:08:45] [dbg] Sent checkertick
[23:08:46] 1562681326 1562681327
[23:08:46] [dbg] Sent checkertick
[23:08:47] 1562681327 1562681328
[23:08:47] [dbg] Sent checkertick
[23:08:48] 1562681328 1562681329
[23:08:48] [dbg] Sent checkertick
[23:08:49] 1562681329 1562681330
[23:08:49] [dbg] Sent checkertick
[23:08:50] 1562681330 1562681331
[23:08:50] [dbg] Sent checkertick
[23:08:52] 1562681332 1562681332
[23:08:53] 1562681333 1562681332
[23:08:54] 1562681334 1562681332
[23:08:55] 1562681335 1562681332
[23:08:56] 1562681336 1562681332
[23:08:58] 1562681337 1562681332
[23:08:58] 1562681338 1562681332

this happens because next TickChecker[0]`s value is based on pre gettime(), and this not mean seconds


RE: SetTimer looping through players with gettime() function - unix - 2019-07-09

(2019-07-09, 01:54 PM)Cada Wrote: gettime(&hour=0,&minute=0,&second=0)



your function usage is wrong



No it is not wrong, if not using the syntax inside the function it returns the year,hour,month,second,day in seconds e.g 15206501548


RE: SetTimer looping through players with gettime() function - unix - 2019-07-11

Anyone?


RE: SetTimer looping through players with gettime() function - Y_Less - 2019-07-13

You have a 0 element array. I'm surprised that code even compiles.


RE: SetTimer looping through players with gettime() function - unix - 2019-07-17

(2019-07-13, 06:38 PM)Y_Less Wrote: You have a 0 element array. ?I'm surprised that code even compiles.



I have tried without a 0 element array although, still having the same problem. :(


RE: SetTimer looping through players with gettime() function - Y_Less - 2019-07-21

It could be crashing. It's hard to say without the rest of the code. Have you run this with crashdetect active?


RE: SetTimer looping through players with gettime() function - fusez - 2019-07-23

This is how i would solve the problem.

I didn't try compiling it but it should work, let me know.



Code:
#define CHECKER_EXEC_INTERVAL_S? ? ?2

#define CHECKER_TIMER_INTERVAL_MS 1000



new nextCheckerTime;



public OnGameModeInit()

{

? ?SetTimer("Checker", CHECKER_TIMER_INTERVAL_MS, true);

}



forward Checker();

public Checker()

{

? ?prinft("[DEBUG] Checker(): gettime() = %i, nextCheckerTime = %i", gettime(), nextCheckerTime);



? ?if( gettime() >= nextCheckerTime )

? ?{

? ? ? ?print("[DEBUG] Checker(): gettime() >= nextCheckerTime");

? ? ? ?// do shit here..

? ? ? ?nextCheckerTime = gettime()  CHECKER_EXEC_INTERVAL_S ; // Apply the next time value to this variable. When gettime() exceeds or equals this value the code within these brackets will be called again.

? ?}

}