Scripting MagicEffect

Revision as of 02:05, 7 November 2016 by imported>Qazaaq (removed user names and moved some script comments to the wiki page.)


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.

Script

Scriptname aaaDynamicIncrementModule extends activemagiceffect

ActorValue Property ActionPoints Auto Const
Actor EffectTarget

float Increment = 1.0
float IncrementVar = 0.01

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

Event OnEffectStart(Actor Target, Actor Caster)
	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)		

;	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
	Increment = Increment + 1

;	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

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
Event OnEffectFinish(Actor akTarget, Actor akCaster)

	EffectTarget = None

EndEvent

Usage

The dynamic Looping Increment script is meant to be used in tandem with Magic Effects; 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.