Events When Gaining/Losing Associates

One more for all the experts out there. I know (or at least I think I know) there’s no built-in event that fires when an associate joins or leaves a party. I would like to run some code on any associate that joins or leaves the PC’s party when that event occurs. Any feedback on the best way to accomplish this? I want this code to run for any associate, including dominated. Since I may not know what creature it will be run on, the OnSpawn event seems to be out and I have no idea what event to use for leaving the party/losing domination, etc.

I considered heartbeat events, but though that cycling through every party on the server every 6 seconds might be a bit much overhead. Thought?

Well, it should be run when the event happens.
For example if the henchman is added after a conversation, then you add the script there, if it’s added after a certain event, the same, etc…
Domination would be handled on the spell impact script and so on.

Ok, thanks for the input. I think I understand the way to get through the appropriate henchman event. Based on what you said, I should be able to use spellhook to run the scripts on Dominated and Summoned creatures. Given that, is there an event or spell that is fired when attempting to summon a familiar, animal companion or mount (for Paladins)?

So, found some more information to further my quest. I attempted to use the spellhook to at least determine when specific SpellIDs were being case (all summons/familiars/animal companions etc.) have a SpellID. Unfortunately, most of the spells that deal with summons aren’t included in the spellhook because they lack the necessary hook code. Summon creature scrolls and summon shadows are the only two summons types that are included in the spellhook, so that method is out for determining if something was summoned. Any other pointers to figure this one out? Thanks in advance for any help you can provide.

There are no “join party” / “leave party” events because those situations are not spontaneous. All henchmen must go through script and AddHenchman / RemoveHenchman - you wrap your code around those functions.

Other associate types are not deemed important by the game due to their disposable nature. BW even removed the ASSOCIATE_COMMANDs shouts firing when they are unsummoned / released from domination. Result: you cannot trap those situations easily anymore.

You also cannot immediately detect Animal Empathy (radial menu trigger).

For vanilla summons you can override nw_ch_summon_9 (OnSpawn) script. Just run your code in a 1s delay to allow the creature to settle in the area.


Thank for the help. I’m looking at doing something like that, but I need to find all the scripts. The one you mentioned only seems to fire for summons, not for animal companions or familiars, which each have their own default summons scripts (for example, nw_ch_acani9 for my wizard’s familiar, nw_ch_summon_9 for my PM’s undead summons). I haven’t checked on an animal companion spawn script yet. If it’s only those few, it should be easy, just need to do some experimentation to figure it out. Thanks again!

As I work to modify the built-ins, I ran into a problem that I’m sure is simple, but doesn’t seem to be working right for me. My test module uses NWNX2 with the resman plug-in. Although I have nw_ch_acani9 in the external script resources, it still calls the internal version when the familiar is summoned. When I attempted to add the script directly into the module, it still called the original BioWare version instead of my modified version with the same name. Now that I think about it, this is the first time I’ve attempted to override an original script. Can you point me in the right direction to ensure my version is called instead of the original BioWare version? I know the compiled file can be put in a hak or the override directory, but is there a way to do it with resource manager? Thanks!

Ok, I’ll show you how to do this for animal companions for now (next time I’ll show you for summon creature spells, ecc…)

First of all, the “event” script you want to run, I assumed it’s named custom_associate_script and that it’s the one called for all associates when they spawn, I don’t know what’s supposed to happen with it, but that’s besides the point right now.

Second, the script that is called when the animal companion is summoned is called nw_s2_animalcom and this is how it should be modified to achieve what you’re asking for:

void StartupAssociateEvent(object oPC)
    ExecuteScript("custom_associate_script", oANIMAL);

void main()
    object oPC = OBJECT_SELF;
    DelayCommand(0.1, StartupAssociateEvent(oPC));

Something similar is done with the summon familiar, the script called in that case is nw_s2_familiar, there are some minimal differences in the functions and the argument of the GetAssociate you must use (famiiar instead of animal companion), but the rest is pretty much the same.

As for a quick way to retrieve the compiled script to put in the override folder, you can do the following:
While the editor is open and the module where the custom script was saved is open, you can go to the following folder:
Documents/Neverwinter Nights/modules/Temp0

there you will find the compiled scripts (both nss and ncs files) ready to be copied in your override folder.

Don’t close the editor or the module or else the temp folder will disappear, obviously.

It can be but don’t do it. Save the script in your module under the original name (the name the game expects and will pick instead of the default).

Rationale: any vanilla script (i.e. nw_ch_acani9) or 2da you modify and put in override may and will interfere with other modules, with considerable probability of rendering them broken.

On the other hand, if you put a script in a hak, it will be called by the game instead of your version in the module (hak content has priority over the module) and as a bonus you won’t be able to edit any of them directly in the toolset.

Or use nwnexplorer to extract it at any time.

Thanks for the pointers. The only reason I asked about the override is because the modified script didn’t appear to work when I put it inside the module. Maybe I was just being dense, so I’ll try it again tonight. I’m running the test module on NWNX2, so there’s a possibility I didn’t restart the server or save the build. Can you confirm that I need to import the .ncs vs compiling the .nss during build?

Also, Clang, thanks for the pointer to that script. I saw it in the log, but hadn’t gotten around to looking into that one yet. I’ll grab all of the summon scripts tonight and throw that hook into them. Thanks again!

Just wanted to provide an update and some closure. I haven’t attempted to put the override scripts inside the module yet, but I have completed the hook system, which looks a lot like Clang’s examples. Thanks! It works as advertised for all animal companions and familiars. I’ll get the other types of associates done soon. Thanks for all the help and guidance!