Difference between revisions of "Scripting MagicEffect"

135 bytes added ,  13:49, 8 November 2016
imported>Mr6
m
imported>Kalevala
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Scripting_Guides]]
[[Category:Scripting_Guides]]


A page for example scripts for scripts attached to Magic Effects in Fallout 4.
This example script can be attached to a Magic Effect and create a looping incremental effect
 
that will increment for the entire duration of the effect, and then either stop or be removed, depending on user preference.
 
ActionPoints are used here, but any ActorValue - including custom ones - can be applied.
==Example Script: Looping Increment==
 


==Script==
<source lang="papyrus">
<source lang="papyrus">
Scriptname change_value_over_time extends activemagiceffect


Scriptname aaaDynamicIncrementModule extends activemagiceffect
ActorValue Property avSomeActorValue Auto Const
{ The actor value you want this script to modify }
Actor akEffectTarget


; This example script can be attached to a Magic Effect and create a looping incremental effect
Float Property fChangeBy Auto
; that will increment for the entire duration of the effect, and then either stop or be
{ The amount to increment the value by each time, to decrease over time use a negative number }
; removed, depending on user preference.
Float Property fInitialAmount Auto
; By aib, bugs tackled by Nexus kinggath - him, 1, OnTimer, 0
{ The value to set when the effect starts }
Float Property fFrequency Auto
{ Seconds between increments }


; ActionPoints are used here, but any ActorValue - including custom ones - can be applied.


ActorValue Property ActionPoints Auto Const
int iChangeTimerID = 10 ; Give our timer an ID we can remember
Actor EffectTarget


float Increment = 1.0
Event OnEffectStart(Actor akTarget, Actor akCaster)
float IncrementVar = 0.01
akEffectTarget = akTarget ; We store this here so that the timer event has access to the target


int aaaIncrementTimerID = 10 ; Give our timer an ID we can remember
        if(fInitialAmount)
            akTarget.SetValue(akSomeActorValue, fInitialAmount)
        endif


Event OnEffectStart(Actor Target, Actor Caster)
; 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 = Target
StartTimer(fFrequency, iChangeTimerID)
; 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
endEvent


Event OnTimer(int aiTimerID)
Event OnTimer(int aiTimerID)
 
        if(aiTimerID == iChangeTimerID)
; 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
            ; Change the value by adding the change amount to the current value, the fChangeBy is negative, it will reduce the value
Increment = Increment + 1
            akEffectTarget.SetValue(avSomeActorValue, akEffectTarget.GetValue(avSomeActorValue) + fChangeBy)
 
; The next line applies the incremented Increment to the target NPC's actor value.
effectTarget.SetValue(ActionPoints, Increment)
 
; Debug announces incrementing; remove if script is working.
Debug.MessageBox(effectTarget.GetValue(ActionPoints))
 
; The next line restarts the loop
StartTimer(1.0, 10)
 
If aiTimerID == aaaIncrementTimerID ; The five second timer we started just expired
 
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