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

FREE RandomKits : 0.1.1 0.1.1

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

namespace Oxide.Plugins
{
     [Info("Random Kits", "bringer0death", "0.1.1")]
     [Description("Allows players to get random kits with cooldown features. Based off RandomWeaponKits by Orange who did the initial code")]
     public class RandomKits : RustPlugin
     {
         #region Vars

         private Dictionary<ulong, double> cooldowns = new Dictionary<ulong, double>();
         
         private const string permUse = "randomkits.use";
         private const string permCooldown = "randomkits.cooldown";

         #endregion

         #region Oxide Hooks

         private void Init()
         {
             permission.RegisterPermission(permUse, this);
             lang.RegisterMessages(EN, this);
         }

         [ChatCommand("random.kit")]
         private void Cmd(BasePlayer player)
         {
             Command(player);
         }

         #endregion
         
         #region Helpers

         private void Command(BasePlayer player)
         {
             if (!HasPerm(player, permUse))
             {
                 return;
             }

             var ignore = permission.UserHasPermission(player.UserIDString, permCooldown);
             
             if (!ignore && HasCooldown(player))
             {
                 return;
             }

             if (!ignore)
             {
                 cooldowns.Add(player.userID, Now());
             }
             
             var kit = config.list.GetRandom();
             var amount1 = Core.Random.Range(kit.minAmmo, kit.maxAmmo);
             var item1 = ItemManager.CreateByName(kit.weaponName);
             var item2 = ItemManager.CreateByName(kit.ammoName, amount1);
             var item3 = ItemManager.CreateByName(kit.item1Name);
             var item4 = ItemManager.CreateByName(kit.item2Name);
             var item5 = ItemManager.CreateByName(kit.item3Name);
             var item6 = ItemManager.CreateByName(kit.item4Name);
             var amount2 = Core.Random.Range(kit.minResource, kit.maxResource);
             var item7 = ItemManager.CreateByName(kit.resourceName, amount2);
             var amount3 = Core.Random.Range(kit.minFood, kit.maxFood);
             var item8 = ItemManager.CreateByName(kit.foodName, amount3);

             if (item1 != null)
             {
                 player.GiveItem(item1);
             }

             if (item2 != null)
             {
                 player.GiveItem(item2);
             }
             
             if (item3 != null)
             {
                 player.GiveItem(item3);
             }

             if (item4 != null)
             {
                 player.GiveItem(item4);
             }
             
             if (item5 != null)
             {
                 player.GiveItem(item5);
             }

             if (item6 != null)
             {
                 player.GiveItem(item6);
             }

             if (item7 != null)
             {
                 player.GiveItem(item7);
             }

             if (item8 != null)
             {
                 player.GiveItem(item8);
             }

             message(player, "Received");
         }

         private double Now()
         {
             return DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;
         }

         private int Passed(double a)
         {
             return Convert.ToInt32(Now() - a);
         }

         private bool HasCooldown(BasePlayer player)
         {
             var id = player.userID;
             if (!cooldowns.ContainsKey(id)) {return false;}
             var value = cooldowns[id];
             var passed = Passed(value);
             if (!(passed < config.cooldown))
             {
                 cooldowns.Remove(id);
                 return false;
             }
             message(player, "Cooldown", config.cooldown - passed);
             return true;
         }
         
         private bool HasPerm(BasePlayer player, string perm)
         {
             if (player == null) {return true;}

             if (permission.UserHasPermission(player.UserIDString, perm))
             {
                 return true;
             }

             message(player, "Permission");
             return false;
         }
         

         #endregion

         #region Localization

         private Dictionary<string, string> EN = new Dictionary<string, string>
         {
             {"Permission", "You don't have permission to use that command"},
             {"Cooldown", "You have cooldown {0} seconds"},
             {"Received", "You received a <color=#00FF00>Random Kit</color>!"}
         };

         private void message(BasePlayer player, string key, params object[] args)
         {
             var message = string.Format(lang.GetMessage(key, this, player.UserIDString), args);
             player.ChatMessage(message);
         }

         #endregion

         #region Configuration
         
         private ConfigData config;
        
         private class ConfigData
         {    
             [JsonProperty(PropertyName = "1. Command cooldown")]
             public float cooldown;
             
             [JsonProperty(PropertyName = "2. List of weapons")]
             public List<OWeapon> list;
             
             public class OWeapon
             {
                 [JsonProperty(PropertyName = "Item1 shortname")]
                 public string item1Name;

                 [JsonProperty(PropertyName = "Item2 shortname")]
                 public string item2Name;

                 [JsonProperty(PropertyName = "Item3 shortname")]
                 public string item3Name;

                 [JsonProperty(PropertyName = "Item4 shortname")]
                 public string item4Name;

                 [JsonProperty(PropertyName = "Weapon shortname")]
                 public string weaponName;
                 
                 [JsonProperty(PropertyName = "Ammo shortname")]
                 public string ammoName;
                 
                 [JsonProperty(PropertyName = "Minimal ammo that be given")]
                 public int minAmmo;
                 
                 [JsonProperty(PropertyName = "Maximal ammo that be given")]
                 public int maxAmmo;

                 [JsonProperty(PropertyName = "Resource shortname")]
                 public string resourceName;
                 
                 [JsonProperty(PropertyName = "Minimal resource that be given")]
                 public int minResource;
                 
                 [JsonProperty(PropertyName = "Maximal resource that be given")]
                 public int maxResource;

                 [JsonProperty(PropertyName = "Food shortname")]
                 public string foodName;
                 
                 [JsonProperty(PropertyName = "Minimal food that be given")]
                 public int minFood;
                 
                 [JsonProperty(PropertyName = "Maximal food that be given")]
                 public int maxFood;
             }
             
         }
        
         private ConfigData GetDefaultConfig()
         {
             return new ConfigData
             {
                 cooldown = 600,
                 list = new List<ConfigData.OWeapon>
                 {
                     new ConfigData.OWeapon
                     {
                         item1Name = "insert shortname",
                         item2Name = "insert shortname",
                         item3Name = "insert shortname",
                         item4Name = "insert shortname",
                         weaponName = "insert shortname",
                         ammoName = "insert shortname",
                         minAmmo = 10,
                         maxAmmo = 100,
                         resourceName = "insert shortname",
                         minResource = 10,
                         maxResource = 100,
                         foodName = "insert shortname",
                         minFood = 10,
                         maxFood = 100
                     },
                     new ConfigData.OWeapon
                     {
                         item1Name = "insert shortname",
                         item2Name = "insert shortname",
                         item3Name = "insert shortname",
                         item4Name = "insert shortname",
                         weaponName = "insert shortname",
                         ammoName = "insert shortname",
                         minAmmo = 10,
                         maxAmmo = 100,
                         resourceName = "insert shortname",
                         minResource = 10,
                         maxResource = 100,
                         foodName = "insert shortname",
                         minFood = 10,
                         maxFood = 100
                     },
                     new ConfigData.OWeapon
                     {
                         item1Name = "insert shortname",
                         item2Name = "insert shortname",
                         item3Name = "insert shortname",
                         item4Name = "insert shortname",
                         weaponName = "insert shortname",
                         ammoName = "insert shortname",
                         minAmmo = 10,
                         maxAmmo = 100,
                         resourceName = "insert shortname",
                         minResource = 10,
                         maxResource = 100,
                         foodName = "insert shortname",
                         minFood = 10,
                         maxFood = 100
                     },
                     new ConfigData.OWeapon
                     {
                         item1Name = "insert shortname",
                         item2Name = "insert shortname",
                         item3Name = "insert shortname",
                         item4Name = "insert shortname",
                         weaponName = "insert shortname",
                         ammoName = "insert shortname",
                         minAmmo = 10,
                         maxAmmo = 100,
                         resourceName = "insert shortname",
                         minResource = 10,
                         maxResource = 100,
                         foodName = "insert shortname",
                         minFood = 10,
                         maxFood = 100
                     }
                 }
             };
         }
        
         protected override void LoadConfig()
         {
             base.LoadConfig();
   
             try
             {
                 config = Config.ReadObject<ConfigData>();
             }
             catch
             {
                 LoadDefaultConfig();
             }

             SaveConfig();
         }

         protected override void LoadDefaultConfig()
         {
             PrintError("Configuration file is corrupt(or not exists), creating new one!");
             config = GetDefaultConfig();
         }

         protected override void SaveConfig()
         {
             Config.WriteObject(config);
         }

         #endregion
     }
}

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