Making a NPC cast a touch spell in dialogue

Post » Tue Sep 13, 2011 4:16 pm

A little background... I'm trying to make a healer npc cast some touch spells on the player when choosing certain dialog options. I created my npc, a quest that contains his dialog, and some touch spells for cure disease, cure poison, restore health, and restore attributes. I made sure the spells are just normal spells that can be used more than once per day, made them only cost 1 mana to cast, made them novice spells, made them immune to silence, disallowed absorb/reflect, and added them to the NPC's spell list.

When the dialog option for cure poison is chosen, I've got it end the conversation and In the result script I've tried...

cast xCurePoison player
xhealernpc.cast xCurePoison player (this npc ref is the base id)
xhealernpcref.cast xCurePoison player (this npc ref is the named ref for the placed version of the npc)

Neither of these are working to get the npc to cast the spell on the player, no casting animation or anything. So I also tried some other things, I changed the xCurePoison to a target, rather than touch, and that didn't work either. I then tried changing the xCurePoison into a self effect, and the NPC does go through the casting animation and casts the spell on himself. Reading the caveats, I saw it mention that with target spells, npcs will sometimes try to get to touch range to cast it and then give up without casting the spell, but I'm not sure that's what's happening since, being in conversation range, the NPC is already in touch range of the player.


So anyone know why this isn't working, and what I can do to get it working?
User avatar
Johanna Van Drunick
 
Posts: 3437
Joined: Tue Jun 20, 2006 11:40 am

Post » Wed Sep 14, 2011 4:29 am

I don't know why it's not working.

If nobody posts a better solution, here's a couple things you can try:

1. Cast the spell from an activator

Have the dialogue results script moveto a disabled, persistent ref activator from a dummy cell to the NPC, then have the activator cast the spell. You can also let the NPC cast something on himself, so it looks like he's doing something and the spell isn't just coming out of nowhere. For example:

YourActivatorRef.MoveTo xhealernpcxhealernpc.Cast SomeSelfSpellYourActivatorRef.Cast xCurePoision Player


2. Use a script jump

In the results script, set a flag variable in the NPC's script, and have a gamemode block in the NPC's script where the NPC casts the spell on the player if the variable is set. For example:

dialog results:
Set xhealernpc.HealFlag to 1


xhealernpc's base object script:

short HealFlagBegin GameMode	If HealFlag == 1		Cast xCurePoison Player		Set HealFlag to 0	EndIfEnd


Hope that helps.
User avatar
Honey Suckle
 
Posts: 3425
Joined: Wed Sep 27, 2006 4:22 pm

Post » Wed Sep 14, 2011 3:24 am

Hope that helps.


It did help, thank you. I just went ahead and made an activator that casts the spell, and gave the npc a summoning spell for the activator itself, that way it still appears that the npc is casting the spell.
User avatar
victoria gillis
 
Posts: 3329
Joined: Wed Jan 10, 2007 7:50 pm

Post » Tue Sep 13, 2011 9:57 pm

You cannot force NPC to attack another actor "On Que" (at a precise moment) for both arrows and magic.

The best you can do is force them to be in combat and then WAIT for them to decided to shoot an arrow or cast a spell.

Maybe in the future with OBSE there may be a way. But for now the hard code puts up too much of a fight for a modder to do that.

But there are ways to fake it. As you already found out.


A little background... I'm trying to make a healer npc cast some touch spells on the player when choosing certain dialog options. I created my npc, a quest that contains his dialog, and some touch spells for cure disease, cure poison, restore health, and restore attributes. I made sure the spells are just normal spells that can be used more than once per day, made them only cost 1 mana to cast, made them novice spells, made them immune to silence, disallowed absorb/reflect, and added them to the NPC's spell list.

When the dialog option for cure poison is chosen, I've got it end the conversation and In the result script I've tried...

cast xCurePoison player
xhealernpc.cast xCurePoison player (this npc ref is the base id)
xhealernpcref.cast xCurePoison player (this npc ref is the named ref for the placed version of the npc)

Neither of these are working to get the npc to cast the spell on the player, no casting animation or anything. So I also tried some other things, I changed the xCurePoison to a target, rather than touch, and that didn't work either. I then tried changing the xCurePoison into a self effect, and the NPC does go through the casting animation and casts the spell on himself. Reading the caveats, I saw it mention that with target spells, npcs will sometimes try to get to touch range to cast it and then give up without casting the spell, but I'm not sure that's what's happening since, being in conversation range, the NPC is already in touch range of the player.


So anyone know why this isn't working, and what I can do to get it working?

User avatar
Janine Rose
 
Posts: 3428
Joined: Wed Feb 14, 2007 6:59 pm


Return to IV - Oblivion