Talismon Posted September 13, 2022 Share Posted September 13, 2022 (edited) EDIT: SOLUTION Checked out the mod "Soul Filcher's Building Time", you can loop through context options and get the option by name: for i,v in ipairs(context.options) do if v.name == getText("ContextMenu_Unequip") then unequipOption = v; unequipOption.notAvailable = true; end end I got crickets from discord too Description I created a mod that spawns you with named Dog Tags equipped to your neck, and I added a few sandbox options. one of the sandbox options I wanted to include was "Prevent Unequip", but It seems the unequip menu option for Base.Necklace_DogTag is created by the ISInventoryPaneContextMenu.createMenu method in ISUI/ISInventoryPaneContextMenu.lua and I can't figure out how to make a small change to it. My Code ISInventoryRenameTags = {}; require "ISInventoryPaneContextMenu" ISInventoryRenameTags.createMenu = function(player, context, items) if not SandboxVars.playerDogTags.AllowRename then return end local canBeRenamedTags = nil; for i, v in ipairs(items) do local item = v; if not instanceof(v, "InventoryItem") then item = v.items[1]; end if item:getFullType() == "Base.Necklace_DogTag" then canBeRenamedTags = item; cantUnequip = item; end end if cantUnequip then local unequipOption = context:addOption(getText("ContextMenu_Unequip"), items, ISInventoryPaneContextMenu.onUnEquip, player); unequipOption.notAvailable = true; end if canBeRenamedTags then context:addOption(getText("Rename Dog Tags"), canBeRenamedTags, ISInventoryRenameTags.onRenameTags, player); end end ISInventoryRenameTags.onRenameTags = function(tags, player) local modal = ISTextBox:new(0, 0, 280, 180, getText("Change Name"), tags:getName(), nil, ISInventoryRenameTags.onRenameTagsClick, player, getSpecificPlayer(player), tags); modal:initialise(); modal:addToUIManager(); end function ISInventoryRenameTags:onRenameTagsClick(button, player, item) if button.internal == "OK" then if button.parent.entry:getText() and button.parent.entry:getText() ~= "" then item:setName(button.parent.entry:getText()); local pdata = getPlayerData(player:getPlayerNum()); pdata.playerInventory:refreshBackpacks(); pdata.lootInventory:refreshBackpacks(); end end end Events.OnPreFillInventoryObjectContextMenu.Add(ISInventoryRenameTags.createMenu); What I've Tried The code above just creates a new Unequip option on top. so I went to look at what creates that original 'Unequip' option, and it lead me to trying to figure out a way to modify this IF statement ( ISUI/ISInventoryPaneContextMenu.lua line 681 ) if unequip and isForceDropHeavyItem(unequip) then context:addOption(getText("ContextMenu_Drop"), items, ISInventoryPaneContextMenu.onUnEquip, player); addDropOption = false elseif unequip then context:addOption(getText("ContextMenu_Unequip"), items, ISInventoryPaneContextMenu.onUnEquip, player); end and I also tried changing this statement ( ISUI/ISInventoryPaneContextMenu.lua line 152 ) if playerObj:isEquipped(testItem) then unequip = testItem; end -- To something like if playerObj:isEquipped(testItem) and testItem:getFullType() ~= "Base.Necklace_DogTag" then unequip = testItem; end I tried copying the entire ISInventoryPaneContextMenu.createMenu method, removing all irrelevant bits, and making the change, but it overwrites the vanilla menu. Last thing I tried was looking for a way to target and remove context menu items, but it seems like there's no "context:removeOption()" for lack of a better description. Edited September 23, 2022 by Talismon solved Link to comment Share on other sites More sharing options...
stuck1a Posted October 17, 2022 Share Posted October 17, 2022 On 9/13/2022 at 3:01 AM, Talismon said: Last thing I tried was looking for a way to target and remove context menu items, but it seems like there's no "context:removeOption()" for lack of a better description. Hey there, even if you have already solved your problem, just let me answer for anyone else who will encounter this problem in future as wel.. There is actual a possibility to remove existing context menu items. You just need the correspnding context object. I'm currently working on finishing an old, unfinished mod from blindc0der. Since it is a build overhaul, I had to remove the vanilla "Build" and "Metal Wielding" objects. You can either overload the build script or do it as follows: BCCrafTec.WorldMenu = function(player, context, worldObjects) -- Remove vanilla menus context:removeOptionByName(getText("ContextMenu_Build")); -- context is an instance of ISContextMenu context:removeOptionByName(getText("ContextMenu_MetalWelding")); -- Add CrafTec build menu -- ...unrelated... end Events.OnFillWorldObjectContextMenu.Add(BCCrafTec.WorldMenu); -- The event will give you the required context Hope this will help someone else in future Best regards stuck1a Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now