questions about activeMagicEffect script and spell.cast.

Post » Sat Nov 17, 2012 12:38 pm

im trying to create a spell that uses a empty magic effect with a script attached that will alter the effect of the spell on the fly.

so for instance i add this script to the magic Effect

Scriptname TestMagicCombo extends ActiveMagicEffectimport inputimport Utilityint iHotKey = 257bool bFlameOn = Falsebool bFlamebolt = FalseFloat fPlayerHealthspell Property Togflames Autospell Property ConFire AutoObjectReference Property PlayerTarget AutoEvent OnInit()Debug.Notification("spell initialised")PlayerTarget = Game.GetPlayer()RegisterForSingleUpdate(0.01)EndEventEvent OnUpdate()fPlayerHealth = PlayerTarget.GetActorValuePercentage("Health")bob()RegisterForSingleUpdate(0.01)EndEventFunction bob()While(IsKeyPressed(iHotKey))  if(fPlayerHealth>25)   Togflames.Cast(PlayerTarget)  Else   ConFire.Cast(PlayerTarget)  EndIf  EndWhileendFunction

two problems:
1) the onInit() is never called for the ActiveMagicEffect so you cant use that to set up the script to to work for RegisterForSingleUpdate(), so i need another event to have the script check the players health to the effect that is being cast
2) im not sure if the spell.cast method will act as I want it to, say if I have the two spells be versions of flames (but the ConFire one is more powerful) will it cast the flames the same as if i was using vanilla flames and holding down M1 of M2.

any help on this would be awesome im really interested in trying to create spells that have dynamic effects.
User avatar
Laura Hicks
 
Posts: 3395
Joined: Wed Jun 06, 2007 9:21 am

Post » Sat Nov 17, 2012 4:06 am

also could you change the form of the spell that is equipped on the fly, i.e change the spell from a fire and forget to a concentration spell with a script.

or by using two magic effects on one spell and adding conditions to the effects that check the actors health and if it falls below a set value use alternate spell effect. so if you have full health it acts as a flames spell but if it falls less than 25% it becomes a fire-storm?
User avatar
marie breen
 
Posts: 3388
Joined: Thu Aug 03, 2006 4:50 am

Post » Sat Nov 17, 2012 11:08 am

OnInit is called for ActiveMagicEffect. I have used it to set up my Player variable and arrays. There are lots of functions that don't work when used in the OnInit event, though, I believe because the Self variable isn't fully populated yet. That would explain why RegisterForUpdate is failing, because it is interpreted as Self.RegisterForUpdate.

The best way to do what you're talking about, though, is to create a spell with two magic effects, each with a conditional statement that determines whether or not it fires. You can look at spells like Atronach summons to see how this works. Each Summon spell is actually 2 magic effects, one which casts if you have the Mastery perk, one which casts if you do not. Presumably you could use a similar method to cast different spell effects based on the player's health.
User avatar
Bellismydesi
 
Posts: 3360
Joined: Sun Jun 18, 2006 7:25 am

Post » Sat Nov 17, 2012 11:47 am

yeah it does work with the conditions on the spell with two magic effects but i was trying to do it with a script as if using the conditions you cant change the type of spell, say from a concentration spell to fire and forget, if you have it as a concentration spell and attach the two effects where the second is an effect that is fire and forget (fireball) and the first is concentration (flames) the result is not quite what i would want. it applies the spell type to the effect so you charge up the fireball and release a constant stream of fireballs as long as button is held down would prefer them to act as if the player has equipped a different spell instantaneously.
User avatar
Ella Loapaga
 
Posts: 3376
Joined: Fri Mar 09, 2007 2:45 pm

Post » Sat Nov 17, 2012 12:36 pm

wait now im confused when is the onInit() called by the ActiveMagicEffect? when i run my script the debug message:

Debug.Notification("spell initialised")
is never called
User avatar
Rex Help
 
Posts: 3380
Joined: Mon Jun 18, 2007 6:52 pm

Post » Sat Nov 17, 2012 10:16 am

Don't know what to tell you, I initialize variables in the OnInit event in activemagiceffect scripts and it works fine for me. Never tried debugging or having it do anything that effects the world, though.

Event onInit()  Player = PlayerREF  WallOfWind = New ObjectReference[3]  rPosX = New Float[15]  rPosY = New Float[15]EndEvent

That sort of thing. Works without fail.
User avatar
quinnnn
 
Posts: 3503
Joined: Sat Mar 03, 2007 1:11 pm

Post » Sat Nov 17, 2012 5:36 am

so when doe these get initialised, when you start the game, equip the spell or fire it off? im just confused as to when it gets called.
User avatar
Gaelle Courant
 
Posts: 3465
Joined: Fri Apr 06, 2007 11:06 pm

Post » Sat Nov 17, 2012 9:31 am

also your rmods are outrageously great!!!
User avatar
Setal Vara
 
Posts: 3390
Joined: Thu Nov 16, 2006 1:24 pm

Post » Sat Nov 17, 2012 2:41 pm

Thanks, you're gonna love what I'm working on...

I believe that event fires when the ActiveMagicEffect script starts, just before the OnLoad event when the spell is cast. Onload is return when the 3d for an object is loaded; even if the object has no 3d to load, placing some code in OnInit takes advantage of that fraction of a second delay to get some expensive stuff (Papyrus arrays are horrendously slow to create) done. But, as I said, references to Self don't seem to work right, just straight scripting. I've had problems trying to do anything more complex in OnInit than variable initialization.
User avatar
Jaylene Brower
 
Posts: 3347
Joined: Tue Aug 15, 2006 12:24 pm

Post » Sat Nov 17, 2012 2:47 am

Okay, I had a bit of extra time before leaving for work so I checked this out... Debug.Trace and Debug.Notification BOTH fired in the OnInit event for me. First thing to do is check for typos in your events... the compiler won't complain about Event OInnit(), but it will never get called. If you're sure your code is correct, then it's likely your script isn't being loaded at all because your spell is simply failing silently which happens a LOT and for no apparent reason.

Try some of the following (obviously skipping things that will break your spell):

Edit the spell, delete the Magic Effect link and put it in again.
Make sure the Magic Effect's Magnitude in the Spell is 1 or greater.
Edit the Magic Effect in the Spell, then cancel out. This updates the effect's Area and sometimes fixes this problem.
Edit the Magic Effect directly, and if your spell doesn't require Magnitude, check the "No Magnitude" box.
Do the same for "No Area" and "No Duration". Save and test after each change to see if the script is now getting called.
Try filling ALL the Visual Effect fields in the Magic Effect, even if you don't plan on using them. Test again. If it works, get rid of them again and retest; sometimes that fixes a failing spell.

If NONE of these work, try attaching your script to a vanilla spell that DOES work and matches your Casting Type and Delivery. See if it fires then. If so, then duplicate that spell and modify it to suit your needs.

Also, if you're trying to create a spell that uses an Explosion to place a Marker, try putting the rest of the spell code in the OnLoad event of the Marker. If I were going to write a teleport spell (and, as fate would have it, I am) that's how I'd do it.
User avatar
Eve(G)
 
Posts: 3546
Joined: Tue Oct 23, 2007 11:45 am


Return to V - Skyrim