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

FREE GoldCard : 1.0.4 1.0.4

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

namespace Oxide.Plugins
{
    [Info("GoldCard", "https://topplugin.ru/", "1.0.4")]
    [Description("Чёткий плагин")]
    class GoldCard : RustPlugin
    {
        #region Vars
        string Shortname = "keycard_red";
        #endregion

        #region Reference
        [PluginReference] Plugin IQChat;
        #endregion

        #region Configuration

        private static Configuration config = new Configuration();
        private class Configuration
        {
            [JsonProperty("SkinID для предмета")]
            public ulong SkinID;
            [JsonProperty("DisplayName для предмета")]
            public string DisplayName;
            [JsonProperty("Количество использований по умолчанию")]
            public int UseCount;
            [JsonProperty("Персональные настройки")]
            public Dictionary <string, int> Perms;
			
			
            public static Configuration GetNewConfiguration()
            {
                return new Configuration
                {
                    SkinID = 1977450795,
                    DisplayName = "Карта общего доступа",
					UseCount=3,
					Perms = new Dictionary <string, int>{
						{"goldcard.elite",7},
						{"goldcard.vip",5}
					}
                };
            }
        }

		public int GetPlayerCount(BasePlayer player){
			if (config.Perms!=null) { 
				foreach(KeyValuePair<string,int> p in config.Perms){
					if (permission.UserHasPermission(player.UserIDString, p.Key)) return p.Value;
				}
			}
			return config.UseCount;
		}
        private void Init()
        {
			if (config!=null){
				if (config.Perms!=null){
					foreach(string p in config.Perms.Keys) permission.RegisterPermission(p, this);					
				}
			}
		}
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                config = Config.ReadObject<Configuration>();
                if (config == null) LoadDefaultConfig();
            }
            catch
            {
                PrintWarning("Ошибка #1" + $"чтения конфигурации 'oxide/config/{Name}', создаём новую конфигурацию!!");
                LoadDefaultConfig();
            }
            NextTick(SaveConfig);
        }

        protected override void LoadDefaultConfig() => config = Configuration.GetNewConfiguration();
        protected override void SaveConfig() => Config.WriteObject(config);

        #endregion

        #region Metods
        void CreateItem(BasePlayer player)
        {
            Item item = ItemManager.CreateByName(Shortname, 1, config.SkinID);
            item.name = config.DisplayName;
			int cond = GetPlayerCount(player);
			Puts(cond.ToString());
			if (cond<1) cond=2;
			item._maxCondition = cond;
			item._condition = cond;
            player.GiveItem(item);
        }

        public void SendChat(string Message, BasePlayer player, Chat.ChatChannel channel = Chat.ChatChannel.Global)
        {
            if (IQChat)
                IQChat?.Call("API_ALERT_PLAYER", player, Message, "");
            else player.SendConsoleCommand("chat.add", channel, 0, Message);
        }
        #endregion

        #region Hooks

        private Item OnItemSplit(Item item, int amount)
        {
            if (plugins.Find("Stacks") || plugins.Find("CustomSkinsStacksFix") || plugins.Find("SkinBox")) return null;
            if (item.skin == config.SkinID)
            {
                Item x = ItemManager.CreateByPartialName(Shortname, amount);
                x.name = config.DisplayName;
                x.skin = config.SkinID;
                x.amount = amount;
                item.amount -= amount;
                return x;
            }
            return null;
        }

        object CanCombineDroppedItem(DroppedItem item, DroppedItem targetItem)
        {
            if (item.GetItem().skin != targetItem.GetItem().skin) return false;
            return null;
        }
        object CanStackItem(Item item, Item targetItem)
        {
            if (item.skin != targetItem.skin) return false;
            return null;
        }

        private object OnCardSwipe(CardReader cardReader, Keycard card, BasePlayer player)
        {
			if (card.skinID != config.SkinID) return null;
			Item obj = card.GetItem();
			if (obj == null) return null;
            if (card.accessLevel != cardReader.accessLevel && card.skinID == config.SkinID)
			{
                cardReader.GrantCard();
				obj._condition--;
				if (obj._condition==0) NextTick(() => obj.Remove(0.0f));
				obj.MarkDirty();
                SendChat("Вы успешно получили доступ к двери", player);
                return true;
            }
            return null;
        }

        #endregion

        #region Commands
        [ConsoleCommand("card")]
        void CardCommand(ConsoleSystem.Arg arg)
        {
            BasePlayer player = BasePlayer.FindByID(ulong.Parse(arg.Args[0]));
            if (player == null) return;
            CreateItem(player);
            SendChat($"Вы успешно получили {config.DisplayName}", player);
            Puts($"Игроку {player.displayName} успешно выдана карта!");
        }
        #endregion
    }
}

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

Другие ресурсы пользователя 15FPS

Сверху