Advertisement
okidoki__

crafthelper41

Jan 4th, 2022
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. require 'crafthelper41';
  2. require 'UI/craftHelper41Window';
  3.  
  4. craftHelper41Menu = {};
  5.  
  6. ---
  7. -- Add option in contextual menu when right click is done on an item in inventory panel
  8. --
  9. craftHelper41Menu.doCraftHelperMenu = function(player,context, items)
  10. local isUsedInRecipe = false;
  11.  
  12. -- Go through the items selected (because multiple selections in inventory is possible)
  13. for _,item in ipairs(items) do
  14.  
  15. if not instanceof(item, "InventoryItem") then
  16. item = item.items[1];
  17.  
  18. end
  19.  
  20. -- We test here if the item is used in any recipes
  21. if type(craftHelper41.recipesByItem[item:getName()]) == 'table' then
  22. isUsedInRecipe = true;
  23. end
  24. end
  25.  
  26. -- If one or more items tested above are used in a recipe
  27. -- we effectively add an option in the contextual menu
  28. if isUsedInRecipe then
  29. context:addOption(getText("UI_CH"), items, craftHelper41Menu.onCraftHelper, player);
  30. end
  31. end
  32.  
  33.  
  34. ---
  35. -- Action to perform when the Craft Helper option in contextual menu is clicked
  36. --
  37. craftHelper41Menu.onCraftHelper = function(items, player)
  38. -- Go through the items selected (because multiple selections in inventory is possible)
  39. for _,item in ipairs(items) do
  40.  
  41. if not instanceof(item, "InventoryItem") then
  42. item = item.items[1];
  43. end
  44.  
  45. -- Show craft helper window
  46. craftHelper41Menu.craftHelperWindow = craftHelper41Window:new(100, 100, item);
  47. craftHelper41Menu.craftHelperWindow:initialise();
  48. craftHelper41Menu.craftHelperWindow:addToUIManager();
  49. end
  50. end
  51.  
  52.  
  53. ---
  54. -- Call doCraftHelperMenu function when context menu in the inventory is created and displayed
  55. --
  56. Events.OnFillInventoryObjectContextMenu.Add(craftHelper41Menu.doCraftHelperMenu);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement