Zerkish

ZHI Modders Resource

May 20th, 2025 (edited)
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.61 KB | None | 0 0
  1. -----------------------------------------------
  2. -- Zerkish Hotkeys Improved Modders Resource
  3. -----------------------------------------------
  4.  
  5. -------------------------
  6. -- Interface
  7. -------------------------
  8. -- Some parts of ZHI are exposed through an interface on the player.
  9.  
  10. local ZHI = require('openmw.interfaces').ZHI
  11. if ZHI.version >= myRequiredVersion then
  12. ...
  13. end
  14.  
  15. Useful Types:
  16. --------------------
  17. ZHI.ZHI_WINDOW = {
  18.     Main,
  19.     MagicSelection,
  20.     InventorySelection,
  21.     HotkeySelect,
  22.     FirstTimePopup,
  23.     QuickKeyMenuPopup,
  24. }
  25.  
  26. Useful functions:
  27.     isWindowOpen(ZHI_WINDOW)
  28.     isAnyWindowOpen()
  29.  
  30.     -- Returns hotbar number
  31.     getActiveHotbar()
  32.  
  33.     -- Get layers used by ZHI
  34.     getPopupLayer()
  35.     getTooltipLayer()
  36.  
  37.  
  38. ----------------------------
  39. -- Events
  40. ----------------------------
  41. -- These are events sent by ZHI when hotkeys are used.
  42.  
  43.  
  44. -- ZHI_HotkeySelectEvent
  45. --------------------------------------------------------------------
  46. -- This event will be sent any time the player presses a hotkey that has something useable on it.
  47. -- Keep in mind that this does not guarantee that the player can immediately use the item/spell,
  48. -- if the player is in an animation for instance.
  49. -- For item usage, the player needs to have the item in their inventory, or the event won't be sent.
  50. local function sendZHIHotkeyEvent(spell, item, itemEnchant)
  51.     if (not spell) and (not item) and (not itemEnchant) then return end
  52.  
  53.     local data = {}
  54.     if spell then
  55.         data.spell = {
  56.             id = spell.id
  57.         }
  58.     elseif item then
  59.         data.item = {
  60.             id = item.id,
  61.             recordId = item.recordId,
  62.             typeName = tostring(item.type),
  63.         }
  64.     elseif itemEnchant then
  65.         -- This is set when the item will be used for its enchantment.
  66.         -- the fields are the same as for data.item
  67.         data.itemEnchant = {
  68.             id = itemEnchant.id,
  69.             recordId = itemEnchant.recordId,
  70.             typeName = tostring(itemEnchant.type),
  71.         }
  72.     end
  73.    
  74.     self:sendEvent('ZHI_HotkeySelectEvent', data)
  75. end
  76.  
  77. -- ZHI_HotkeyEquipEvent
  78. --------------------------------------------------------------------
  79. -- This is sent when ZHI equips an item.
  80. -- It is not sent if the item is already equipped.
  81. local function sendZHIHotkeyEquipEvent(item, equipmentSlot)
  82.     if (not item) then return end
  83.  
  84.     local data = {
  85.         item = {
  86.             id = item.id,
  87.             typeName = tostring(item.type),
  88.         },
  89.         equipmentSlot = equipmentSlot,
  90.     }
  91.  
  92.     self:sendEvent('ZHI_HotkeyEquipEvent', data)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment