Adding Spells to Actors Using Scripts

Post » Thu Jan 21, 2010 1:01 pm

I am wanting to know the best method to go about adding spells to NPCs and Creatures without having to add them manually to each one. Currently I have this script constantly running in the background of my mod:

Begin AI_Attack        Short HasSpell        Float HasWeaponDrawn        Float HasHealth        Float Timer        long AIRef ;change the variables to whatever you want        long tmp        ifx ( AIRef )                setx AIRef to xNextRef AIRef ;finds the next NPC or creature in the cell        else                setx AIRef to xFirstNPC ;finds the first NPC or creature in the cell        endif        if ( AIRef == 0 )   ;end of list or empty cell                return        endif        setx tmp to AIRef->xRefType        if ( tmp != 1598246990 ) ;if not type NPC                if ( tmp != 1095062083 ) ;if not type Creature                        return                endif        endif        xSetRef AIRef        set HasSpell to ( Getspell, "Ai Realistic Striking" )        If ( HasSpell != 1 )                if ( MenuMode == 0 )                        AIRef->Addspell, "Ai Realistic Striking"                elseif ( MenuMode == 1 );                        AIRef->Removespell, "Ai Realistic Striking"                endif        endifend


It gets the job done, however it makes Morrowind crash nearly every time you try to re-load a game with the mod enabled if this script was running when saving. Does anyone know of a method to prevent the crashing yet still have the script add that spell to all NPCs and Creatures near the player?
User avatar
sara OMAR
 
Posts: 3451
Joined: Wed Jul 05, 2006 11:18 pm

Post » Thu Jan 21, 2010 8:13 pm

At the top of the script detect loading and set AIRef to 0 when the game is loaded. Info on detecting loading should be in MWSFD
User avatar
Zach Hunter
 
Posts: 3444
Joined: Wed Aug 08, 2007 3:26 pm

Post » Fri Jan 22, 2010 1:49 am

Thanks Yacoby! I'll give it a shot and see how it goes.
User avatar
Kat Lehmann
 
Posts: 3409
Joined: Tue Jun 27, 2006 6:24 am

Post » Fri Jan 22, 2010 5:18 am

        If ( HasSpell != 1 )                if ( MenuMode == 0 )                        AIRef->Addspell, "Ai Realistic Striking"                elseif ( MenuMode == 1 );                        AIRef->Removespell, "Ai Realistic Striking"  ; this removes nothing                endif        endif 
Try something like this
If ( HasSpell )	if ( MenuMode )		AIRef->Removespell "Ai Realistic Striking"	endifelseif ( MenuMode == 0 )	AIRef->Addspell "Ai Realistic Striking"endif

User avatar
Laura Mclean
 
Posts: 3471
Joined: Mon Oct 30, 2006 12:15 pm

Post » Thu Jan 21, 2010 9:49 pm

Thanks. It seems Yacoby's suggestion worked as well as yours Abot.
User avatar
Claudz
 
Posts: 3484
Joined: Thu Sep 07, 2006 5:33 am


Return to III - Morrowind