Hi im looking to make a timer repeat itself every 5 minutes, the plugin currently has
"AutoTimers.Add(timer.Once(TimeBuild, () => StartFightPhase()));"
I took a look at the timer basics in the docs but that doesnt seem to help me i need it to say how long is currently left (Still new to working with plugins)
Repeating timer every 5 minutes?
Discussion in 'Rust Development' started by UKz RANDALL, Sep 12, 2016.
-
Wulf Community Admin
Code:timer.Every(300f, () => StartFightPhase();
-
Seemed to do the trick but its switching game phase every 5 minutes instead of displaying how long is left, "Build Phase" is set to last for 30 minutes then its meant to switch to "Fight Phase".
-
Why not do something like:
Code:const double totalDuration = 1800.0; const double notificationInterval = 300.0; var leftoverTime = totalDuration; timer.Once(totalDuration, StartFightPhase); timer.Repeat(notificationInterval, (int) (totalDuration / notificationInterval), () => { leftoverTime -= notificationInterval; // broadcast leftoverTime });
Last edited by a moderator: Sep 12, 2016 -
Code:private void StartBuildPhase() { DestroyTimers(); BuildPhase = false; BroadcastToChat(lang.GetMessage("Title", this) + lang.GetMessage("BuildPhase", this)); BroadcastToChat(string.Format(lang.GetMessage("Title", this) + lang.GetMessage("BuildPhaseTime", this), (TimeBuild / 60).ToString())); //Build Rate CraftingRate = CraftBuild; //Gather Rate GatherRate = BuildGatherMulti; //Update UpdateGatherRate(); UpdateCraftingRate(); //Timers PhaseStart = DateTime.Now.AddMinutes(TimeBuild / 60); AutoTimers.Add(timer.Every(300f, () => StartFightPhase())); }