Script to make an NPC cast a specific spell

Post » Tue Jun 19, 2012 1:57 pm

So I want to attach a script to an NPC to make him cast StromThrall at the beginning of combat. He has StormThrall on his spell list. So what I've done so far is open up his npc tab, click add script, click new script, then edit the source of that script. The actor ID is JSReddin. So far I have an uncompleted script, because I have no idea how to do it. This is what I have so far (Yes I understand I didn't finish the Cast part of it). Any help would be greatly appreciated!

Spoiler
Scriptname JSReddinCastSpell extends ObjectReference

Actor Property JSReddin Auto
SPELL Property StormThrall Auto

Event OnCombatStateChanged()
if (JSReddin.GetCombatState() == 1)
StormThrall.Cast(JSReddin)
endif
endEvent


User avatar
Misty lt
 
Posts: 3400
Joined: Mon Dec 25, 2006 10:06 am

Post » Tue Jun 19, 2012 4:26 am

bump
User avatar
JESSE
 
Posts: 3404
Joined: Mon Jul 16, 2007 4:55 am

Post » Tue Jun 19, 2012 2:31 am

Any suggestions?
User avatar
Brian LeHury
 
Posts: 3416
Joined: Tue May 22, 2007 6:54 am

Post » Tue Jun 19, 2012 9:46 am

Instead of using a script you could try setting up a combat interrupt package and using UseMagic procedure to cast it
User avatar
Hearts
 
Posts: 3306
Joined: Sat Oct 20, 2007 1:26 am

Post » Tue Jun 19, 2012 9:50 am

Big question is do you want him to go through the casting animations. If so, you need to use the ai routines and not a script, if the CK wiki is correct.
User avatar
Joie Perez
 
Posts: 3410
Joined: Fri Sep 15, 2006 3:25 pm

Post » Tue Jun 19, 2012 7:58 am

Okay I'll try that. Another question though. Is there any combat package that's already made that makes the NPC use a two handed destruction spell automatically, or a two handed conjuration spell?
User avatar
Darren
 
Posts: 3354
Joined: Wed Jun 06, 2007 2:33 pm

Post » Tue Jun 19, 2012 4:41 am

Fortunately, i tackled and solved this problem a few days ago, just attach a script like this to one of your actors:

Scriptname ActorCombatScript extends Actor;This script will cast the spell 'SpellOfDoom' whenever; this actor enters combatSPELL Property SpellOfDoom  AutoEvent OnCombatStateChanged(Actor akTarget, int aeCombatState)    ;we have entered combat with actor akTarget    if (aeCombatState == 1)       ;equip the spell in your hand first, AI will equip spell in both hands if it has to       ;but otherwise a value of 0 = lefthand, 1= righthand, 2=voice (use this for powers)       EquipSpell(SpellOfDoom,0)	       ;now cast Spell of doom on enemy akTarget. Pass 'self' as the second param to this function if you       ;want to cast a spell like healing or invisibility	DoCombatSpellApply(SpellOfDoom, akTarget)    elseif (aeCombatState == 2)	Debug.Trace("We are searching for the enemy...")	;AI enters this state at the beginning of combat (before it has Line-of-Sight to enemy) also when an enemy runs away or turns a corner	;So this spot would be a good place to cast 'power up' or 'protective' spells    endIfendEvent
User avatar
Amy Masters
 
Posts: 3277
Joined: Thu Jun 22, 2006 10:26 am


Return to V - Skyrim