Иконка ресурса

FREE Eggs : 1.1.6 1.1.6

Нет прав для скачивания
C#:
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using UnityEngine;
using Oxide.Core;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Facepunch;
using Rust;

#region Changelogs and ToDo
/**********************************************************************
* 
* 1.0.0 :       -   Initial release
* 1.1.0 :       -   patch & Randomising egg injection
* 1.1.1 :       -   Added config settings for egg randomiser
*               -   Added a gathermultiplier block for eggs (1) to cancel multipliers from Gathermanaer and Zlevels)
* 1.1.2 :       -   Patched to make sure 1st egg is chosen if multiple eggs where triggered
* 1.1.3 :       -   Recalculated the hard limit of 1 egg on gathering
* 1.1.4 :       -   Fix for egg sequence giving diffrent eggs
* 1.1.5 :       -   Patched for double codeing to fix Gold egg issue
* 1.1.6 :       -   Reformatted position of egg cap limiting (timing)
*               -   Default eggs now displays egg types instead of shortname in chat
*               -   Added support for custom egg naming through cfg
                -   Added Eggnames to language file for messages
*               -   Added Egg amount limits per type through cfg
*                              
**********************************************************************/
#endregion

namespace Oxide.Plugins
{
    [Info("Eggs", "Krungh Crow", "1.1.6")]
    [Description("Harvest eggs from chickens to upgrade")]

    class Eggs : RustPlugin
    {
        #region Variables
        const string Chat_Perm = "eggs.chat";

        ulong chaticon = 0;
        string prefix;
        bool Debug = false;
        bool ShowMsg = true;

        string RandomEgg;
        string EggName;
        bool EggSucces;

        #endregion

        #region Configuration
        void Init()
        {
            if (!LoadConfigVariables())
            {
            Puts("Config file issue detected. Please delete file, or check syntax and fix.");
            return;
            }

            permission.RegisterPermission(Chat_Perm, this);

            Debug = configData.PlugCFG.Debug;
            ShowMsg = configData.PlugCFG.Msg;
            prefix = "[<color=yellow>Eggs</color>] : ";
            if (Debug) Puts($"[Debug] Debug is activated if unintentional disable this in the config !");
        }

        private ConfigData configData;

        class ConfigData
        {
            [JsonProperty(PropertyName = "Main config")]
            public SettingsPlugin PlugCFG = new SettingsPlugin();
            [JsonProperty(PropertyName = "Egg injection Settings")]
            public EggSettings EggCFG = new EggSettings();
            [JsonProperty(PropertyName = "Max eggs when using multiplier plugins")]
            public Multipliers EggMax = new Multipliers();
            [JsonProperty(PropertyName = "Custom egg names (suggest to keep default)")]
            public CustomNames EggNaming = new CustomNames();
        }

        class SettingsPlugin
        {
            [JsonProperty(PropertyName = "Debug")]
            public bool Debug = false;
            [JsonProperty(PropertyName = "Show Chat messages")]
            public bool Msg = true;
        }

        class EggSettings
        {
            [JsonProperty(PropertyName = "Chance on Egg Injection (0-100)")]
            public float RandomEgg = 50f;
            [JsonProperty(PropertyName = "Chance on Regular Egg (0-100)")]
            public float RandomEggRegular = 60f;
            [JsonProperty(PropertyName = "Chance on Bronze Egg (0-100)")]
            public float RandomEggBronze = 30f;
            [JsonProperty(PropertyName = "Chance on Silver Egg (0-100)")]
            public float RandomEggSilver = 20f;
            [JsonProperty(PropertyName = "Chance on Golden Egg (0-100)")]
            public float RandomEggGold = 10f;
            [JsonProperty(PropertyName = "Default Egg")]
            public string DefaultEgg = "easter.paintedeggs";
        }

        class Multipliers
        {
            [JsonProperty(PropertyName = "Max Regular Eggs")]
            public int MaxRegular = 1;
            [JsonProperty(PropertyName = "Max Bronze Eggs")]
            public int MaxBronze = 1;
            [JsonProperty(PropertyName = "Max Silver Eggs")]
            public int MaxSilver = 1;
            [JsonProperty(PropertyName = "Max Golden Eggs")]
            public int MaxGolden = 1;
        }

        class CustomNames
        {
            [JsonProperty(PropertyName = "Regular egg")]
            public string NameRegular = "EGG";
            [JsonProperty(PropertyName = "Bronze egg")]
            public string NameBronze = "BRONZE EGG";
            [JsonProperty(PropertyName = "Silver egg")]
            public string NameSilver = "SILVER EGG";
            [JsonProperty(PropertyName = "Gold egg")]
            public string NameGold = "GOLD EGG";
        }

        private bool LoadConfigVariables()
        {
            try
            {
            configData = Config.ReadObject<ConfigData>();
            }
            catch
            {
            return false;
            }
            SaveConf();
            return true;
        }

        protected override void LoadDefaultConfig()
        {
            Puts("Fresh install detected Creating a new config file.");
            configData = new ConfigData();
            SaveConf();
        }

        void SaveConf() => Config.WriteObject(configData, true);
        #endregion

        #region LanguageAPI
        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["EggRegular"] = "Egg",
                ["EggBronze"] = "Bronze EGG",
                ["EggSilver"] = "Silver EGG",
                ["EggGold"] = "Gold EGG",
                ["Info"] = "\n<color=green>Available Commands</color>\n<color=green>/egg info</color> : Shows info on version/author and commands",
                ["InvalidInput"] = "<color=red>Please enter a valid command!</color>",
                ["FoundEgg"] = "You found a <color=#4A95CC>{0}</color>",
                ["Version"] = "Version : V",
                ["NoPermission"] = "<color=green>You do not have permission to use that command!</color>",
            }, this);
        }

        #endregion

        #region Commands

        [ChatCommand("egg")]
        private void cmdPrimary(BasePlayer player, string command, string[] args)
        {
            if (!permission.UserHasPermission(player.UserIDString, Chat_Perm))
            {
                Player.Message(player, prefix + string.Format(msg("NoPermission", player.UserIDString)), chaticon);
                if (Debug) Puts($"[Debug] {player} had no permission for using Commands");
                return;
            }

            if (args.Length == 0)
            {
                Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon);
            }
            else
            {
                if (args[0].ToLower() == "info")
                {
                    Player.Message(player, prefix + string.Format(msg("Version", player.UserIDString)) + this.Version.ToString() + " By : " + this.Author.ToString()
                    + msg("Info")
                    , chaticon);
                    return;
                }
                else
                {
                    Player.Message(player, prefix + string.Format(msg("InvalidInput", player.UserIDString)), chaticon);
                }

            }
        }
        #endregion

        #region Hooks

        #region Egg injection
        void OnEntitySpawned(BaseCorpse corpse)
        {
            var dispenser = corpse.GetComponent<ResourceDispenser>();
            if (dispenser != null && dispenser.ToString().Contains("chicken.corpse") && (UnityEngine.Random.Range(0f, 1f) <= configData.EggCFG.RandomEgg / 100))
            {
                EggSucces = false;
                if (UnityEngine.Random.Range(0f, 1f) <= configData.EggCFG.RandomEggGold / 100)
                {
                    RandomEgg = "easter.goldegg";
                    EggName = lang.GetMessage("EggGold", this);
                    EggSucces = true;
                }
                else if (UnityEngine.Random.Range(0f, 1f) <= configData.EggCFG.RandomEggSilver / 100)
                {
                    RandomEgg = "easter.silveregg";
                    EggName = lang.GetMessage("EggSilver", this);
                    EggSucces = true;
                }
                else if (UnityEngine.Random.Range(0f, 1f) <= configData.EggCFG.RandomEggBronze / 100)
                {
                    RandomEgg = "easter.bronzeegg";
                    EggName = lang.GetMessage("EggBronze", this);
                    EggSucces = true;
                }
                else if (UnityEngine.Random.Range(0f, 1f) <= configData.EggCFG.RandomEggRegular / 100)
                {
                    RandomEgg = "easter.paintedeggs";
                    EggName = lang.GetMessage("EggRegular", this);
                    EggSucces = true;
                }
                else if(!EggSucces)
                {
                    RandomEgg = configData.EggCFG.DefaultEgg;
                    if (RandomEgg.Contains("easter.paintedeggs"))
                    {
                        EggName = lang.GetMessage("EggRegular", this);
                    }
                    if (RandomEgg.Contains("easter.bronzeegg"))
                    {
                        EggName = lang.GetMessage("EggBronze", this);
                    }
                    if (RandomEgg.Contains("easter.silveregg"))
                    {
                        EggName = lang.GetMessage("EggSilver", this);
                    }
                    if (RandomEgg.Contains("easter.goldegg"))
                    {
                        EggName = lang.GetMessage("EggGold", this);
                    }
                    if (Debug) Puts($"{corpse} was injected with a [{EggName}] (EggSucces was false)");
                }

                Item egg = ItemManager.CreateByName(RandomEgg, 1, 0);
                ItemAmount EggInfo = new ItemAmount() { itemDef = egg.info, amount = 1, startAmount = 1 };
                dispenser.containedItems.Add(EggInfo);
                dispenser.Initialize();
                if (Debug) Puts($"{corpse} was injected with a [{EggName}]");
                return;
            }
            return;
        }
        #endregion

        #region egg skin handling - messages - egg limit
        void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) //dispencer = resourcedispenser | entity is player | item is items harvested
        {
            BasePlayer player = entity.ToPlayer();
            if (player == null || dispenser == null || entity == null || item == null) return;

            if (dispenser.ToString().Contains("chicken.corpse"))
            {
                if (item.info.itemid == -126305173)//easter.paintedeggs	
                {
                    item.name = configData.EggNaming.NameRegular;
                    item.skin = 2588614999UL;//Egg
                    item.MarkDirty();
                    if (ShowMsg) Player.Message(player, prefix + string.Format(msg("FoundEgg", player.UserIDString), EggName), chaticon);
                    EggName = lang.GetMessage("EggRegular", this);

                    if (item.amount > configData.EggMax.MaxRegular)
                    {
                        if (Debug) Puts($"[{item.amount} {EggName}(s)] was reduced to {configData.EggMax.MaxRegular}");
                        item.UseItem(item.amount - configData.EggMax.MaxRegular);
                    }
                }
                else if (item.info.itemid == 844440409)//Bronze Egg
                {
                    item.name = configData.EggNaming.NameBronze;
                    item.MarkDirty();
                    EggName = lang.GetMessage("EggBronze", this);

                    if (ShowMsg) Player.Message(player, prefix + string.Format(msg("FoundEgg", player.UserIDString), EggName), chaticon);
                    if (item.amount > configData.EggMax.MaxBronze)
                    {
                        if (Debug) Puts($"[{item.amount} {EggName}(s)] was reduced to {configData.EggMax.MaxBronze}");
                        item.UseItem(item.amount - configData.EggMax.MaxBronze);
                    }
                }
                else if (item.info.itemid == 1757265204)//Silver Egg
                {
                    item.name = configData.EggNaming.NameSilver;
                    item.MarkDirty();
                    EggName = lang.GetMessage("EggSilver", this);
                    if (ShowMsg) Player.Message(player, prefix + string.Format(msg("FoundEgg", player.UserIDString), EggName), chaticon);
                    if (item.amount > configData.EggMax.MaxSilver)
                    {
                        if (Debug) Puts($"[{item.amount} {EggName}(s)] was reduced to {configData.EggMax.MaxSilver}");
                        item.UseItem(item.amount - configData.EggMax.MaxSilver);
                    }
                }
                else if (item.info.itemid == -1002156085)//Gold Egg
                {
                    item.name = configData.EggNaming.NameGold;
                    item.MarkDirty();
                    EggName = lang.GetMessage("EggGold", this);
                    if (ShowMsg) Player.Message(player, prefix + string.Format(msg("FoundEgg", player.UserIDString), EggName), chaticon);
                    if (item.amount > configData.EggMax.MaxGolden)
                    {
                        if (Debug) Puts($"[{item.amount} {EggName}(s)] was reduced to {configData.EggMax.MaxGolden}");
                        item.UseItem(item.amount - configData.EggMax.MaxGolden);
                    }
                }
            }   
            return;
        }
        #endregion

        #endregion

        #region Message helper

        private string msg(string key, string id = null) => lang.GetMessage(key, this, id);

        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху