I'm trying to make a timer wait n seconds based on a range of in-game time (ie, 2hrs): I've tried the following:
The problem I'm seeing is that it only seems to cover just over half of the desired wait time, so I get many extra timers spawned:Code:void TimerLoop() { float nextEvent = NextEvent(TOD_Sky.Instance.Cycle.Hour); // calculate time to next event float realtimeSeconds = TOD_Sky.Instance.Components.Time.DayLengthInMinutes * 60f; // to seconds float timeToWait = nextEvent / 24f * realtimeSeconds; timer.Once(timeToWait, () => TimerLoop()); }
Is there something I'm missing? Or a more accurate way to do this than to just scale my timers by 2x?Code:TimerLoop: wait time: 28.03087 TimerLoop: wait time: 13.80358 TimerLoop: wait time: 6.753445 TimerLoop: wait time: 3.32365 TimerLoop: wait time: 1.640511 TimerLoop: wait time: 0.5607605 TimerLoop: wait time: 0.2749443 TimerLoop: wait time: 0.1161575 TimerLoop: wait time: 0.05264282 TimerLoop: wait time: 0.02088547 TimerLoop: wait time: 599.9891
Solved Getting accurate realtime from game time?
Discussion in 'Rust Development' started by ignignokt84, Feb 22, 2017.
-
Code:
TOD_Sky.Instance.Components.Time.OnDay += ()=> { Interface.Oxide.LogInfo("one day passed..."); };
-
Sorry, but that's not what I'm looking for. I'm looking for a more accurate way to translate x in-game hours to y real-time seconds.
EDIT: Looks like I just have to scale the time by 2f - I guess "Day" length translates to daytime?Last edited by a moderator: Feb 22, 2017 -
TOD_Sky.Instance.Cycle.DateTime.ToShortTimeString() ?
Edit: Misunderstand your question, this method is to get ingame hours+seconds, not converted to real time passed. -
As far as I can tell you want an event to occur every 2 hours (in-game time) so you would actually be able to use a variant of what Andrew Mensky suggested before. The TODTimeComponent has various events you can add an action to, including `OnHour` which is supposed to trigger on the hour (in-game time) every hour.