Custom Server time
#8

Quote:
Originally Posted by MP2
Посмотреть сообщение
1. Declare two variables - one to store the current hour and one to store the current minute.
2. Set a repeating one second timer to increase the current minute. If the current minute reaches 60, set it to 0 and increase the current hour. If the current hour reaches 24, set it to 0.
3. Set a player's time when the spawn or perhaps periodically (once a minute?) to keep players' time in sync.

Note that with TogglePlayerClock enabled, if a player pauses, their clock will pause for the duration they are paused. So perhaps also sync the time when a player unpauses (when no longer paused, detected using OnPlayerUpdate).

Hope this was helpful, unless you are attempting to do something different from this?
If you want it to be accurate - which is better if you use the ingame clock since timers aren't perfectly accurate - use the unix timestamp and modulo it by 1440 (24 minutes). Then convert the result to hours and minutes.
This will also have the nice side-effect that the ingame time will be an exactly 60x sped up equivalent to the real time, meaning every real life day at 18:54 server time it will be 6:00 ingame with a stable pattern.

Using timers you'll occassionally notice the ingame time getting out of sync and it will never be the same ingame time at the same time of RL day because of the inaccuracy (which becomes very noticable after a while, even with timerfix).

Код:
new tstamp = gettime() % 1440,
    hour = tstamp / 60,
    min = tstamp % 60;
It's technically even easier to code.
Reply


Messages In This Thread
Custom Server time - by NoahAntilles - 21.03.2019, 20:22
Re: Custom Server time - by NoahAntilles - 21.03.2019, 21:43
Re: Custom Server time - by NoahAntilles - 22.03.2019, 09:41
Re: Custom Server time - by Kaliber - 22.03.2019, 09:51
Re: Custom Server time - by NoahAntilles - 22.03.2019, 16:21
Re: Custom Server time - by NoahAntilles - 05.04.2019, 15:49
Re: Custom Server time - by MP2 - 06.04.2019, 15:56
Re: Custom Server time - by NaS - 06.04.2019, 16:54

Forum Jump:


Users browsing this thread: 1 Guest(s)