using System; using System.Linq; using System.Collections.Generic; using Oxide.Core.Libraries.Covalence; using Newtonsoft.Json; using Oxide.Game.Rust.Libraries; using UnityEngine; namespace Oxide.Plugins { [Info("CKit", "Crazy", 3.0)] [Description("Give Kit")] class CKit : RustPlugin { #region CONFIG #region GENERAL private cConfig c; private class cConfig { [JsonProperty("KITS")] public List kit; public class KitList { [JsonProperty("1. Name")] public string name; [JsonProperty("2. Chat Command")] public string command; [JsonProperty("3. Short Desc")] public string description; [JsonProperty("4. Oxide group or permission")] public string groupe; [JsonProperty("5. Kit default")] public bool isDefault; [JsonProperty("6. Kit active")] public bool isActive; [JsonProperty("7. Start")] public List start; [JsonProperty("8. End")] public List end; [JsonProperty("9. Belt")] public List belt; [JsonProperty("10. Main")] public List main; [JsonProperty("11. Wear")] public List wear; } public static cConfig GetDefaultConfig() { return new cConfig { kit = new List { new KitList { name = "Default", command = null, description = "Kits give when a player respawn", groupe = null, isDefault = true, isActive = true, start = new List { }, end = new List { }, belt = new List { new KInventory { shortName = "rock", skin = 804791902, amount = 1, condition = 100, ammo = 0, ammotype = null, instanceData = null, contents = null }, new KInventory { shortName = "torch", skin = 0, amount = 1, condition = 50, ammo = 0, ammotype = null, instanceData = null, contents = null } }, main = new List { }, wear = new List { new KInventory { shortName = "tshirt", skin = 0, amount = 1, condition = 0, ammo = 0, ammotype = null, instanceData = null, contents = null } } } } }; } } #endregion #region OBJECT public class KInventory { [JsonProperty("SHORT NAME")] public string shortName; [JsonProperty("SKIN ID")] public ulong skin; [JsonProperty("AMOUNT")] public int amount; [JsonProperty("CONDITION")] public float condition; [JsonProperty("AMMO")] public int ammo; [JsonProperty("AMMO TYPE")] public string ammotype; [JsonProperty("INSTANCE DATA")] public ProtoBuf.Item.InstanceData instanceData; [JsonProperty("CONTENTS")] public KInventory[] contents; } public class DateList { [JsonProperty("DAY")] public string day; [JsonProperty("MONTH")] public string month; [JsonProperty("YEAR")] public string year; [JsonProperty("TIME / H24 / 08:00")] public string time; } #endregion #region LOAD / SAVE protected override void LoadConfig() { base.LoadConfig(); c = Config.ReadObject(); } protected override void LoadDefaultConfig() => c = cConfig.GetDefaultConfig(); protected override void SaveConfig() => Config.WriteObject(c); #endregion #endregion #region DICTIONARY public Dictionary Lang = new Dictionary{ {"SyntaxError", "Syntax error : /kit "}, {"SyntaxClearError", "Syntax error :

" +"/clear all : Delete all inventories
" +"/clear main : Delete main inventory
" +"/clear wear : Delete the clothing inventory
" +"/clear belt : Delete quick Inventorye"}, {"NotExist", "Kit {name} does not exists"}, {"IsInactive", "The kit is currently inactive"}, {"NotPerm", "You do not have the required permissions"}, {"NotStart", "The kit {name} is currently not activated. It will be activated on the {start}"}, {"IsEnd", "The kit {name} is no longer available"}, }; #endregion #region MESSAGE private void MessageReply(IPlayer player, string m) => player.Reply("SERVER : " + m + ""); private void Message(string m) => Server.Command("say " + m); private string Translate(string msg, Dictionary parameters = null) { if (string.IsNullOrEmpty(msg)) return string.Empty; if (parameters != null) { foreach (var lekey in parameters) { if (msg.Contains("{" + lekey.Key + "}")) msg = msg.Replace("{" + lekey.Key + "}", lekey.Value); } } return msg; } #endregion #region SERVER private void OnPlayerRespawned(BasePlayer player) { LoadConfig(); var def = GetKitDefaultName(); if (def == null) return; GiveKits(player, def); } #endregion #region EFFECT private void SendEffect(BasePlayer player, string sound) { var effect = new Effect(sound, player, 0, Vector3.zero, Vector3.forward); EffectNetwork.Send(effect, player.net.connection); } #endregion #region FUNCTIONS public bool CheckKitExist(string args) => c.kit.Any(x => x.name == args); public bool CheckKitActive(string args) => c.kit.Single(x => x.command == args).isActive; public bool CheckKitState(string state, string args) { string[] ret = GetKitDate(state, args); if (ret.Count() == 0) return true; string date = $"{ret[0]}/{ret[1]}/{ret[2]} {ret[3]}"; if (state == "start") { if (DateTime.ParseExact(date, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture) <= DateTime.Now) return true; } if (state == "end") { if (DateTime.ParseExact(date, "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture) >= DateTime.Now) return true; } return false; } public bool CheckHasPerms(BasePlayer player, string args) => c.kit.Single(x => x.command == args).groupe == null ? true : permission.UserHasGroup(player.IPlayer.Id, c.kit.Single(x => x.command == args).groupe); public bool CheckCommandExist(string args) => c.kit.Any(x => x.command == args); public string GetKitDefaultName() { if (!c.kit.Any(x => x.isDefault)) return null; return c.kit.Single(x => x.isDefault).name; } public string GetKitName(string args) => c.kit.Single(x => x.command == args).name; private string[] GetKitDate(string state, string args) { string[] ret = new string[] {}; switch (state) { case "start": try { var cmd = c.kit.Single(x => x.command == args); var d = cmd.start[0].day; var m = cmd.start[0].month; var y = cmd.start[0].year; var t = cmd.start[0].time; ret = new string[] { d, m, y, t }; return ret; } catch { return ret; } case "end": try { var cmd = c.kit.Single(x => x.command == args); var d = cmd.end[0].day; var m = cmd.end[0].month; var y = cmd.end[0].year; var t = cmd.end[0].time; ret = new string[] { d, m, y, t }; return ret; } catch { return ret; } default: return ret; } } #endregion #region GIVE public enum InventoryType { main, wear, belt }; private void GiveKits(BasePlayer player, string name) { if (!CheckKitExist(name)) return; player.inventory.Strip(); GiveItems(player, name, InventoryType.belt); GiveItems(player, name, InventoryType.wear); GiveItems(player, name, InventoryType.main); SendEffect(player, "assets/prefabs/deployable/locker/sound/equip_zipper.prefab"); } private void GiveItems(BasePlayer player, string name, InventoryType type) { if (!CheckKitExist(name)) return; ItemContainer container = type == InventoryType.belt ? player.inventory.containerBelt : type == InventoryType.wear ? player.inventory.containerWear : player.inventory.containerMain; var cmd = c.kit.Single(x => x.name == name); var list = type == InventoryType.belt ? cmd.belt : type == InventoryType.wear ? cmd.wear : cmd.main; foreach (var iSave in list) { var item = ItemManager.CreateByName(iSave.shortName, iSave.amount, iSave.skin); item.condition = iSave.condition; if (iSave.instanceData != null) item.instanceData = iSave.instanceData; var weapon = item.GetHeldEntity() as BaseProjectile; if (weapon != null) { if (!string.IsNullOrEmpty(iSave.ammotype)) weapon.primaryMagazine.ammoType = ItemManager.FindItemDefinition(iSave.ammotype); weapon.primaryMagazine.contents = iSave.ammo; } if (iSave.contents != null) { foreach (var contentData in iSave.contents) { var newContent = ItemManager.CreateByName(contentData.shortName, contentData.amount); if (newContent != null) { newContent.condition = contentData.condition; newContent.MoveToContainer(item.contents); } } } item.MoveToContainer(container); } } #endregion #region COMMAND [ChatCommand("clear")] private void ClearInvCommand(BasePlayer player, string command, string[] args) { if (!player.IsAdmin) { MessageReply(player.IPlayer, Translate(Lang["NotPerm"])); return; } if (args.Count() == 0) { MessageReply(player.IPlayer, Translate(Lang["SyntaxClearError"])); return; } switch (args[0].ToLower()) { case "all": player.inventory.Strip(); break; case "main": player.inventory.containerMain.Clear(); break; case "wear": player.inventory.containerWear.Clear(); break; case "belt": player.inventory.containerBelt.Clear(); break; default: return; } } [ChatCommand("kit")] private void KitCommand(BasePlayer player, string command, string[] args) { LoadConfig(); if (args.Count() == 0) { MessageReply(player.IPlayer, Translate(Lang["SyntaxError"])); return; } if (!CheckCommandExist(args[0])) { MessageReply(player.IPlayer, Translate(Lang["NotExist"], new Dictionary { { "name", args[0] } })); return; } if (!CheckKitActive(args[0])) { MessageReply(player.IPlayer, Translate(Lang["IsInactive"])); return; } if (!CheckHasPerms(player, args[0])) { MessageReply(player.IPlayer, Translate(Lang["NotPerm"])); return; } if (!CheckKitState("start", args[0])) { string[] ret = GetKitDate("start", args[0]); string date = $"{ret[0]}/{ret[1]}/{ret[2]} à {ret[3]}"; MessageReply(player.IPlayer, Translate(Lang["NotStart"], new Dictionary { { "name", GetKitName(args[0]) }, { "start", date } })); return; } if (!CheckKitState("end", args[0])) { MessageReply(player.IPlayer, Translate(Lang["IsEnd"], new Dictionary { { "name", GetKitName(args[0]) }})); return; } GiveKits(player, GetKitName(args[0])); } #endregion } }