/** * OxidationAutoLights.cs * Copyright (C) 2023 kasvoton * * All Rights Reserved. * DO NOT DISTRIBUTE THIS SOFTWARE. * * You should have received a copy of the EULA along with this software. * If not, see . * * * ################################# * ### I AM AVAILABLE FOR HIRING ### * ################################# * * IF YOU WANT A CUSTOM PLUGIN FOR YOUR SERVER GET INTO CONTACT WITH ME SO * WE CAN DISCUSS YOUR NEED IN DETAIL. I CAN BUILD PLUGINS FROM SCRATCH OR * MODIFY EXISTING ONES DEPENDING ON THE COMPLEXITY. * * */ using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; namespace Oxide.Plugins { [Info("OxidationAutoLights", "kasvoton", "1.1.3")] [Description("Project Oxidation :: Automatic light control")] public class OxidationAutoLights : RustPlugin { private readonly List Lights = new List { "chineselantern.deployed", "jackolantern.angry", "jackolantern.happy", "lantern.deployed", "tunalight.deployed" }; // // --- UMOD EVENTS ----------------------------------------------------- // private void OnServerInitialized() { TOD_Sky.Instance.Components.Time.OnSunrise += OnSunrise; TOD_Sky.Instance.Components.Time.OnSunset += OnSunset; } private void Unload() { TOD_Sky.Instance.Components.Time.OnSunrise -= OnSunrise; TOD_Sky.Instance.Components.Time.OnSunset -= OnSunset; } // // --- CUSTOM EVENTS --------------------------------------------------- // private void OnSunrise() => ServerMgr.Instance.StartCoroutine(GlobalSetState(false)); private void OnSunset() => ServerMgr.Instance.StartCoroutine(GlobalSetState(true)); private object OnFuelConsume(BaseOven Oven, Item Fuel, ItemModBurnable Burnable) { if (Oven == null || Oven.IsDestroyed || Oven.OwnerID == 0) return null; if (!Lights.Contains(Oven?.ShortPrefabName)) return null; return false; } // // --- COROUTINES ------------------------------------------------------ // private IEnumerator GlobalSetState(bool PowerState) { int x = 0; foreach (BaseOven Oven in BaseNetworkable.serverEntities.OfType()) { if (Oven == null || Oven.IsDestroyed || Oven.OwnerID == 0) continue; if (!Lights.Contains(Oven?.ShortPrefabName)) continue; if (PowerState) Oven.StartCooking(); else Oven.StopCooking(); if (x % 10 == 0) yield return CoroutineEx.waitForEndOfFrame; x++; } } } }