using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; using Oxide.Core; using UnityEngine; namespace Oxide.Plugins { [Info("FireTools", "XAVIER", "1.0.1")] public class FireTools : RustPlugin { #region Lang public static StringBuilder sb = new StringBuilder(); public string GetLang(string LangKey, string userID = null, params object[] args) { sb.Clear(); if (args != null) { sb.AppendFormat(lang.GetMessage(LangKey, this, userID), args); return sb.ToString(); } return lang.GetMessage(LangKey, this, userID); } private void LoadMessages() { lang.RegisterMessages(new Dictionary { ["NotRepair"] = "Вы не можете починить данный предмет!", } , this, "ru"); lang.RegisterMessages(new Dictionary { ["NotRepair"] = "You can not repair this tool!", } , this); } #endregion #region Initialized private Dictionary Transmutations; private readonly List Transmutatable = new List() { "chicken.raw", "humanmeat.raw", "bearmeat", "deermeat.raw", "meat.boar", "wolfmeat.raw", "hq.metal.ore", "metal.ore", "sulfur.ore", "horsemeat.raw" }; void OnServerInitialized() { Transmutations = ItemManager.GetItemDefinitions().Where(p => Transmutatable.Contains(p.shortname)) .ToDictionary(p => p, p => p.GetComponent()?.becomeOnCooked); ItemDefinition wood = ItemManager.FindItemDefinition("wood"); ItemDefinition charcoal = ItemManager.FindItemDefinition("charcoal"); Transmutations.Add(wood, charcoal); LoadMessages(); } #endregion #region Hooks object OnItemRepair(BasePlayer player, Item item) { if (player == null || item == null) return null; var find = config._listTool.Find(p => p.ShortName == item.info.shortname && p.SkinID == item.skin); if (find != null) { if (!find.isRepair) { player.ChatMessage(GetLang("NotRepair", player.UserIDString)); return false; } } return null; } void OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) { if (dispenser == null || entity == null || item == null) return; BasePlayer player = entity.ToPlayer(); if (player == null) return; var itemTarget = player.GetActiveItem(); if (itemTarget == null) return; var find = config._listTool.Find(p => p.ShortName == itemTarget.info.shortname && p.SkinID == itemTarget.skin); if (find != null) { if (find._listitemTools.Contains(item.info.shortname) && Transmutations.ContainsKey(item.info)) item.info = Transmutations[item.info]; } } void OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) { if (dispenser == null || player == null || item == null) return; var itemTarget = player.GetActiveItem(); if (itemTarget == null) return; var find = config._listTool.Find(p => p.ShortName == itemTarget.info.shortname && p.SkinID == itemTarget.skin); if (find != null) { if (find._listitemTools.Contains(item.info.shortname) && Transmutations.ContainsKey(item.info)) item.info = Transmutations[item.info]; } } #endregion #region ConsoleCommand [ConsoleCommand("give.fire")] void GiveFireTool(ConsoleSystem.Arg args) { if (!args.IsAdmin) return; if (args.Args.Length < 2) { PrintWarning($"Error! Example: give.fire hatchet Sparkless"); return; } var item = config._listTool.Find(p => p.ShortName == args.Args[0]); if (item == null) { PrintWarning($"Error! Example: give.fire hatchet Sparkless"); return; } var target = BasePlayer.Find(args.Args[1]); if (target == null) { PrintWarning($"Error! Player {args.Args[1]} not found!"); return; } var createItem = ItemManager.CreateByName(item.ShortName, 1, item.SkinID); createItem.name = item.DisplayName; target.GiveItem(createItem, BaseEntity.GiveItemReason.PickedUp); } #endregion #region Configuration private PluginConfig config; protected override void LoadDefaultConfig() { config = PluginConfig.DefaultConfig(); } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); if (config.PluginVersion < Version) UpdateConfigValues(); Config.WriteObject(config, true); } private void UpdateConfigValues() { PluginConfig baseConfig = PluginConfig.DefaultConfig(); if (config.PluginVersion < new VersionNumber(0, 0, 1)) { PrintWarning("Config update detected! Updating config values..."); PrintWarning("Config update completed!"); } config.PluginVersion = Version; } protected override void SaveConfig() { Config.WriteObject(config); } public class SettingsTools { [JsonProperty("ShortName Tool")] public string ShortName; [JsonProperty("DisplayName Tool")] public string DisplayName; [JsonProperty("SkinID Tool")] public ulong SkinID; [JsonProperty("Will it be possible to repair the tool")] public bool isRepair; [JsonProperty("List of items that will be recycled by this tool")] public List _listitemTools = new List(); } private class PluginConfig { [JsonProperty("Tool List")] public List _listTool = new List(); [JsonProperty("Verison Configuration")] public VersionNumber PluginVersion = new VersionNumber(); public static PluginConfig DefaultConfig() { return new PluginConfig() { _listTool = new List() { new SettingsTools() { ShortName = "hatchet", DisplayName = "Fire Hatchet", SkinID = 2570607902, isRepair = false, _listitemTools = new List() { "chicken.raw", "humanmeat.raw", "bearmeat", "deermeat.raw", "meat.boar", "wolfmeat.raw", "horsemeat.raw", "wood" }, }, new SettingsTools() { ShortName = "pickaxe", DisplayName = "Fire Pickaxe", SkinID = 2570608713, isRepair = false, _listitemTools = new List() { "chicken.raw", "humanmeat.raw", "bearmeat", "deermeat.raw", "meat.boar", "wolfmeat.raw", "hq.metal.ore", "metal.ore", "sulfur.ore", "horsemeat.raw" }, }, new SettingsTools() { ShortName = "jackhammer", DisplayName = "Fire Jackhammer", SkinID = 2570608219, isRepair = false, _listitemTools = new List() { "chicken.raw", "humanmeat.raw", "bearmeat", "deermeat.raw", "meat.boar", "wolfmeat.raw", "hq.metal.ore", "metal.ore", "sulfur.ore", "horsemeat.raw" }, }, }, PluginVersion = new VersionNumber(), }; } } #endregion } }