Aller au contenu

Photo

INFO: How to Force Spell Hooking For AI PC/NPC Spell Casting


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi All,

I was unaware of this until I discovered my spell hook code not working for NPCs (or companions using AI) casting spells: Spell hooking does not work for NPCs/PCs not controlled by the player.

In other words, if you have some spell hook code that you want to fire (irrespective of who is casting the spell), then it will not fire if neither the player or DM are controlling the caster. This also means spells cast by companions while using AI rather than the player controlling them will not fire your spell hook code.

The workaround is to add the following line of code to every area OnEnter:

// FORCE SPELL HOOK CODE TO WORK ON NPCS (FOR AI CASTING AS WELL)
 object oCreature = GetEnteringObject();
object oArea = GetArea(oCreature);
 SetLocalInt(oArea, "X2_L_WILD_MAGIC", 1); // SEE x2_inc_spellhook

It may be something that only I am concerned about, but may be of interest to other builders who also want their spell hook code to work no matter who or what is casting the said spell.

Lance.

Modifié par Lance Botelle, 14 février 2011 - 08:17 .


#2
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
Redo your x2_inc_spellhook, lot easier to fix there. ( line 261 )



Has some nonsense about dm possessed, but no check for being a dm. I'd be leery of setting an area to be wildmagic, even though that is likely only in a custom spell hook. You just need to make sure you check for NPC's in your spellhook since they are using dumber AI and should be able to cheat some.

#3
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages

painofdungeoneternal wrote...

Redo your x2_inc_spellhook, lot easier to fix there. ( line 261 )

Has some nonsense about dm possessed, but no check for being a dm. I'd be leery of setting an area to be wildmagic, even though that is likely only in a custom spell hook. You just need to make sure you check for NPC's in your spellhook since they are using dumber AI and should be able to cheat some.


Hi painofdungeoneternal,

I do not like to have to alter OC include files unless I really have to.

As far as I can see, there is no other benefit to having this variable set than to allow spell hooking as my mod stands at the moment.

It's more about the fact that companions using AI to cast spells will not have the spell hook code fire when this is not set than allowing "NPC's being able to cheat some" ... if you see what I mean?

Lance.

Modifié par Lance Botelle, 14 février 2011 - 08:51 .


#4
painofdungeoneternal

painofdungeoneternal
  • Members
  • 1 799 messages
Then do this in module load, pcloaded, or some such event that runs once, just do it once and not repeatedly.



object oArea = GetFirstArea();
while ( GetIsObjectValid(oArea) )
{
  SetLocalInt(oArea, "X2_L_WILD_MAGIC", TRUE );		
  oArea = GetNextArea();
}



This will set all the areas as you want with that var, and not put overhead happening all over the place.



( And as you learn more you will find you don't really have a choice but to modify those OC scripts, it starts out being one little thing at a time, but you end up realizing you have to fix it IF you actually study how it's working. The determining factor is how much knowledge you have, eventually you will conclude you need to just replace all of it so it works correctly instead of playing whack-a-mole as new issues show up caused core issues inherent in those scripts written by every summer intern who worked for obsidian, bioware and stormfront ( and prolly even older than that ) )

#5
Lance Botelle

Lance Botelle
  • Members
  • 1 480 messages
Hi painofdungeoneternal,

Fair comment. :) I have done the same. (I realised the ease of this afterwards.)

I know what you mean about possibly having to modify the include scripts eventually anyway - I have already altered a few ... I just want to keep it to a minimum if possible. :)

Lance.

Modifié par Lance Botelle, 14 février 2011 - 10:39 .


#6
The Fred

The Fred
  • Members
  • 2 516 messages
It's better to change the include, but that then requires that you recompile each and every script in the game. Luckily you can normally get by without doing it.



As for the Wild Magic flag, you can manually set it on areas anyway, meaning that you don't need to have them all call a special piece of script. However, looping through them all is much nicer. I didn't know we actually had GetFirst/NextArea() functions, though... maybe they were added for NWN2, but I remember having exactly this problem in NWN1 and being highly frustrated with BioWare for adding such a cool system but building it in such a way that it's not actually useful. ;-)