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);
}
}
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.