cecell

COBJ

Mar 10th, 2022
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.62 KB | None | 0 0
  1. Scriptname SpellResearchEnchantedCOBJ Extends ReferenceAlias
  2.  
  3. ObjectReference Property PlayerRef Auto
  4. FormList Property _srFL_cOBJCreatedItemFormList Auto
  5. FormList Property _srFL_DynamicCOBJList Auto
  6. FormList Property _srFL_COBJEnableList Auto
  7.  
  8. Int wasInSmelter = 0
  9.  
  10. Event OnInit()
  11. RegisterForAnimationEvent(Game.GetPlayer(), "IdleSmelterEnter")
  12. RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExitSlow")
  13. EndEvent
  14.  
  15. Event OnPlayerLoadGame()
  16. RegisterForAnimationEvent(Game.GetPlayer(), "IdleSmelterEnter")
  17. RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExitSlow")
  18. Debug.Trace("Player loaded the game!")
  19. EndEvent
  20.  
  21. Event OnAnimationEvent(ObjectReference akSource, string asEventName)
  22. Debug.Trace("Event fired! akSource: " + akSource + ", and asEventName: " + asEventName)
  23. if asEventName == "IdleSmelterEnter"
  24. wasInSmelter = 1
  25. Debug.Notification("Just entered the smelter!")
  26. return
  27. Form[] weaponsInInv = PO3_SKSEFunctions.AddItemsOfTypeToArray(Game.GetPlayer(), 41, TRUE, TRUE, TRUE)
  28. Weapon[] weaponsEnchantedInInv = New Weapon[32]
  29. MiscObject[] cOBJResults = New MiscObject[32]
  30. ConstructibleObject curCOBJ
  31. Enchantment curEnchantment
  32. Weapon curWeapon
  33. ;FormList _srFL_COBJEnableList = Game.GetFormFromFile(0x00000878, "Spell Research - Even More Patches.esp") as FormList
  34. ;FormList _srFL_DynamicCOBJList = Game.GetFormFromFile(0x00000899, "Spell Research - Even More Patches.esp") as FormList
  35. ;FormList _srFL_cOBJCreatedItemFormList = Game.GetFormFromFile(0x0000089C, "Spell Research - Even More Patches.esp") as FormList
  36.  
  37. Int idx
  38. Int j = 0
  39. Int i = 0
  40. while i < weaponsInInv.length && j < 31 ; j -> Break if exceeding 32 ench items
  41. curWeapon = weaponsInInv[i] as Weapon
  42. ; Filter out all non-enchanted
  43. if curWeapon
  44. curEnchantment = curWeapon.GetEnchantment()
  45. if curEnchantment && curEnchantment.GetNthEffectMagicEffect(0)
  46. ; determine type to set COBJ result item
  47. if curWeapon.IsBattleAxe() ; Battleaxe and Warhammer BOTH return type 6 so must handle one first
  48. idx = 0
  49. else
  50. idx = curWeapon.GetWeaponType()
  51. endif
  52. if idx != 2 && idx < 7 ; daggers(2), bows(7), staves(8) and crossbows(9) not yet implemented
  53. cOBJResults[j] = _srFL_cOBJCreatedItemFormList.GetAt(idx) as MiscObject
  54. endif
  55. if cOBJResults[j] != None ; should only be None if it's 2, 7, 8 or 9
  56. weaponsEnchantedInInv[j] = curWeapon
  57. j += 1
  58. endif
  59. endif
  60. endif
  61. i += 1
  62. endwhile
  63.  
  64. ; update and enable COBJs
  65. i = 0
  66. while i < weaponsEnchantedInInv.length
  67. ; Get the recipe COBJ
  68. curCOBJ = _srFL_DynamicCOBJList.GetAt(i) as ConstructibleObject
  69. ; Set the enchanted weapon as the only ingredient
  70. curCOBJ.SetNthIngredient(weaponsEnchantedInInv[i], 0)
  71. ; **The qty is set to 1 in the recipe already**
  72. ; Set result to the misc object that will swap the LVLI results in
  73. curCOBJ.SetResult(cOBJResults[i])
  74. ; enable Global that is the condition
  75. (_srFL_COBJEnableList.GetAt(i) as GlobalVariable).SetValue(1.0)
  76. i += 1
  77. endwhile
  78.  
  79. elseif asEventName == "IdleFurnitureExitSlow"
  80. Debug.Notification("Just exited the smelter!")
  81. if wasInSmelter != 0
  82. wasInSmelter = 0
  83. ; on exit smelter disable COBJs
  84. Int i = 0
  85. while i < _srFL_COBJEnableList.GetSize()
  86. (_srFL_COBJEnableList.GetAt(i) as GlobalVariable).SetValue(0.0)
  87. i += 1
  88. endwhile
  89. endif
  90. endif
  91. EndEvent
  92.  
Advertisement
Add Comment
Please, Sign In to add comment