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

FREE StationaryPaper : 1.1.1 1.1.1

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

namespace Oxide.Plugins
{
    [Info("Stationary Paper" , "Krungh Crow" , "1.1.1")]
    [Description("Craft stationery paper notes")]
    class StationaryPaper : RustPlugin
    {
        #region Variables

        const string Admin_Perm = "stationarypaper.admin";
        const string NormalCost_Perm = "stationarypaper.normal";

        ulong chaticon = 76561199180049293;
        string FortuneMsg;
        string prefix;
        bool Debug = false;
        bool ActiveTip = false;

        #endregion

        #region Configuration

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

            permission.RegisterPermission(Admin_Perm , this);
            permission.RegisterPermission(NormalCost_Perm , this);

            Debug = configData.PlugCFG.Debug;
            prefix = configData.PlugCFG.Prefix;

            if (Debug)
            {
                Puts("[Debug] trigger for Debug is true");
            }
        }

        private ConfigData configData;

        class ConfigData
        {
            [JsonProperty(PropertyName = "Main config")]
            public SettingsPlugin PlugCFG = new SettingsPlugin();

            [JsonProperty(PropertyName = "Crafting Costs")]
            public SettingsCosts CostsCFG = new SettingsCosts();
        }

        class SettingsPlugin
        {
            [JsonProperty(PropertyName = "Debug")]
            public bool Debug = false;

            [JsonProperty(PropertyName = "Chat Prefix")]
            public string Prefix = "[<color=purple>Stationary Paper</color>] ";
        }

        class SettingsCosts
        {
            [JsonProperty(PropertyName = "Wood ammount")]
            public int CraftCost = 100;
        }

        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>
            {
                ["NoteCrafted"] = "You succesfully crafted a <color=orange>{0}</color>" ,
                ["Info"] = "\n<color=green>Available Commands</color> :\n<color=orange>/note info</color> : Shows info on version/author and commands" ,
                ["InfoAdmin"] = "<color=orange>/note admin</color> : Crafts a Admin Note" ,
                ["InfoBomb"] = "<color=orange>/note bomb</color> : Crafts a Bomb letter (does not explode)" ,
                ["InfoCrow"] = "<color=orange>/note crow</color> : Crafts a Crow Note" ,
                ["InfoInfo"] = "<color=orange>/note information</color> : Crafts a Info Note" ,
                ["InfoLove"] = "<color=orange>/note love</color> : Crafts a Love Letter" ,
                ["InvalidInput"] = "Please enter a valid command!" ,
                ["InventoryFull"] = "You need at least 1 more slot in your inventory,canceling the craft" ,
                ["Version"] = "Version : V" ,
                ["NoPermission"] = "You do not have permission to use that command!" ,
            } , this);
        }

        #endregion

        #region Commands

        [ChatCommand("Note")]
        private void cmdNote(BasePlayer player , string command , string[] args)
        {
            if (args.Length == 0)
            {
                Player.Message(player , prefix + string.Format(msg("InvalidInput" , player.UserIDString)) , chaticon);
                return;
            }

            string subCommand = args[0].ToLower();

            if (subCommand == "info")
            {
                Player.Message(player ,
                    prefix + string.Format(msg("Version" , player.UserIDString)) + Version + " By : " + Author
                    + msg("Info")
                    + "\n" + msg("InfoAdmin")
                    + "\n" + msg("InfoBomb")
                    + "\n" + msg("InfoCrow")
                    + "\n" + msg("InfoInfo")
                    + "\n" + msg("InfoLove") ,
                    chaticon);
                return;
            }

            if (subCommand == "admin")
            {
                if (!HasPerm(player , Admin_Perm))
                {
                    Player.Message(player , prefix + string.Format(msg("NoPermission" , player.UserIDString)) , chaticon);

                    if (Debug)
                    {
                        Puts($"[Debug] {player} had no permission for using Commands");
                    }

                    return;
                }

                CraftNote(player , "Admin Note" , 2514975127UL);
                return;
            }

            if (subCommand == "bomb")
            {
                CraftNoteBomb(player);
                return;
            }

            if (subCommand == "crow")
            {
                CraftNoteCrow(player);
                return;
            }

            if (subCommand == "information")
            {
                CraftNoteInfo(player);
                return;
            }

            if (subCommand == "love")
            {
                CraftNoteLove(player);
                return;
            }

            Player.Message(player , prefix + string.Format(msg("InvalidInput" , player.UserIDString)) , chaticon);
        }

        #endregion

        #region Hooks

        [ConsoleCommand("note.update")]
        void OnNoteEdit(ConsoleSystem.Arg arg)
        {
            try
            {
                BasePlayer editor = arg.Player();

                if (editor == null || arg.Args == null || arg.Args.Length < 2)
                {
                    return;
                }

                ulong id = arg.GetULong(0);
                Item item = editor.inventory.FindItemByUID(new ItemId(id));

                if (item == null)
                {
                    return;
                }

                string TextCheck = item.text ?? "";
                string newText = arg.Args[1].ToString();

                bool PaperNoteEdit = editor.IPlayer.HasPermission(Admin_Perm) || editor.IsAdmin || editor.IsDeveloper;
                bool canWrite = string.IsNullOrEmpty(TextCheck);

                if (item.info.itemid == 62577426)
                {
                    item.text = newText;

                    if (Debug)
                    {
                        Puts($"photo written/edited by : {editor} text = {newText}");
                    }
                }

                if (item.info.itemid == 946662961 || item.name.Contains("Car Key"))
                {
                    item.text = newText;

                    if (Debug)
                    {
                        Puts($"car.key written/edited/clicked on by : {editor} text = {newText}");
                    }
                }

                if (item.name.Contains("Admin Note") && PaperNoteEdit)
                {
                    item.text = newText;

                    if (Debug)
                    {
                        Puts($"Admin note written/edited/clicked on by : {editor} text = {newText}");
                    }
                }

                if (item.name.Contains("Simple Note") || item.name.Contains("Bomb Note") || item.name.Contains("Crows Note") || item.name.Contains("Info Note") || item.name.Contains("Love Letter") || canWrite)
                {
                    if (Debug)
                    {
                        Puts($"{item.name} note written/edited by : {editor} text = {newText}");
                    }

                    item.text = newText;
                }

                item.MarkDirty();
            }
            catch
            {
            }
        }

        void OnItemCraftFinished(ItemCraftTask task , Item item)
        {
            if (item.info.itemid == 1414245162)
            {
                item.skin = 2515255356UL;
                item.name = "Simple Note";
                item.MarkDirty();
            }
        }

        public void ItemRemove(BasePlayer player , int itemid , int amount)
        {
            List<Item> items = player.inventory.containerMain.itemList;

            int Amounts = 0;
            int Remaining = amount;

            for (int i = 0; i < items.Count; i++)
            {
                Item item = items[i];

                if (item == null || item.info.itemid != itemid)
                {
                    continue;
                }

                Amounts = Remaining;

                if (item.amount < Amounts)
                {
                    Amounts = item.amount;
                }

                if (item.amount > Amounts)
                {
                    item.SplitItem(Amounts);
                }
                else
                {
                    item.UseItem(Amounts);
                }

                Remaining = Remaining - Amounts;

                if (Remaining <= 0)
                {
                    break;
                }
            }
        }

        #endregion

        #region Core

        private void CraftNote(BasePlayer player , string name , ulong skinid)
        {
            Item PaperNote = ItemManager.CreateByName("note" , 1 , skinid);

            if (PaperNote != null)
            {
                PaperNote.name = name;
                PaperNote.info.stackable = 1;
                PaperNote.MarkDirty();
                PaperNote.MoveToContainer(player.inventory.containerMain);

                Player.Message(player , prefix + string.Format(msg("NoteCrafted" , player.UserIDString) , PaperNote.name) , chaticon);
                return;
            }

            Player.Message(player , prefix + string.Format(msg("Something went wrong" , player.UserIDString)) , chaticon);
        }

        private void CraftNoteBomb(BasePlayer player)
        {
            int Cost = configData.CostsCFG.CraftCost;

            if (HasPerm(player , NormalCost_Perm))
            {
                Cost = 10;
            }

            if (CheckWood(player , Cost))
            {
                CraftNote(player , "Bomb Note" , 2514978449UL);
                ItemRemove(player , -151838493 , Cost);
                TIP(player , $"<color=red>-{Cost} wood</color>" , 5f);
            }
        }

        private void CraftNoteCrow(BasePlayer player)
        {
            int Cost = configData.CostsCFG.CraftCost;

            if (HasPerm(player , NormalCost_Perm))
            {
                Cost = 10;
            }

            if (CheckWood(player , Cost))
            {
                CraftNote(player , "Crows Note" , 2514997813UL);
                ItemRemove(player , -151838493 , Cost);
                TIP(player , $"<color=red>-{Cost} wood</color>" , 5f);
            }
        }

        private void CraftNoteInfo(BasePlayer player)
        {
            int Cost = configData.CostsCFG.CraftCost;

            if (HasPerm(player , NormalCost_Perm))
            {
                Cost = 10;
            }

            if (CheckWood(player , Cost))
            {
                CraftNote(player , "Info Note" , 2514986521UL);
                ItemRemove(player , -151838493 , Cost);
                TIP(player , $"<color=red>-{Cost} wood</color>" , 5f);
            }
        }

        private void CraftNoteLove(BasePlayer player)
        {
            int Cost = configData.CostsCFG.CraftCost;

            if (HasPerm(player , NormalCost_Perm))
            {
                Cost = 10;
            }

            if (CheckWood(player , Cost))
            {
                CraftNote(player , "Love Letter" , 2514963840UL);
                ItemRemove(player , -151838493 , Cost);
                TIP(player , $"<color=red>-{Cost} wood</color>" , 5f);
            }
        }

        private bool CheckWood(BasePlayer player , int Cost)
        {
            int woodAmount = player.inventory.GetAmount(-151838493);

            if (woodAmount >= Cost && !player.inventory.containerMain.IsFull())
            {
                if (Debug)
                {
                    Puts($"{player} has enough wood and/or inventory space");
                }

                return true;
            }

            if (player.inventory.containerMain.IsFull())
            {
                if (Debug)
                {
                    Puts($"{player} has no inventory space");
                }

                Player.Message(player , prefix + string.Format(msg("InventoryFull" , player.UserIDString)) , chaticon);
                return false;
            }

            if (Debug)
            {
                Puts($"{player} was {Cost - woodAmount} Wood short");
            }

            Player.Message(player , prefix + $"you are {Cost - woodAmount} Wood short" , chaticon);
            return false;
        }

        #endregion

        #region Message helpers

        private string msg(string key , string id = null)
        {
            return lang.GetMessage(key , this , id);
        }

        void TIP(BasePlayer player , string message , float dur)
        {
            if (player == null)
            {
                return;
            }

            if (!ActiveTip)
            {
                player.SendConsoleCommand("gametip.hidegametip");
                player.SendConsoleCommand("gametip.showgametip" , message);

                ActiveTip = true;

                timer.Once(dur , () =>
                {
                    if (player != null)
                    {
                        player.SendConsoleCommand("gametip.hidegametip");
                    }

                    ActiveTip = false;
                });
            }
            else
            {
                timer.Once(1f , () =>
                {
                    Puts("Check frequency 1 sec");
                    TIP(player , message , dur);
                });
            }
        }

        bool HasPerm(BasePlayer player , string perm)
        {
            return permission.UserHasPermission(player.UserIDString , perm);
        }

        #endregion
    }
}

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