Jump to content

Getting a reference for an active magic effect on an actor


Recommended Posts

I want to create a script based magic effect, and then be able to access that script effect so I can call functions from it.

 

Say I have one magic effect that's part of a constant effect with a function defined called "DoSomething()".

 

From another script I want to do this:

MagicEffect Property targetEffect auto    ; The magic effect I want to access

Actor targetActor
MagicEffect effectRef

;;; Find the target actor somehow

effectRef = GetReferenceToMagicEffect(targetActor,targetEffect)    ; This is what I don't know how to do
effectRef.DoSomething()
Link to comment
Share on other sites

Actor Who = IDKLetsGoWithNazeem as Actor
Spell FirstSpellFound = Who.GetNthSpell(0)
MagicEffect FirstEffectFound = FirstSpellFound.GetNthEffectMagicEffect(0)
Projectile TheMissleItUses = FirstEffectFound.GetProjectile()

Etc...

 

Now if summoning an atronach or something far as I know you cannot read that unless its also a script property so best you could do there

is scan for a nearby actor of that base using Game.FindNearest... call

 

As for the script yeah you could cast the MagicEffect as ScriptName, but if it extends ActiveMagicEffect that wont work. And even if you could read MagicEffect, thats something you would need to know in advance manually unless you use a clever and complicated StringUtil call to read the script name, but then youd still need to know what properties to interact with so... yeah kinda where that stands

 

TBH you might want to look into ModEvents. The ActiveMagicEffect can send a ModEvent to a listener script when applicable and take whatever action. I am assuming you want something dynamic to happen on demand, which is where ModEvents shine

Link to comment
Share on other sites

You wrote: "I want to create a script based magic effect, and then be able to access that script effect so I can call functions from it."

 

Depends on:

1. count of actors be involved by this kind of magic effect

2. content of function code to run here

there are various ways to come along with.

 

A simple way would be the use of a GlobalVariable with different values, which makes the magic effect to do somethings depends on value.

A script of type activemagiceffect do not have "really" a self on it! So there is no way to call functions here from other scripts like external function call, as well as property get or set.

But you can use OnUpdate() to wait for and respond of the value from a GlobalVariable. In other scripts you set the value to force action in the base magic effect.

 

zorakConstantMGEFScript

 

Scriptname zorakConstantMGEFScript extends ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/10939083-getting-a-reference-for-an-active-magic-effect-on-an-actor/

  GlobalVariable PROPERTY myGlobal auto        ; new created by CK

  Actor target


; -- EVENTs -- 4

EVENT OnUpdate()
    myF_Action()
ENDEVENT


EVENT OnEffectStart(Actor akTarget, Actor akCaster)
    target = akTarget
    RegisterForSingleUpdate(1.0)
ENDEVENT

EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
    target = None
ENDEVENT


EVENT OnDying(Actor akKiller)
    UnRegisterForUpdate()
    myGlobal.SetValue(-1.0)
    self.Dispel()
ENDEVENT


; -- FUNCTIONs --

;--------------------
FUNCTION myF_Action()
;--------------------
IF ( target )
ELSE
    self.Dispel()
    RETURN    ; - STOP -    target not found!
ENDIF
;---------------------
IF target.IsDead()
    RETURN    ; - STOP -    safety net..
ENDIF
;---------------------
    float f = 1.0                        ; 1.0 - default cooldown time
    int i = myGlobalGetValueInt()

IF ( i )                ; (i != 0)
    IF     (i == 1)
        myF_A01()

    ELSEIF (i == 2)
        myF_A02()
        f = 2.0                          ; 2.0 update default cooldown (as a sample here)

    ELSEIF (i == 3)
        myF_A03()
    ENDIF
ENDIF

    IF (i >= 0)
        RegisterForSingleUpdate(f)       ; wait a bit before next action will be called
    ENDIF
ENDFUNCTION


;-----------------
FUNCTION myF_A01()
;-----------------
    ; code here
ENDFUNCTION


;-----------------
FUNCTION myF_A02()
;-----------------
    ; code here
ENDFUNCTION


;-----------------
FUNCTION myF_A03()
;-----------------
    ; code here
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

  • Recently Browsing   0 members

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