You're close with your code. I'll retype how I typically do this sort of thing with the while loop. As long as the GetFirst and GetNext functions pass a valid object, the while loop continues thru everything in the area.
void main()
{
object oArea = GetArea(OBJECT_SELF);
object oEncounter = GetFirstObjectInArea(oArea);
while( GetIsObjectValid(oEncounter) )
{
if( GetObjectType(oEncounter) == OBJECT_TYPE_ENCOUNTER )
{
SetEncounterActive(TRUE,oEncounter);
}
oEncounter = GetNextObjectInArea(oArea);
}
}
//**I typed this directly here, so hopefully it compiles and I didn't make any typographical errors.
// Get the first object within oPersistentObject.
// - oPersistentObject
// - nResidentObjectType: OBJECT_TYPE_*
// - nPersistentZone: PERSISTENT_ZONE_ACTIVE. [This could also take the value
// PERSISTENT_ZONE_FOLLOW, but this is no longer used.]
// * Returns OBJECT_INVALID if no object is found.
GetFirstInPersistentObject() is used for AoE (area of effect) spells. I know it seems like the area object would be classified as a persistent object, but it isn't used this way.
EffectAreaOfEffect() creates a persistent object. For example, when you cast entangle, it uses this function. Then entangle uses GetFirstInPersistentObject() to start cycling through objects within the entangle area of effect.