Weird encounter problem

I have a weird problem in my module that I can’t understand. In an area there are four separate rooms with Encounters. All these encounters have their custom tag, resource name and template resref. When you destroy an object in each of these rooms, the encounter in that specific room is set to Active:False through a script.

In the first room everything seems to be working as it should, but in the other three rooms the scripts on the OnDeath of the objects in those separate rooms, where I put the Active:False, doesn’t work. The encounters run again if you walk through those triggers, although the triggers should have been set to inactive. I will try some debugging with SendMessageToPC now but if anyone has any thoughts about this please let me know.

Here’s the scipt for the OnDeath of the object in one of the rooms where it doesn’t work. (Gaah, sometimes it’s so darn hard to explain these problems with text)

void main()

object oBook = OBJECT_SELF;
object oPC = GetLastKiller();

object oEncounter = GetObjectByTag("windel");


object oTarg = GetFirstFactionMember(oPC);

            oTarg = GetNextFactionMember(oPC);


One thing that I KNOW works with this script is that it runs, as the PC gets 120 XP when destroying the object.


So you say that you got 4 identical scripts to this one with just the tag for difference…mmm.
Just like that, did you try “GetNearestObjectByTag” instead ?

Also try to check your object first, to be sure it has been found.

else SendMessageToPC(oPC, "Nope");

Yep, that’s right.

Good suggestion. I’ll try that.

Hmmm. This is really weird. Now in three of the four rooms everything works like it should, and even though I did a SendMessageToPC on the scipt shown here, I did nothing on the others and still all but one work now. Will fiddle on with the last encounter and see if I’ve missed something.

Eh…and now the last one work as well. What did I do? Since it didn’t work at first I incorporated Arlhan’s SendMessage script…and then all of a sudden it worked…
The only logical thing I can think of is that I somehow managed to forget to save and compile the first script, but I don’t think that’s the case. Well, it works now so…NWN2 works in mysterious ways sometimes. :man_shrugging:

Sometimes the compilation process fails and it’s hard to spot. But good to know it works!

1 Like

In rare instances (in my second module I had one of these if I remember correctly) the GetObjectByTag doesn’t quite work. Since it’s quite a lot for the game to search for every object with a tag, maybe that’s what caused this? Still, I have had more problems with GetNearestObjectByTag than GetObjectByTag so I tend to use the latter.


Sometimes it may not be the PC doing the direct killing and is collateral damage. So oPC can be invalid. Perhaps?

Edit: Actually, I may have misread your issue, so ignore this. Just be aware this can happen though.

@Lance_Botelle Hmmm, maybe, but I don’t quite see how that would be in this case. I mean, the PC and its companions are the only ones able to hurt the object I think. Ok, perhaps if there is a spell used that effect a large part of the area. Maybe I should just change oPC to GetFirstPC() instead… Wait a second, when looking at the script the GetLastKiller has nothing to do with SetEncounterActive actually, only to do with the PC receiving XP, so in this case it should not matter if the Encounter is set to active or not.


Yes, that is what I realized after reading your post again. My point was about the oPC can be invalid in other situations like you say. But, in your case it was irrelevant.

Eh. It may have been relevant if using the oPC to get a nearest object relevant to them.

True, but as you can see I used GetObjectByTag and not GetNearestObjectByTag so…


So … exactly!

As I said in my first post (in an edit), my comment was not relevant to your current situation (as I had misread your posts). However, if you did ever use GetNearestObjectByTag, then it could well be relevant.

I nearly deleted my original comment, but left it there as a highlight to a potential issue (similar to you describe) if you ever tried to use the function in that way and if the “killer” was not a PC according to its findings.

It’s not an issue, just a point regarding using the GetLastKiller function. :slight_smile:

I’ve just been testing this again and now it no longer works. This must be a bug in the scripts in some way. I think the only thing I can do at this point is to remove the Encounter Triggers and make my own custom triggers where I have full control over what code I use and spawn the evil creatures that way. I see no other way around it at this point. I even added a script to the OnEnter of the Encounter where it checks if the object with the OnDeath scripts is in the area, and if it’s not, it’s supposed to destroy the Encounter by DestroyObject. But the enemies in the Encounter Trigger just keep respawning. It’s like the game refuses to let me do anything with this.

Try setting the ‘Auto-Reset?’ property to FALSE. I’m pretty sure if that property is set to TRUE, it will cause the encounter to re-activate after the designated amount of seconds in the ‘Auto-reset Delay’ property.

Eh…yes. It’s set to TRUE since I want it to reactivate until you destroy a certain object. When that object is destroyed I set the SetEncounterActive to FALSE, and I’ve even tried to destroy the encounter object, but none of that seems to work. Because of this I will now do a custom trigger for this instead. It seems to be the only way to get rid of this bug/problem.

EDIT: I now made my own series of scripts for this. It took some effort but it was totally worth it since now it seems to work flawlessly, and with my own code I feel like I have total control of what I’m doing and what is happening. So, I exchanged the Encounter Triggers for General Triggers with my own code and did some scripts for the OnDeath of the elementals (mainly setting global ints to FALSE and TRUE) and when the objects were destroyed, instead of doing some SetEncounterActive to FALSE, I instead just set a global int that my General Triggers check for before spawning an enemy elemental. It’s difficult to explain all the details but…well, now it works.

1 Like

You will likey end up doing this more and more … as I discovered the same sort of issues you have throughout the process of building/scripting.