cecell icon

COBJ

cecell | PRO | 03/11/22 01:18:20 AM UTC | 0 ⭐ | 426 👁️ | Never ⏰ | []
text |

3.62 KB

|

None

|

0 👍

/

0 👎

Scriptname SpellResearchEnchantedCOBJ Extends ReferenceAlias
 ObjectReference Property PlayerRef Auto
FormList Property _srFL_cOBJCreatedItemFormList Auto
FormList Property _srFL_DynamicCOBJList Auto
FormList Property _srFL_COBJEnableList Auto
 Int wasInSmelter = 0
 Event OnInit()
  RegisterForAnimationEvent(Game.GetPlayer(), "IdleSmelterEnter")
  RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExitSlow")
EndEvent
 Event OnPlayerLoadGame()
  RegisterForAnimationEvent(Game.GetPlayer(), "IdleSmelterEnter")
  RegisterForAnimationEvent(Game.GetPlayer(), "IdleFurnitureExitSlow")
  Debug.Trace("Player loaded the game!")
EndEvent
 Event OnAnimationEvent(ObjectReference akSource, string asEventName)
  Debug.Trace("Event fired! akSource: " + akSource + ", and asEventName: " + asEventName)
  if asEventName == "IdleSmelterEnter"
    wasInSmelter = 1
    Debug.Notification("Just entered the smelter!")
    return
    Form[] weaponsInInv = PO3_SKSEFunctions.AddItemsOfTypeToArray(Game.GetPlayer(), 41, TRUE, TRUE, TRUE)
    Weapon[] weaponsEnchantedInInv = New Weapon[32]
    MiscObject[] cOBJResults = New MiscObject[32]
    ConstructibleObject curCOBJ
    Enchantment curEnchantment
    Weapon curWeapon
    ;FormList _srFL_COBJEnableList = Game.GetFormFromFile(0x00000878, "Spell Research - Even More Patches.esp") as FormList
    ;FormList _srFL_DynamicCOBJList = Game.GetFormFromFile(0x00000899, "Spell Research - Even More Patches.esp") as FormList
    ;FormList _srFL_cOBJCreatedItemFormList = Game.GetFormFromFile(0x0000089C, "Spell Research - Even More Patches.esp") as FormList
     Int idx
    Int j = 0
    Int i = 0
    while i < weaponsInInv.length && j < 31 ; j -> Break if exceeding 32 ench items
      curWeapon = weaponsInInv[i] as Weapon
      ; Filter out all non-enchanted
      if curWeapon
        curEnchantment = curWeapon.GetEnchantment()
        if curEnchantment && curEnchantment.GetNthEffectMagicEffect(0)
          ; determine type to set COBJ result item
          if curWeapon.IsBattleAxe() ; Battleaxe and Warhammer BOTH return type 6 so must handle one first
            idx = 0
          else
            idx = curWeapon.GetWeaponType()
          endif
          if idx != 2 && idx < 7 ; daggers(2), bows(7), staves(8) and crossbows(9) not yet implemented
            cOBJResults[j] = _srFL_cOBJCreatedItemFormList.GetAt(idx) as MiscObject
          endif
          if cOBJResults[j] != None ; should only be None if it's 2, 7, 8 or 9
            weaponsEnchantedInInv[j] = curWeapon
            j += 1
          endif
        endif
      endif
      i += 1
    endwhile
     ; update and enable COBJs
    i = 0
    while i < weaponsEnchantedInInv.length
      ; Get the recipe COBJ
      curCOBJ = _srFL_DynamicCOBJList.GetAt(i) as ConstructibleObject
      ; Set the enchanted weapon as the only ingredient
      curCOBJ.SetNthIngredient(weaponsEnchantedInInv[i], 0)
      ; **The qty is set to 1 in the recipe already**
      ; Set result to the misc object that will swap the LVLI results in
      curCOBJ.SetResult(cOBJResults[i])
      ; enable Global that is the condition
      (_srFL_COBJEnableList.GetAt(i) as GlobalVariable).SetValue(1.0)
      i += 1
    endwhile
   elseif asEventName == "IdleFurnitureExitSlow"
    Debug.Notification("Just exited the smelter!")
    if wasInSmelter != 0
      wasInSmelter = 0
      ; on exit smelter disable COBJs
      Int i = 0
      while i < _srFL_COBJEnableList.GetSize()
        (_srFL_COBJEnableList.GetAt(i) as GlobalVariable).SetValue(0.0)
        i += 1
      endwhile
    endif
  endif
EndEvent
 

Comments