NPC AI and spells that effect certain types

Post » Sun Sep 01, 2013 5:39 pm

Hello everyone,

I'm in the process of modifying a number of the vanilla companions to be more unique.

First on the list is Lydia, which I want to make more of a Paladin like character. I have a spell that I have created called Divine Aura. This spell is a form of cloak spell that burns undead in melee range.

I have tested the spell and I have successfully made it so the spell only effects undead.

The problem is that Lydia casts the spell no matter which enemy type she is facing.

I would like to make it so that Lydia will only cast Divine Aura if her target is undead.

It has been suggested that I use two combat shouts. One to detect if there are undead nearby, and if so, add the spell to her spell list, and the other shout to remove it if no undead are nearby.

This seems like a heavy handed way of doing it and I am wondering if there is a way of adding a script to the spell that does this detection for Lydia.

Any help you all could give me would be very appreciated.

Thanks,

-Aiden

User avatar
Myles
 
Posts: 3341
Joined: Sun Oct 21, 2007 12:52 pm

Post » Sun Sep 01, 2013 7:21 pm

Well, you could add a script to the spell that will dispel it immediately if there are no undead nearby. This would be doable using getCombatTarget() or FindClosestReferenceOfAnyTypeInListFromRef(), searching for nearby undead actors. However, this might just result in Lydia casting the spell constantly over and over until she's out of magicka. Hard to say for sure.

There are a few other options that might work better though. For instance, you could put Lydia in a reference alias with a script attached to it, and that script can check whenever onCombatStateChanged() whether any undead are nearby, and if so, add the spell until another onCombatStateChanged() event says combat is over, at which time it could be removed again.

Edit: if you want to go with option 1 (a script on the spell), you could try making the spell script dispel itself and add a dummy cloak spell to Lydia if there are no undead nearby, I would guess that the AI would prevent her from casting it again if she already has a cloak effect on her, thus a dummy cloak that's invisible/does nothing may do the trick. You would have to test it though to be sure.

User avatar
Mariana
 
Posts: 3426
Joined: Mon Jun 12, 2006 9:39 pm

Post » Sun Sep 01, 2013 5:55 pm

I'm having difficulty even knowing where to begin. The CK wiki says something about creating a quest.

http://www.creationkit.com/Dynamically_Attaching_Scripts#Set_Up_a_Reference_Alias

User avatar
Brandon Bernardi
 
Posts: 3481
Joined: Tue Sep 25, 2007 9:06 am

Post » Sun Sep 01, 2013 5:23 am

Follow those instructions to set up the Reference Alias, except instead of choosing Specific Reference/PlayerRef, click the button for Unique Actor, and choose HousecarlWhiterun (this is Lydia's editor ID name). You can name the alias whatever you want, the name wont show up in game. You'll then need to attach the script you make to the new reference alias. That script will automatically be attached to Lydia then whenever you load the game.

User avatar
Aliish Sheldonn
 
Posts: 3487
Joined: Fri Feb 16, 2007 3:19 am

Post » Sun Sep 01, 2013 5:13 pm

This script should work if you attach it to the reference alias. Don't forget to fill the script's Properties in the creation kit. It should fill ActorTypeUndead for you automatically if you hit "Auto-fill properties".

Scriptname LydiaSpellAliasScript extends ReferenceAliasKeyword property ActorTypeUndead autoSpell property DivineAura autoEvent OnCombatStateChanged(Actor akTarget, int aeCombatState)  if aeCombatState == 1 ;combat has begun    if akTarget.hasKeyword(ActorTypeUndead)      self.getActorReference().addSpell(DivineAura)    endif  endif  if aeCombatState == 0 ;combat has ended    self.getActorReference().removeSpell(DivineAura)  endifEndEvent
User avatar
Klaire
 
Posts: 3405
Joined: Wed Sep 27, 2006 7:56 am


Return to V - Skyrim