[Solved] How to get rid of unlimited encounters

Sometimes I play modules where encounters are PEST. They are set to “continuous” and unlimited spawn.

I tried to develop a tool to get rid of them, but

  • Setting them to inactive doesn’t help, they activate themselves after the Respawn Time lapses
  • Seemingly they cant be destroyed, DestroyObject doesn’t work

So is there any way to “supress” them?

This would be great. I have dismissed so many modules because of it!

I’ve no experience of this, but did you try SetEncounterSpawnsMax?

Maybe in combination with SetEncounterSpawnsCurrent?

I assume your tools operates before the OnEnter event.

1 Like

Very well, this seems to be the solution.

The function seems to return -1 on encounters with unlimited spawn. That are the ones I want to catch. This clue is not in the lexicon.

Setting it to 0 seems to prevent, that the encounter is activated again after the given time.

However, automatic reactivating an unlimited encounter after timeout obviously happens only once. If it is active again, you can set it to inactive and it will stay inactive (another clue wich should go to the lexicon).

The following script (triggered by an item with unique power) sets the “EncounterSpawnsMax” to 0 if it is -1, this should stop the unlimited respawn. The active flag isn’t touched, so the encounter is triggered at least once.

// warning: there is a small risk to create plotbreaking issues by deactivating encounters.
void main()
  int nEvent = GetLocalInt(OBJECT_SELF, "X2_L_LAST_ITEM_EVENT");
  if (nEvent != 0) return;

  int i;
  object oPC = GetItemActivator();
  object a = GetArea(oPC);

  SendMessageToPC (oPC, "Looking for encounters");

  object o = GetFirstObjectInArea(a);
  while (GetIsObjectValid(o))
      if (GetObjectType (o) == OBJECT_TYPE_ENCOUNTER)
          SendMessageToPC (oPC, "Found " + GetName(o) + " " + IntToString(GetEncounterActive(o)));
          i = GetEncounterSpawnsMax(o);
          if (i == -1)
              SendMessageToPC (oPC, "Deactivated " + GetName(o));
              SetEncounterSpawnsMax(0, o);
      o = GetNextObjectInArea(a);
1 Like


I would like to get some test results from a third person. Maybe you can eventually tell me your experience?

I do use the SetEncounterSpawnsMax to prevent the vanilla encounters to spawning further after some conditions are met so I can confirm it works if that is what you ask. But I used value of 1 not 0.

1 Like


I guess 0 or 1 doesn’t make much of a difference. The encounter spawns once anyway.

So sorry, Mmat, I don’t think I’ll be playing NWN for a while now. I will definitely test your script, but it will take some time before I do!

Well, thanks anyway. Shadow already confirmed that it will work.