Is it possible to remove a spell from an NPC from OnSpellCas

Post » Thu Jun 21, 2012 10:52 am

I'm trying to remove a spell after it is cast by the NPC. I put this simple script on the NPC:

RemoveSpell extends ObjectReference  Event OnSpellCast (Form akSpell)   Self.RemoveSpell (akSpell)endEvent

But I get back this error when compiling:

(4,8): RemoveSpell is not a function or does not exist

Not very good at this stuff, so if someone could tell me how to get something like this to work I would be happy. I can get it to work from a "magic effect" instead of from the NPC, but I would like it done at the NPC level.

EDIT: Okay I think I understand why it's not working. It's referring to an object casting a spell and not an actor, I think. Still not sure how to fix it, though.
User avatar
Steve Fallon
 
Posts: 3503
Joined: Thu Aug 23, 2007 12:29 am

Post » Thu Jun 21, 2012 2:10 am

Try changing akspell to a property and selecting the spell you want removed.

Scriptname RemoveSpell extends ObjectReference   spell property removewhatEvent OnSpellCast (Form akSpell)    Self.RemoveSpell (removewhat)endEvent
User avatar
courtnay
 
Posts: 3412
Joined: Sun Nov 05, 2006 8:49 pm

Post » Thu Jun 21, 2012 5:58 am

RemoveSpell is a function on the Actor Script, so your script would need to extend Actor?

Scriptname SpellRemovalScript extends ActorEvent OnSpellCast (Form akSpell)   Self.RemoveSpell (akSpell as Spell)endEvent
This script would remove every spell the actor casts after he/she casts it, 3djake's suggestion would let you specify a single spell for removal
User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am

Post » Thu Jun 21, 2012 6:17 am

Ok, that works perfectly. Thank you cscottydont!

My problem was I was using (akSpell) instead of (akSpell as Spell). I'm not really sure why you have to add the "as Spell"? Do you know?
User avatar
Terry
 
Posts: 3368
Joined: Mon Jul 09, 2007 1:21 am

Post » Thu Jun 21, 2012 12:50 am

yes as a matter of fact I do!

in this bit
Event OnSpellCast (Form akSpell)
the...thing that is triggering this event is of type Form

and in this bit
Self.RemoveSpell (akSpell as Spell)
the function "RemoveSpell" is looking for a thing of type Spell

so the variable "akSpell" starts out as a Form and you have to specifically say that you're using it as a Spell instead

you can tell what types of variables functions and events are using by the prefix(? or whatever you want to call it) that comes before the variable
In this case it is Form for http://www.creationkit.com/OnSpellCast_-_ObjectReference and Spell for http://www.creationkit.com/RemoveSpell_-_Actor
User avatar
Yvonne Gruening
 
Posts: 3503
Joined: Mon Apr 23, 2007 7:31 pm

Post » Thu Jun 21, 2012 2:07 am

Oh, okay I see it now. It's defined as a "form" instead of a "spell" in the OnSpellCast event.

I'm sure that will help me in the future. Thanks again!
User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm


Return to V - Skyrim