Difference between revisions of "Scripting MagicEffect"
→Script
imported>Qazaaq |
imported>Kalevala (→Script) |
||
Line 7: | Line 7: | ||
==Script== | ==Script== | ||
<source lang="papyrus"> | <source lang="papyrus"> | ||
Scriptname | Scriptname change_value_over_time extends activemagiceffect | ||
ActorValue Property | ActorValue Property avSomeActorValue Auto Const | ||
Actor | { The actor value you want this script to modify } | ||
Actor akEffectTarget | |||
Float Property fChangeBy Auto | |||
{ 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 iChangeTimerID = 10 ; Give our timer an ID we can remember | |||
; | |||
Event | Event OnEffectStart(Actor akTarget, Actor akCaster) | ||
akEffectTarget = akTarget ; We store this here so that the timer event has access to the target | |||
if(fInitialAmount) | |||
akTarget.SetValue(akSomeActorValue, fInitialAmount) | |||
endif | |||
; | ; 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. | ||
StartTimer(fFrequency, iChangeTimerID) | |||
endEvent | |||
Event OnTimer(int aiTimerID) | |||
if(aiTimerID == iChangeTimerID) | |||
; Change the value by adding the change amount to the current value, the fChangeBy is negative, it will reduce the value | |||
akEffectTarget.SetValue(avSomeActorValue, akEffectTarget.GetValue(avSomeActorValue) + fChangeBy) | |||
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 | ||