Jump to content

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

1. Use an array to save all the effects for which OnMagicEffectApply was called.

2. Use a timer to detect when an effect is not active anymore. For this use the Actor.HasMagicEffect() function.

 

Probably you'll have to use more arrays, because one can hold up to 128 entries and may not be enough. And iterating the array(s) and calling HasMagicEffect for each entry is not very fast...

 

If you want to have a list with all player's active effects and F4SE is an option then see this: https://www.nexusmods.com/fallout4/mods/32735

You can use that extension as a start point (the source code is public), but it doesn't export a native function that can be used from a Papyrus script.

Edited by Wolfmark
Link to comment
Share on other sites

Maybe using RegisterForRemoteEvent:

Event OnInit()
    RegisterForMagicEffectApplyEvent(PlayerRef)
EndEvent

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

Event MagicEffect.OnEffectFinish(MagicEffect akEffect, Actor akTarget, Actor akCaster)
    Debug.Notification("Some effect ended.")
EndEvent

I didn't tested it, but it could work.

 

EDIT: Actually OnEffectFinish is an event of ActiveMagicEffect not MagicEffect, so doubt it works as is, but you maybe find this approach of use.

Edited by DieFeM
Link to comment
Share on other sites

  • Recently Browsing   0 members

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