Different effect depending on if spell hits a target or not

Post » Sat Jan 04, 2014 1:24 pm

I want to create a spell that returns the targeted actor, or, if no actor was hit by the spell, return the caster/player.

So far I've made a spell and a magic effect (both are of type "Target Actor"), attached the magic effect to the spell and the following script to the magic effect:

Spoiler
spell property Fireball autoevent OnSpellCast(Form akSpell)		Spell spellCast = akSpell as Spell		if spellCast && spellCast == Fireball		debug.Notification("We just cast a fireball!")	else		debug.Notification("We cast something, but we don't know what it is")	endIf	endEventevent OnEffectStart(actor target, actor caster)		if target == None		debug.Notification("No target")	else		debug.Notification("Target found")	endIf	endEvent

The "OnEffectStart" part works fine, if I target an actor I get the message "Target found", however the "OnSpellCast" doesn't seem to be triggered. Does "OnSpellCast" doesn't trigger because a spell of the type "Target Actor" isn't actually cast when there's no target?

Bascially I look for a way to find out if a targeted spell doesn't hit anything, it doesn't have to use "OnSpellCast".

User avatar
FLYBOYLEAK
 
Posts: 3440
Joined: Tue Oct 30, 2007 6:41 am

Post » Sat Jan 04, 2014 10:55 am

OnSpellCast in this context will only work on the actor who has been hit by the spell. So if you hit a Conjurer, then the next time they cast a spell (if this spell is still active on them), you will see the debug. If you want to detect when the player or caster is casting this spell, you'll have to put a script on them instead. (or just use the caster variable from the OnEffectStart event to detect who casted the spell).

It's unclear to me exactly what you're trying to accomplish though. You just want the spell to do nothing if it doesn't hit an actor? Then just use the OnEffectStart event you already have, and only do your thing when target isn't None.

User avatar
celebrity
 
Posts: 3522
Joined: Mon Jul 02, 2007 12:53 pm

Post » Sat Jan 04, 2014 6:53 am

Thought as much; however this has the issue that the script will run every time any spell is cast and thus unnecessarily reduces performance.

"OnEffectStart" isn't triggered when the spell doesn't hit something, or at least not if the spell has the type "Target Actor". If it's somehow possible to create a spell that activates its effect regardless if it hits something or not than I could solve my problem like this:

Spoiler
actor property chosenActor autoevent OnEffectStart(actor target, actor caster)		if target == None		chosenActor = caster	else		chosenActor = target	endIf	endEvent

Hm, maybe I could create a spell that targets yourself, sets "chosenActor" as caster, then activates a Target Actor spell and if it hits something overwrites "chosenActor" with the target, and then parses "chosenActor".

User avatar
Alina loves Alexandra
 
Posts: 3456
Joined: Mon Jan 01, 2007 7:55 pm

Post » Sat Jan 04, 2014 12:26 pm

There's some possibilities.

Number 1 - try using the OnInit() block instead. This might fire even if the spell doesn't hit anything (not sure about that, but worth a try):

Spoiler
actor property chosenActor autoevent OnInit()  chosenActor = game.getPlayer()  utility.wait(1.0) ;give the spell time to start if it does hit something  ;do whatever you want to do with chosenActor here, it should now equal the target if anything was hit, or else still equal the player.endeventevent OnEffectStart(actor target, actor caster)	  if target    chosenActor = target  endIf	endEvent

Number 2 - and probably the more surefire way to do this without causing performance issues:

-Add an "Equip Ability" to your magic effect for the spell. Then set up your OnSpellCast script in the equip ability. It will only be active while the spell is equipped.

User avatar
Jordyn Youngman
 
Posts: 3396
Joined: Thu Mar 01, 2007 7:54 am


Return to V - Skyrim