Difference between revisions of "Scripting MagicEffect"

315 bytes added ,  13:49, 8 November 2016
imported>Qazaaq
m (removed user names and moved some script comments to the wiki page.)
imported>Kalevala
 
(4 intermediate revisions by 2 users not shown)
Line 5: Line 5:
ActionPoints are used here, but any ActorValue - including custom ones - can be applied.
ActionPoints are used here, but any ActorValue - including custom ones - can be applied.


===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)
 
akEffectTarget = None ; This isn't the target sent by the event, just our temporary variable keeping the actor reference. Maintaining references in variables can cause them to persist, it's a good habit to confirm they aren't being kept when no longer needed.
EffectTarget = None
 
EndEvent
EndEvent


</source>
</source>


===Usage===
==Usage==


The dynamic Looping Increment script is meant to be used in tandem with [[Magic Effect]]s; it will increment a chosen Actor Value for the duration of the Magic Effect, at a frequency indicated by the user. This is useful for situations where a magic effect is intended to increase or decrease an actor value within the duration of the effect, rather than immediately "jump" to a particular value as is only allowed for by default behavior.
The dynamic Looping Change script is meant to be used in tandem with [[Magic Effect]]s; it will change a chosen Actor Value for the duration of the Magic Effect, at a frequency indicated by the user. This is useful for situations where a magic effect is intended to increase or decrease an actor value within the duration of the effect, rather than immediately "jump" to a particular value as is only allowed for by default behavior.
Anonymous user