How do continuous script spells work?

Post » Sat Nov 17, 2012 5:17 pm

What exactly goes on when you make a spell with the Concentration casting type and an attached script? Does the script get triggered multiple times, or does it only run once and then terminate? Can the script figure out how long the caster has spent casting the spell?

As a bit of background, I'm trying to turn the Transmute Mineral Ore spell into a concentration spell that will convert minerals until you run out of either minerals or mana. It would also be helpful if I could pop up messages in the corner of the screen about what's being triggered when, but that seems convoluted.
User avatar
Emily Jeffs
 
Posts: 3335
Joined: Thu Nov 02, 2006 10:27 pm

Post » Sat Nov 17, 2012 4:13 pm

I've got a couple of spells that fire timed events while concentrating. It's not too complicated :smile:

Here's the script I use for my Deep Freeze spell:
Spoiler
Scriptname ELEM_Frost_Deepfreeze_Effect_Script extends activemagiceffect{Slows down nearby enemies, effect increases with time};--=== Imports ===--Import UtilityImport Game;--=== Properties ===--Actor Property PlayerREF autoImageSpaceModifier property ELEM_Frost_Deepfreeze1_ISMD autoShaderParticleGeometry Property DeepFreezeParticles autoSpell Property ELEM_Frost_DeepFreezeSlowdownArea_Spell autoGlobalVariable Property ELEM_DeepFreeze_Active auto;--=== Variables ===--Actor PlayerActor TargetBool Casting = True;--=== Events ===--Event OnInit()Player = PlayerRefEndEventEvent onEffectStart(Actor akTarget, Actor akCaster)Debug.Trace(self + ": Casting began!")ELEM_Frost_Deepfreeze1_ISMD.ApplyCrossFade()DeepFreezeParticles.Apply(1.0)While Casting  Wait(1)  If Casting   Debug.Trace("Slowing nearby enemies!")   ELEM_DeepFreeze_Active.SetValue(1)   ELEM_Frost_DeepFreezeSlowDownArea_Spell.Cast(akCaster)  EndIfEndWhileEndEventEvent onEffectFinish(Actor akTarget, Actor akCaster)Casting = FalseDebug.Trace(self + ": Casting ended!")ImageSpaceModifier.RemoveCrossFade(4.0)DeepFreezeParticles.Remove(4.0)Wait(2)ELEM_DeepFreeze_Active.SetValue(0)EndEvent;--=== Functions ===--

As you can see, the onEffectStart event fires when you begin casting the spell, and onEffectFinish fires when you stop casting it. In this case, while the caster is concentrating, another spell called ELEM_Frost_DeepFreezeSlowDownArea_Spell is cast once every second.

You could do something similar to do your transmutation spell and pop up a notification on each iteration of the loop, or just have the actual transmutation spell do the notification.
User avatar
Toby Green
 
Posts: 3365
Joined: Sun May 27, 2007 5:27 pm

Post » Sat Nov 17, 2012 10:49 pm

Oh allright, that looks exactly like what I need. Thanks!
User avatar
Nicholas
 
Posts: 3454
Joined: Wed Jul 04, 2007 12:05 am


Return to V - Skyrim