This is one possible way to do this.
int GetNumPCsInArea(object oArea)
{
if(!GetIsObjectValid(oArea) || GetArea(oArea) != oArea)
{
return 0;
}
object oPC = GetFirstPC();
int nCount;
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC) == oArea)
{
nCount++;
}
oPC = GetNextPC();
}
return nCount;
}
Just place this function at top of your script and then in your script use:
if(GetNumPCsInArea(oArea) == 0)
Another method using GetNearestCreature, and that method is more efficient, but when we are speaking about such small codes, it don't matter really.
BTW you might consider to postphone the cleaning area to 2minutes after last PC exit area. Quite often, some player enters area again until that, so cleaning could be quite ineffective. (If you delay cleaning, just must then re-check PC count in area!)
Also, good idea is to reset all encounters when you clean monsters, to ensure players won't exploit cleaning area in order to get safely through area to lower floor.
Modifié par ShaDoOoW, 02 août 2010 - 08:14 .