using Newtonsoft.Json; using Oxide.Core; using System.Collections; using System.Collections.Generic; using ru = Oxide.Game.Rust; using System.Linq; namespace Oxide.Plugins { [Info("ZXCSmelter", "fermens#8767", "1.0.2")] class ZXCSmelter : RustPlugin { #region Config private PluginConfig config; protected override void LoadDefaultConfig() { config = PluginConfig.DefaultConfig(); } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); } protected override void SaveConfig() { Config.WriteObject(config); } private class PluginConfig { [JsonProperty("Cooldown")] public float cooldown; [JsonProperty("Chat command")] public string command; [JsonProperty("Smelt wood?")] public bool wood; [JsonProperty("Special smelting rates")] public Dictionary ooo { get; set; } = new Dictionary { { "crude.oil", 3 } }; public static PluginConfig DefaultConfig() { return new PluginConfig() { cooldown = 300f, command = "smelt", wood = true }; } } #endregion #region Lang Dictionary messagesRU = new Dictionary { {"M.COOLDOWN", "[ZXC Smelter] Переплавка инвентаря находится на перезарядке подождите: {0} сек."}, {"M.PERM", "[ZXC Smelter] У вас нет разрешения на использование Inventory Smelter." }, {"M.INV", "[ZXC Smelter] Ваш инвентарь успешно переплавлен." } }; Dictionary messagesEN = new Dictionary { {"M.COOLDOWN", "[ZXC Smelter] Inventory Smelter is on cooldown, please wait: {0} сек."}, {"M.PERM", "[ZXC Smelter] You do not have permission to use Inventory Smelter." }, {"M.INV", "[ZXC Smelter] Your inventory has been successfully smelted." } }; #endregion #region Initialize const string perminsta = "zxcsmelter.instant"; const string permcommand = "zxcsmelter.command"; private Dictionary cooldowns = new Dictionary(); private ItemDefinition coal; private void OnServerInitialized() { permission.RegisterPermission(perminsta, this); permission.RegisterPermission(permcommand, this); lang.RegisterMessages(messagesEN, this, "en"); lang.RegisterMessages(messagesRU, this, "ru"); Interface.Oxide.GetLibrary(null).AddChatCommand(config.command, this, "SmeltCmd"); if (config.wood) coal = ItemManager.FindItemDefinition(-1938052175); } #endregion #region Gathering private object OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item) { var player = entity.ToPlayer(); if (player == null || !permission.UserHasPermission(player.UserIDString, perminsta)) return null; return SmeltIt(player, item); } private object OnDispenserBonus(ResourceDispenser dispenser, BasePlayer player, Item item) { if (!permission.UserHasPermission(player.UserIDString, perminsta)) return null; return SmeltIt(player, item); } private void OnCollectiblePickup(Item item, BasePlayer player) { if (!permission.UserHasPermission(player.UserIDString, perminsta)) return; SmeltIt(player, item); } #endregion #region Command private void SmeltCmd(BasePlayer player, string command, string[] args) { if (!permission.UserHasPermission(player.UserIDString, permcommand)) { SendReply(player, lang.GetMessage("M.PERM", this, player.UserIDString)); return; } float cooldown; if (cooldowns.TryGetValue(player.userID, out cooldown) && cooldown > UnityEngine.Time.realtimeSinceStartup) { SendReply(player, lang.GetMessage("M.COOLDOWN", this, player.UserIDString), cooldowns[player.userID] - (int)UnityEngine.Time.realtimeSinceStartup); return; } foreach (Item item in player.inventory.containerBelt.itemList.ToList()) SmeltIt(player, item); foreach (Item item in player.inventory.containerMain.itemList.ToList()) SmeltIt(player, item); SendReply(player, lang.GetMessage("M.INV", this, player.UserIDString)); cooldowns[player.userID] = (int)UnityEngine.Time.realtimeSinceStartup + config.cooldown; } #endregion #region Smelt private object SmeltIt(BaseEntity player, Item item) { if (item.info.itemid == -151838493 && config.wood) return GiveToPlayer(player, item, coal); else { ItemModCookable cookable = item.info.GetComponent(); if (cookable == null) return null; return GiveToPlayer(player, item, cookable.becomeOnCooked); } } private object GiveToPlayer(BaseEntity player, Item item, ItemDefinition def) { int x; if (!config.ooo.TryGetValue(item.info.shortname, out x)) x = 1; Item newItem = ItemManager.Create(def, item.amount * x); if (newItem == null) return null; item.Remove(0.0f); player.GiveItem(newItem, BaseEntity.GiveItemReason.ResourceHarvested); return true; } #endregion } }