using System.Collections.Generic; using Newtonsoft.Json; using UnityEngine; using System.Linq; namespace Oxide.Plugins { [Info("DoorHealth", "Miho", "1.0.0")] [Description("Allows you to change the maximum health of doors")] public class DoorHealth : RustPlugin { private static ConfigData config = new ConfigData(); private class ConfigData { [JsonProperty(PropertyName = "Door health in percents")] public Dictionary percents = new Dictionary() { { "door.hinged.wood", 100 }, { "door.hinged.metal", 100 }, { "door.hinged.toptier", 100 }, { "door.double.hinged.wood", 100 }, { "door.double.hinged.metal", 100 }, { "door.double.hinged.toptier", 100 }, { "wall.frame.garagedoor", 100 }, { "door.hinged.industrial.d", 100 } }; } private void OnServerInitialized(bool initial) { foreach (Door d in BaseNetworkable.serverEntities.OfType()) { ModifyDoorHealth(d); } } private void Unload() { foreach (Door d in BaseNetworkable.serverEntities.OfType()) { ModifyDoorHealth(d, true); } } private void OnEntitySpawned(BaseNetworkable entity) { var door = entity as Door; if (door != null) { ModifyDoorHealth(door); } } private void ModifyDoorHealth(Door door, bool isUnloading = false) { if (door == null) return; int percent = 100; if (config.percents.TryGetValue(door.ShortPrefabName, out percent)) { if (percent <= 0) return; float originalMaxHealth; switch (door.ShortPrefabName) { case "door.hinged.wood": originalMaxHealth = 200f; break; case "door.hinged.metal": originalMaxHealth = 250f; break; case "door.hinged.toptier": originalMaxHealth = 1000f; break; case "door.double.hinged.wood": originalMaxHealth = 200f; break; case "door.double.hinged.metal": originalMaxHealth = 250f; break; case "door.double.hinged.toptier": originalMaxHealth = 1000f; break; case "wall.frame.garagedoor": originalMaxHealth = 600f; break; case "door.hinged.industrial.d": originalMaxHealth = 250f; break; default: return; } if (isUnloading) { door._maxHealth = originalMaxHealth; if (door.health > originalMaxHealth) { door.health /= percent / 100f; } } else { if (door._maxHealth == originalMaxHealth) { door._maxHealth *= percent / 100f; door.health *= percent / 100f; } } door.SendNetworkUpdate(BasePlayer.NetworkQueue.Update); } } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); if (config == null) { LoadDefaultConfig(); } SaveConfig(); } protected override void LoadDefaultConfig() { config = new ConfigData(); } protected override void SaveConfig() { Config.WriteObject(config); } } }