06.04.2019, 16:54
Quote:
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? |
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;