using Oxide.Core; using Newtonsoft.Json; using System.Collections.Generic; namespace Oxide.Plugins { [Info("No Vood", "Sapnu Puas", "1.0.3")] [Description("use furnaces with no wood and quick smelt options")] public class NoVood : RustPlugin { #region[Permissions] private void Init() { permission.RegisterPermission(PermissionNoVood, this); permission.RegisterPermission(PermissionQuickSmelt, this); } private const string PermissionNoVood = "novood.use"; private const string PermissionQuickSmelt = "novood.quick-smelt"; #endregion[Permissions] #region[Hooks] private object OnFindBurnable(BaseOven oven) { if (oven == null || oven.net == null) return null; if (!permission.UserHasPermission(oven?.OwnerID.ToString(), PermissionNoVood)) return null; if (!config.furnaceSettings.ContainsKey(oven.ShortPrefabName)) return null; var furnacesetup = config.furnaceSettings[oven.ShortPrefabName]; bool usenowood = furnacesetup.UseNoWood; bool raw = furnacesetup.NeedRes; if (!string.IsNullOrEmpty(oven.ShortPrefabName)) { foreach (var check in oven.inventory.itemList) if (check.info.shortname.Contains("wood")) return null; if (usenowood) { var fuel = ItemManager.CreateByItemID(-151838493); if (!raw) { return fuel; } foreach (var check in oven.inventory.itemList) if (config.AllowedRes.Contains(check.info.shortname)) { return fuel; } return null; } } return null; } private void OnOvenToggle(StorageContainer container, BasePlayer player) { var oven = container as BaseOven; if (oven == null || player == null || container == null) return; if (oven.IsDestroyed) return; if (!config.furnaceSettings.ContainsKey(oven.ShortPrefabName)) return ; var furnacesetup = config.furnaceSettings[oven.ShortPrefabName]; int ovenspeed = furnacesetup.Speed; if (permission.UserHasPermission(player.userID.ToString(), PermissionQuickSmelt)) NextTick(() => { if (!string.IsNullOrEmpty(oven.ShortPrefabName)) { if (!oven.HasFlag(BaseEntity.Flags.On)) NextTick(() => { NextTick(oven.StopCooking); }); else { var speed = 0.5f / ovenspeed; oven.CancelInvoke(oven.Cook); oven.inventory.temperature = oven.cookingTemperature; oven.UpdateAttachmentTemperature(); oven.InvokeRepeating(oven.Cook, speed, speed); return; } } return; }); return; } #endregion[Hooks] #region [Configuration] private PluginConfig config; private class PluginConfig { [JsonProperty("base oven short prefab name and settings")] public Dictionary furnaceSettings { get; set; } [JsonProperty("Allowed Resources (Item Shortnames) items must be in this list to use without wood")] public HashSet AllowedRes = new HashSet() { { "metal.ore" }, { "hq.metal.ore" }, { "sulfur.ore" }, { "crude.oil"}, { "bearmeat" }, { "chicken.raw" }, { "horsemeat.raw" }, { "meat.boar" }, {"wolfmeat.raw" }, { "deermeat.raw" }, { "fish.raw"}, {"humanmeat.raw" } }; } private class FurnaceSetup { [JsonProperty("Uses no fuel ?")] public bool UseNoWood { get; set; } [JsonProperty("Require raw resources to start when using no fuel")] public bool NeedRes { get; set; } [JsonProperty("Quicksmelt speed (1 is default speed)")] public int Speed { get; set; } } protected override void LoadDefaultConfig() { PrintWarning("Loading Default Config"); config = new PluginConfig(); } protected override void LoadConfig() { base.LoadConfig(); config = Config.ReadObject(); Config.Settings.DefaultValueHandling = DefaultValueHandling.Populate; config = AdditionalConfig(Config.ReadObject()); Config.WriteObject(config,true); SaveConfig(); } protected override void SaveConfig() => Config.WriteObject(config, true); private PluginConfig AdditionalConfig(PluginConfig pluginConfig) { pluginConfig.furnaceSettings = pluginConfig.furnaceSettings ?? new Dictionary { ["furnace"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["furnace.large"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["refinery_small_deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["carvable.pumpkin"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["chineselantern.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["jackolantern.angry"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["jackolantern.happy"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["lantern.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["tunalight.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = false, Speed = 1 }, ["bbq.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["campfire"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["fireplace.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["hobobarrel.deployed"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, ["skull_fire_pit"] = new FurnaceSetup { UseNoWood = true, NeedRes = true, Speed = 1 }, }; return pluginConfig; } #endregion [Configuration] } }