Ok, had a moment and crated a simple despawner. you could easily use this as a template to include an area cleanup. You can merge this into your own area hb, enter, exit event scripts, or you can just place and ExecuteScript on the area.
Here they are.
// k_on_area_enter.nss
void main()
{
int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
object oObject = GetEnteringObject();
if(GetIsPC(oObject))
SetLocalInt(OBJECT_SELF, "PC_COUNT", ++nPCCount);
}
// k_on_area_exit.nss
void main()
{
int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
object oObject = GetExitingObject();
if(GetIsPC(oObject))
SetLocalInt(OBJECT_SELF, "PC_COUNT", --nPCCount);
}
// k_area_hb.nss
void main()
{
int bPROCESS_ONLY_ENCOUNTER_SPAWNS = TRUE;
string sTag = GetTag(OBJECT_SELF);
int nIteration = GetLocalInt(OBJECT_SELF, "ITERATION_"+sTag);
int nPCCount = GetLocalInt(OBJECT_SELF, "PC_COUNT");
if(nPCCount==FALSE)
{
if(nIteration<50)
SetLocalInt(OBJECT_SELF, "ITERATION_"+sTag, ++nIteration);
// destroy only encounter spawns
else if(bPROCESS_ONLY_ENCOUNTER_SPAWNS)
{
object oCreature = GetFirstObjectInArea();
while(oCreature != OBJECT_INVALID)
{
if(GetIsEncounterCreature(oCreature))
{
AssignCommand(oCreature, SetIsDestroyable(1,0,0));
DestroyObject(oCreature);
}
oCreature = GetNextObjectInArea();
}
}
// destroy all creatures, not just encounter spawns
else
{
object oCreature = GetFirstObjectInArea();
while(oCreature != OBJECT_INVALID)
{
if(GetObjectType(oCreature) == OBJECT_TYPE_CREATURE)
{
AssignCommand(oCreature, SetIsDestroyable(1,0,0));
DestroyObject(oCreature);
}
oCreature = GetNextObjectInArea();
}
}
}
//ERROR-Reset the PC count
else if(nPCCount<0)
{
nPCCount = 0;
object oPC = GetFirstPC();
while(oPC != OBJECT_INVALID)
{
if(GetArea(oPC) == OBJECT_SELF)
++nPCCount;
oPC = GetNextPC();
}
SetLocalInt(OBJECT_SELF, "PC_COUNT", nPCCount);
}
// PC's are in the area, reset the iteration count
else
{
if(nIteration)
SetLocalInt(OBJECT_SELF, "ITERATION_"+sTag, 0);
}
}