Jump to content

[LE] Event for detecting any effect ending on the player?


ngentili

Recommended Posts

I am trying to call an event every time ANY active effect on the player starts or ends.

 

The closest I've gotten is something like this:

Event OnInit()
    RegisterForMagicEffectApplyEvent(PlayerRef)
EndEvent

;works fine
Event OnMagicEffectApply(ObjectReference akTarget, ObjectReference akCaster, MagicEffect akEffect)
    Debug.Notification("Some effect applied.")
    RegisterForMagicEffectApplyEvent(PlayerRef)
EndEvent

;does not work
Event OnEffectFinish(Actor akTarget, Actor akCaster)
    Debug.Notification("Some effect ended.")
EndEvent

But the OnEffectFinish doesn't work because it can only be attached to a specific MagicEffect, not to the player, as far as I know. Is there another way of detecting active effects ending? Or can I somehow reference the akEffect from the OnMagicEffectApply to detect when it ends?

Edited by nigtitz
Link to comment
Share on other sites

RegisterForMagicEffectApplyEvent is an FO4 event. It does not exist for Skyrim.

Here is the Scripting Reference page for Skyrim.

 

 

Using OnMagicEffectApply, you could pass the akEffect into an update loop that checks for the effect to no longer exist on the player with HasMagicEffect. However, if a new effect gets applied, it could change the effect being monitored and / or cause other unexpected behavior.

 

There may be a way to use an array to store effects added to the player, cycle them in the update loop to determine if they are still active or not. When not active, empty that array entry and do whatever you want to occur when an effect ends. It would take some testing to get the code correct as, for me at least, it is just theory.

Link to comment
Share on other sites

Don't need arrays. OnMagicEffectApply gives you a MagicEffect, not an ActiveMagicEffect, and a MagicEffect is a form. Therefore, it can be added to a FormList, which is for this purpose effectively a dynamically resizing array that's been user-proofed for you.

 

Then, start a poll where the list is iterated through at some interval to see if everything in it still applies. If not, remove the ones that aren't (and trigger your 'on stop' stuff, whatever that may be), and if the count of things in the list hits 0, stop the polling until more things are added again.

 

This allows you to avoid the use of SKSE for dynamic array sizing, if not required elsewhere.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...