using System; using System.Collections.Generic; using System.Linq; using Newtonsoft.Json; using Oxide.Core; #region Changelogs and ToDo /********************************************************************** * 1.0.0 Release * 1.1.0 Added Global block to a cfg * Using switch case method * Fix for rust changes in stables vendor **********************************************************************/ #endregion namespace Oxide.Plugins { [Info("Vendor Block" , "Krungh Crow" , "1.1.0")] [Description("Disables interaction with the airwolf/boat/stables vendor npc")] class VendorBlock : RustPlugin { #region Variables private bool heliVendorEnabled; private bool boatVendorEnabled; private bool horseVendorEnabled; const string Heli_Perm = "vendorblock.heli"; const string Boat_Perm = "vendorblock.boat"; const string Horse_Perm = "vendorblock.horse"; private const string TargetPrefabPath = "assets/prefabs/deployable/vendingmachine/npcvendingmachines/shopkeeper_vm_invis.prefab"; #endregion #region Configuration protected override void LoadDefaultConfig() { Config["HeliVendorEnabled"] = heliVendorEnabled = GetConfig("HeliVendorEnabled" , true); Config["BoatVendorEnabled"] = boatVendorEnabled = GetConfig("BoatVendorEnabled" , true); Config["HorseVendorEnabled"] = horseVendorEnabled = GetConfig("HorseVendorEnabled" , true); SaveConfig(); } private T GetConfig(string key , T defaultValue) { return Config[key] == null ? defaultValue : (T)Config[key]; } #endregion #region LanguageAPI protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { ["VendorReplyAirwolf"] = "Using the Airwolf Vendor is disabled on this server!" , ["VendorReplyBoat"] = "Using the Boat Vendor is disabled on this server!" , ["VendorReplyStables"] = "Using the Horse Vendor is disabled on this server!" , } , this); } #endregion #region Oxide hooks void Init() { permission.RegisterPermission(Heli_Perm , this); permission.RegisterPermission(Boat_Perm , this); permission.RegisterPermission(Horse_Perm , this); } bool? OnNpcConversationStart(object vendor , BasePlayer player , ConversationData conversationData) { // Debugging: Print out the shortname and type of the vendor Puts($"Conversation started with vendor: {conversationData.shortname}, Vendor Type: {vendor.GetType().Name}"); switch (conversationData.shortname) { case "airwolf_heli_vendor": if (!permission.UserHasPermission(player.UserIDString , Heli_Perm) && !heliVendorEnabled) { player.ChatMessage(lang.GetMessage("VendorReplyAirwolf" , this , player.UserIDString)); return false; } break; case "boatvendor": if (!permission.UserHasPermission(player.UserIDString , Boat_Perm) && !boatVendorEnabled) { player.ChatMessage(lang.GetMessage("VendorReplyBoat" , this , player.UserIDString)); return false; } break; case "stables_shopkeeper": if (!permission.UserHasPermission(player.UserIDString , Horse_Perm) && !horseVendorEnabled) { player.ChatMessage(lang.GetMessage("VendorReplyStables" , this , player.UserIDString)); return false; } break; default: break; } return null; } object CanUseVending(BasePlayer player , VendingMachine machine) { string prefabName = machine.PrefabName; switch (prefabName) { case TargetPrefabPath: var requiredItemIds = new HashSet { 1559915778, // ID for Single Horse Saddle -1323101799, // ID for Double Horse Saddle 60528587, // ID for Roadsign Horse Armor 1989785143 // ID for High Quality Horse Shoes }; var vendingItems = machine.inventory.itemList; bool hasRequiredItems = requiredItemIds.All(requiredId => vendingItems.Any(item => item.info.itemid == requiredId)); if (hasRequiredItems) { if (!permission.UserHasPermission(player.UserIDString , Horse_Perm) && !horseVendorEnabled) { player.ChatMessage(lang.GetMessage("VendorReplyStables" , this , player.UserIDString)); return false; } } else { Puts("The vending machine does not contain the required items."); return false; } break; default: break; } return null; } #endregion } }