using System; using System.Collections.Generic; namespace Oxide.Plugins { [Info("Infinite Candles and Fog", "bsdinis", "0.0.7")] [Description("Candles burn indefinitely and Fog and Snow Machines do not consume fuel.")] class InfiniteCandlesFog : RustPlugin { List candles = new List(); List fogs = new List(); ItemDefinition fuel = ItemManager.FindItemDefinition("lowgradefuel"); void Init() { Unsubscribe(nameof(OnEntitySpawned)); permission.RegisterPermission("infinitecandlesfog.candle", this); permission.RegisterPermission("infinitecandlesfog.fog", this); permission.RegisterPermission("infinitecandlesfog.snow", this); } void OnServerInitialized() { Subscribe(nameof(OnEntitySpawned)); foreach (BaseNetworkable entity in BaseNetworkable.serverEntities) { Candle candle = entity as Candle; FogMachine fog = entity as FogMachine; if (candle != null) OnEntitySpawned(candle); else if (fog != null) OnEntitySpawned(fog); } } void OnEntitySpawned(Candle candle) { if (candle == null) return; BasePlayer player = BasePlayer.FindAwakeOrSleeping(candle.OwnerID.ToString()); if (player == null || !permission.UserHasPermission(player.UserIDString, "infinitecandlesfog.candle")) return; candles.Add(candle); candle.lifeTimeSeconds = 999999f; candle.burnRate = 0f; } void OnEntitySpawned(FogMachine fog) { if (fog.IsDestroyed || !fog.OwnerID.IsSteamId()) return; BasePlayer player = BasePlayer.FindAwakeOrSleeping(fog.OwnerID.ToString()); if (player == null) return; if (fog is SnowMachine) { if (!permission.UserHasPermission(player.UserIDString, "infinitecandlesfog.snow")) return; } else { if (!permission.UserHasPermission(player.UserIDString, "infinitecandlesfog.fog")) return; } if (fog is SnowMachine) { SnowMachine sm = fog as SnowMachine; Item lgf = ItemManager.Create(fuel, 1); lgf.MoveToContainer(sm.inventory); sm.fuelPerSec = 0f; sm.CancelInvoke(new Action(sm.CheckTrigger)); sm.SetFlag(BaseEntity.Flags.On, true, true, true); sm.InvokeRepeating(new Action(sm.StartFogging), 0, 60); } else { fog.fuelPerSec = 0f; fog.CancelInvoke(new Action(fog.CheckTrigger)); fog.SetFlag(BaseEntity.Flags.On, true, true, true); fog.EnableFogField(); fog.InvokeRepeating(new Action(fog.StartFogging), 0, 60); } } void OnEntityKill(BaseNetworkable networkable) { Candle candle = networkable as Candle; FogMachine fog = networkable as FogMachine; if (candle != null) candles.Remove(candle); else if (fog != null) fogs.Remove(fog); } void Unload() { for (int i = 0; i < candles.Count; i++) { candles[i].lifeTimeSeconds = 7200f; candles[i].burnRate = 10f; } for (int i = 0; i < fogs.Count; i++) { if (fogs[i] is SnowMachine) fogs[i].fuelPerSec = 3f; else fogs[i].fuelPerSec = 1f; } } } }