05.06.2017, 13:24
I haven't personally tested it, but the logic seems right. Hour should actually be minute in the timer call, so:
The logic is:
Let's say the current minute is 20. If we take 60 and subtract 20, we get 40 minutes. There are 40 minutes left in the hour, so call the timer in 40 minutes. We multiply the result by 1000 afterwards to get the proper amount of time, since timer functions don't use seconds.
Current time: 3:40.
(60 - 40) = 20
20*(1000*60)
20 * 60000
= 20 minutes left until next hour
Edit: Sorry, another mistake. It needs to be 1000*60, not just 60, since its minutes we want and not seconds. Also, after the first timer call, you'll need to redo the timer for a straight hour. So,
pawn Code:
SetTimerEx("HourlyUpdate", (60 - minute) * 1000*60, false, "i", true);
Let's say the current minute is 20. If we take 60 and subtract 20, we get 40 minutes. There are 40 minutes left in the hour, so call the timer in 40 minutes. We multiply the result by 1000 afterwards to get the proper amount of time, since timer functions don't use seconds.
Current time: 3:40.
(60 - 40) = 20
20*(1000*60)
20 * 60000
= 20 minutes left until next hour
Edit: Sorry, another mistake. It needs to be 1000*60, not just 60, since its minutes we want and not seconds. Also, after the first timer call, you'll need to redo the timer for a straight hour. So,
pawn Code:
public HourlyUpdate(bool: firstcall)
{
if(firstcall == true)
{
KillTimer(HourTimer);
HourTimer = SetTimerEx("HourlyUpdate", 3600000, true, "i", false);
firstcall = false;
}
// after insert
if(server_hour == 23) server_hour = 0;
else server_hour ++;
}