Jump to content

How to add context menu option to equip an item?


trashcanhands

Recommended Posts

Hi, all. 

I'm helping someone on the workshop with a mod that makes Wallets equippable containers. I have everything working except there is no context menu option to equip them. Double clicking the item equips it fine. I've searched high and low for a guide on this and haven't found anything. (RoboMat's tutorial being now defunct)..

 

I know I need to use the OnFillInventoryContextMenu event, and I've written a snippet of code but honestly, I'm just unsure as to how to implement it properly. 

 

Literally any guidance on this would be greatly appreciated. Thanks to all you awesome people.

Link to comment
Share on other sites

  • 1 month later...

Here is basic example snippet:

 

local function MyItemsContextMenuEntry(player, context, items)
  local items = ISInventoryPane.getActualItems(items)
  for _, item in ipairs(items) do
    if item:getFullType() == 'YourModule.YourItemType' then
      context:addOption(getText('IGUI_YourEntryTranslationString'), getSpecificPlayer(player), YourCallbackFunctionWhenClickedTheMenuEntry)
    end
  end
end

Events.OnFillInventoryObjectContextMenu.Add(MyItemsContextMenuEntry)

 

As best practice, cancel the function as soon as possible, if its clear, that its not targeting any of your desired item(s), because it will be executed every time, you right click on any invetory object. That's why those handlers are mostly wrapped together in the vanilla code or well coded mods.

 

If the event fires, it will send you int player, ISContextMenu context an ArrayList items out of the JS sources, so these three params are defined. You should be able to add optional arguments, if required by adding them as additional arguments of the .Add() call.

Edited by stuck1a
typo
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...