Difference between revisions of "Scripting MagicEffect"

85 bytes added ,  13:39, 8 November 2016
imported>Qazaaq
imported>Kalevala
Line 7: Line 7:
==Script==
==Script==
<source lang="papyrus">
<source lang="papyrus">
Scriptname aaaDynamicIncrementModule extends activemagiceffect
Scriptname change_value_over_time extends activemagiceffect


ActorValue Property ActionPoints Auto Const
ActorValue Property avSomeActorValue Auto Const
Actor EffectTarget
{ The actor value you want this script to modify }
Actor akEffectTarget


float Increment = 1.0
Float Property fChangeBy Auto
float IncrementVar = 0.01
{ The amount to increment the value by each time, to decrease over time use a negative number }
Float Property fInitialAmount Auto
{ The value to set when the effect starts }
Float Property fFrequency Auto
{ Seconds between increments }


int aaaIncrementTimerID = 10 ; Give our timer an ID we can remember


Event OnEffectStart(Actor Target, Actor Caster)
int iChangeTimerID = 10 ; Give our timer an ID we can remember
effectTarget = Target
; Debug box announces if script has started
Debug.MessageBox("Effect on " + Target)
; The frequency of each increment is modified on the next line both here and in Event OnTimer - the first number in the parentheses controls the frequency of application. So a Magic Effect lasting ten seconds with 1.0 frequency will apply ten times in this example.
StartTimer(1.0, 10)
endEvent


Event OnTimer(int aiTimerID)
Event OnEffectStart(Actor akTarget, Actor akCaster)
akEffectTarget = akTarget ; We store this here so that the timer event has access to the target


; The next line increments; you can use any values or math in general that you want here. The point is that each time the script look comes to this point it adds onto Increment
        if(fInitialAmount)
Increment = Increment + 1
            akTarget.SetValue(akSomeActorValue, fInitialAmount)
        endif


; The next line applies the incremented Increment to the target NPC's actor value.  
; This script will continue applying the fChangeBy amount every fFrequency seconds until the effect wears off, so a Magic Effect lasting ten seconds with 1.0 frequency will apply ten times in this example.
effectTarget.SetValue(ActionPoints, Increment)
StartTimer(fFrequency, iChangeTimerID)
 
endEvent
; Debug announces incrementing; remove if script is working.
Debug.MessageBox(effectTarget.GetValue(ActionPoints))


; The next line restarts the loop
Event OnTimer(int aiTimerID)
StartTimer(1.0, 10)
        if(aiTimerID == iChangeTimerID)
 
            ; Change the value by adding the change amount to the current value, the fChangeBy is negative, it will reduce the value
If aiTimerID == aaaIncrementTimerID ; The five second timer we started just expired
            akEffectTarget.SetValue(avSomeActorValue, akEffectTarget.GetValue(avSomeActorValue) + fChangeBy)
 
EndIf


            StartTimer(fFrequency, iChangeTimerID) ; Start the timer again
endif
EndEvent
EndEvent


; It's important leave this event block in so that effectTarget gets cleaed out of the memory when the effect completes. It can also be used to add any final effects
; It's important leave this event block in so that effectTarget gets cleaed out of the memory when the effect completes. It can also be used to add any final effects
Event OnEffectFinish(Actor akTarget, Actor akCaster)
Event OnEffectFinish(Actor akTarget, Actor akCaster)
EffectTarget = None
EffectTarget = None
EndEvent
EndEvent


Anonymous user