Exemplo n.º 1
0
        public override void OnEnable()
        {
            if (!Config.GetBool("util_enable", true))
            {
                return;
            }

            Info("Loading Common-Utils, created by the EXILED Team!");

            Instance = this;

            HarmonyInstance = HarmonyInstance.Create("exiled.common.utils");
            HarmonyInstance.PatchAll();

            bool enable914Configs = Config.GetBool("util_914_enable", true);

            if (enable914Configs)
            {
                Dictionary <string, string> configHealth = KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_role_health", "NtfCommander:400,NtfScientist:350"));

                try
                {
                    foreach (KeyValuePair <string, string> kvp in configHealth)
                    {
                        roleHealth.Add((RoleType)Enum.Parse(typeof(RoleType), kvp.Key), int.Parse(kvp.Value));
                        DebugBoi(kvp.Key + "'s default health is now: " + kvp.Value);
                    }
                    Info("Loaded " + configHealth.Keys.Count() + "('s) default health classes.");
                }
                catch (Exception e)
                {
                    Error("Failed to add custom health to roles. Check your 'util_role_health' config values for errors!\n" + e);
                }

                Dictionary <string, string> configRoles =
                    KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_914_roles", ""));
                try
                {
                    foreach (KeyValuePair <string, string> kvp in configRoles)
                    {
                        scp914Roles.Add(Scp914PlayerUpgrade.ParseString(kvp.Key),
                                        (Scp914Knob)Enum.Parse(typeof(Scp914Knob), kvp.Value));
                    }

                    Info("Loaded " + configRoles.Count + "('s) custom 914 upgrade classes.");
                }
                catch (Exception e)
                {
                    Error($"Failed to parse 914 role upgrade settings. {e}");
                }



                Dictionary <string, string> configItems = KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_914_items", "Painkillers-Medkit:Fine,Coin-Flashlight:OneToOne"));

                try
                {
                    foreach (KeyValuePair <string, string> kvp in configItems)
                    {
                        scp914Items.Add(Scp914ItemUpgrade.ParseString(kvp.Key), (Scp914Knob)Enum.Parse(typeof(Scp914Knob), kvp.Value));
                    }

                    Info("Loaded " + configItems.Count + "('s) custom 914 recipes.");
                }
                catch (Exception e)
                {
                    Error("Failed to add items to 914. Check your 'util_914_items' config values for errors!\n" + e);
                }
            }

            bool enableCustomInv = Config.GetBool("util_enable_inventories", false);

            if (enableCustomInv)
            {
                // Custom items
                try
                {
                    Inventories               = new CustomInventory();
                    Inventories.ClassD        = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_classd_inventory", null)));
                    Inventories.Chaos         = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_chaos_inventory", null)));
                    Inventories.NtfCadet      = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfcadet_inventory", null)));
                    Inventories.NtfCommander  = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfcommander_inventory", null)));
                    Inventories.NtfLieutenant = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntflieutenant_inventory", null)));
                    Inventories.NtfScientist  = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfscientist_inventory", null)));
                    Inventories.Scientist     = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_scientist_inventory", null)));
                    Inventories.Guard         = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_guard_inventory", null)));
                    Info("Loaded Inventories.");
                }
                catch (Exception e)
                {
                    Error("Failed to add items to custom inventories! Check your inventory config values for errors!\n[EXCEPTION] For Developers:\n" + e);
                    return;
                }
            }

            bool upgradeHeldItems = Config.GetBool("util_914_upgrade_hand", true);

            bool enableBroadcasting = Config.GetBool("util_broadcast_enable", true);

            string broadcastMessage = Config.GetString("util_broadcast_message", "<color=lime>This server is running <b><color=red>EXILED-CommonUtils</color></b>, enjoy playing!</color>");

            int boradcastSeconds = Config.GetInt("util_broadcast_seconds", 300); // 300 is 5 minutes. :D
            int boradcastTime    = Config.GetInt("util_broadcast_time", 4);

            string joinMessage     = Config.GetString("util_joinMessage", "<color=lime>Welcome <b>%player%</b>! <i>Please read our rules!</i></color>");
            int    joinMessageTime = Config.GetInt("util_joinMessage_time", 6); // 6 seconds duhhhhh

            bool enableAutoNuke = Config.GetBool("util_enable_autonuke", false);

            int   autoNukeTime      = Config.GetInt("util_autonuke_time", 600); // 600 seconds is 10 minutes.
            bool  clearRagdolls     = Config.GetBool("util_cleanup_ragdolls", true);
            float clearRagdollTimer = Config.GetFloat("util_cleanup_interval", 250f);
            bool  clearOnlyPocket   = Config.GetBool("util_cleanup_only_pocket", false);
            bool  clearItems        = Config.GetBool("util_cleanup_items", true);

            EventHandler = new EventHandlers(upgradeHeldItems, scp914Roles, scp914Items, roleHealth, broadcastMessage, joinMessage, boradcastTime, boradcastSeconds, joinMessageTime, Inventories, autoNukeTime, enableAutoNuke, enable914Configs, enableBroadcasting, enableCustomInv, clearRagdolls, clearRagdollTimer, clearOnlyPocket, clearItems)
            {
                LockAutoNuke = Config.GetBool("util_autonuke_lock", false)
            };
            Events.PlayerJoinEvent        += EventHandler.PlayerJoin;
            Events.Scp914UpgradeEvent     += EventHandler.SCP914Upgrade;
            Events.RoundStartEvent        += EventHandler.RoundStart;
            Events.RoundEndEvent          += EventHandler.OnRoundEnd;
            Events.WaitingForPlayersEvent += EventHandler.OnWaitingForPlayers;

            Info("Common-Utils Loaded! Created by the EXILED Team.");

            if (!enableBroadcasting)
            {
                return;
            }

            cor = Timing.RunCoroutine(EventHandler.CustomBroadcast());
        }
Exemplo n.º 2
0
        public override void OnEnable()
        {
            if (!Config.GetBool("util_enable", true))
            {
                return;
            }

            Info("Loading Common-Utils, created by the EXILED Team!");

            Dictionary <string, string> configHealth = KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_role_health", "NtfCommander:400,NtfScientist:350"));

            try
            {
                foreach (KeyValuePair <string, string> kvp in configHealth)
                {
                    roleHealth.Add((RoleType)Enum.Parse(typeof(RoleType), kvp.Key), int.Parse(kvp.Value));
                }
            }
            catch (Exception e)
            {
                Error("Failed to add custom health to roles. Check your 'util_role_health' config values for errors!\n" + e);
                return;
            }

            Info("Loaded " + configHealth.Count() + "('s) default health classes.");

            Dictionary <string, string> configRoles =
                KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_914_roles", ""));

            try
            {
                foreach (KeyValuePair <string, string> kvp in configRoles)
                {
                    scp914Roles.Add(Scp914PlayerUpgrade.ParseString(kvp.Key), (Scp914Knob)Enum.Parse(typeof(Scp914Knob), kvp.Value));
                    Info($"Loaded {kvp.Key} - {kvp.Value} custom 914 upgrade");
                }
            }
            catch (Exception e)
            {
                Error($"Failed to parse 914 role upgrade settings. {e}");
                return;
            }

            Info("Loaded " + configRoles.Count + "('s) custom 914 upgrade classes.");

            Dictionary <string, string> configItems = KConf.ExiledConfiguration.GetDictonaryValue(Config.GetString("util_914_items", "Painkillers-Medkit:Fine,Coin-Flashlight:OneToOne"));

            try
            {
                foreach (KeyValuePair <string, string> kvp in configItems)
                {
                    scp914Items.Add(Scp914ItemUpgrade.ParseString(kvp.Key), (Scp914Knob)Enum.Parse(typeof(Scp914Knob), kvp.Value));
                }
            }
            catch (Exception e)
            {
                Error("Failed to add items to 914. Check your 'util_914_items' config values for errors!\n" + e);
                return;
            }

            Info("Loaded " + configItems.Count + "('s) custom 914 recipes.");

            // Custom items
            try
            {
                Inventories               = new CustomInventory();
                Inventories.ClassD        = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_classd_inventory", null)));
                Inventories.Chaos         = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_choas_inventory", null)));
                Inventories.NtfCadet      = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfcadet_inventory", null)));
                Inventories.NtfCommander  = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfcommander_inventory", null)));
                Inventories.NtfLieutenant = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntflieutenant_inventory", null)));
                Inventories.NtfScientist  = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_ntfscientist_inventory", null)));
                Inventories.Scientist     = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_scientist_inventory", null)));
                Inventories.Guard         = CustomInventory.ConvertToItemList(KConf.ExiledConfiguration.GetListStringValue(Config.GetString("util_guard_inventory", null)));
            }
            catch (Exception e)
            {
                Error("Failed to add items to custom inventorys!. Check your inventory config values for errors!\n[EXCEPTION] For Developers:\n" + e);
                return;
            }

            Info("Loaded Inventories.");

            bool upgradeHeldItems = Config.GetBool("util_914_upgrade_hand", true);

            string broadcastMessage = Config.GetString("util_broadcast_message", "<color=lime>This server is running <color=red>EXILED-CommonUtils</color>, enjoy playing!</color>");

            int boradcastSeconds = Config.GetInt("util_broadcast_seconds", 300); // 300 is 5 minutes. :D
            int boradcastTime    = Config.GetInt("util_broadcast_time", 4);

            string joinMessage     = Config.GetString("util_joinMessage", "<color=lime>Welcome %player%! Please read our rules!</color>");
            int    joinMessageTime = Config.GetInt("util_joinMessage_time", 6);

            EventHandler               = new EventHandlers(upgradeHeldItems, scp914Roles, scp914Items, roleHealth, broadcastMessage, joinMessage, boradcastTime, boradcastSeconds, joinMessageTime, Inventories);
            Events.PlayerJoinEvent    += EventHandler.PlayerJoin;
            Events.Scp914UpgradeEvent += EventHandler.SCP914Upgrade;
            Events.SetClassEvent      += EventHandler.SetClass;

            cor = Timing.RunCoroutine(EventHandler.CustomBroadcast());

            Info("Common-Utils Loaded! Created by the EXILED Team.");
        }