Advertisement
dunc001

Auto-Add new items on equipping

Dec 6th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. ;This event handles auto-adding newly equipped items to the left, right and shout slots
  2. Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)
  3. debug.trace("iEquip_PlayerEventHandler OnObjectEquipped called")
  4. if WC.bAutoAddNewItems
  5. int equippedSlot = -1
  6. if PlayerRef.GetEquippedObject(0) == akBaseObject
  7. equippedSlot = 0
  8. elseIf PlayerRef.GetEquippedObject(1) == akBaseObject
  9. equippedSlot = 1
  10. elseIf PlayerRef.GetEquippedObject(2) == akBaseObject
  11. equippedSlot = 2
  12. endIf
  13. ;If the item has been equipped in the left, right or shout slot
  14. if equippedSlot != -1
  15. bool blockCall = false
  16. bool formFound = iEquip_AllCurrentItemsFLST.HasForm(akBaseObject)
  17. string itemName = akBaseObject.GetName()
  18. ;Check if we've just manually equipped an item that is already in this iEquip queue
  19. int targetIndex = -1
  20. if formFound
  21. ;If it's been found in the queue for the equippedSlot it's been equipped to
  22. targetIndex = WC.findInQueue(equippedSlot, itemName)
  23. if targetIndex != -1
  24. ;If it's already shown in the widget do nothing
  25. if WC.aiCurrentQueuePosition[equippedSlot] == targetIndex
  26. blockCall = true
  27. ;Otherwise update the position and name, then update the widget
  28. else
  29. WC.aiCurrentQueuePosition[equippedSlot] = targetIndex
  30. WC.asCurrentlyEquipped[equippedSlot] = itemName
  31. if equippedSlot < 2 || WC.bShoutEnabled
  32. WC.updateWidget(equippedSlot, targetIndex, false, true)
  33. endIf
  34. endIf
  35. endIf
  36. endIf
  37. ;If it isn't already contained in the AllCurrentItems formlist, or it is but findInQueue has returned -1 meaning it's a 1H item contained in the other hand queue
  38. if !formFound || targetIndex == -1
  39. ;First check if the target Q has space or can grow organically - ie bHardLimitQueueSize is disabled
  40. bool freeSpace = true
  41. targetIndex = jArray.count(WC.aiTargetQ[equippedSlot])
  42. if targetIndex >= WC.iMaxQueueLength
  43. if WC.bHardLimitQueueSize
  44. freeSpace = false
  45. blockCall = true
  46. else
  47. WC.iMaxQueueLength += 1
  48. endIf
  49. endIf
  50. if freeSpace
  51. ;If there is space in the target queue create a new jMap object and add it to the queue
  52. debug.trace("iEquip_PlayerEventHandler OnObjectEquipped - akBaseObject: " + akBaseObject + " - " + itemName + ", equippedSlot: " + equippedSlot)
  53. int itemID = WC.createItemID(itemName, akBaseObject.GetFormID())
  54. int itemType = akBaseObject.GetType()
  55. if itemType == 41 ;if it is a weapon get the weapon type
  56. itemType = (akBaseObject as Weapon).GetWeaponType()
  57. endIf
  58. int iEquipItem = jMap.object()
  59. jMap.setForm(iEquipItem, "Form", akBaseObject)
  60. jMap.setInt(iEquipItem, "ID", itemID)
  61. jMap.setInt(iEquipItem, "Type", itemType)
  62. jMap.setStr(iEquipItem, "Name", itemName)
  63. jMap.setStr(iEquipItem, "Icon", WC.GetItemIconName(akBaseObject, itemType, itemName))
  64. if equippedSlot < 2
  65. jMap.setInt(iEquipItem, "isEnchanted", 0)
  66. jMap.setInt(iEquipItem, "isPoisoned", 0)
  67. endIf
  68. jArray.addObj(WC.aiTargetQ[equippedSlot], iEquipItem)
  69. ;If it's not already in the AllItems formlist because it's in the other hand queue add it now
  70. if !formFound
  71. iEquip_AllCurrentItemsFLST.AddForm(akBaseObject)
  72. endIf
  73. ;Send to moreHUD if loaded
  74. if WC.bMoreHUDLoaded
  75. if formFound
  76. AhzMoreHudIE.AddIconItem(itemID, WC.asMoreHUDIcons[3]) ;Both queues
  77. else
  78. AhzMoreHudIE.AddIconItem(itemID, WC.asMoreHUDIcons[equippedSlot])
  79. endIf
  80. endIf
  81. ;Now update the widget to show the equipped item
  82. WC.aiCurrentQueuePosition[equippedSlot] = targetIndex
  83. WC.asCurrentlyEquipped[equippedSlot] = itemName
  84. if equippedSlot < 2 || WC.bShoutEnabled
  85. WC.updateWidget(equippedSlot, targetIndex, false, true)
  86. endIf
  87. endIf
  88. endIf
  89. ;And run the rest of the hand equip cycle without actually equipping to toggle ammo mode if needed and update count, poison and charge info
  90. if !blockCall && equippedSlot < 2
  91. WC.checkAndEquipShownHandItem(equippedSlot, false, true)
  92. endIf
  93. endIf
  94. endIf
  95. endEvent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement