Okay, so verifying the presence of other PCs in the area. Depending on your setup and/or preferences, I would see two simple possibilities, yet I'm sure there are more.
1- You can replace your script's code with:
void DelChests()
{
object oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC) == OBJECT_SELF) return;
oPC = GetNextPC();
}
DestroyObject(GetObjectByTag("chest1"));
DestroyObject(GetObjectByTag("chest2"));
}
void main()
{
object oPC = GetExitingObject();
if(!GetIsPC(oPC) || GetIsDMPossessed(oPC)) return;
oPC = GetFirstPC();
while(GetIsObjectValid(oPC))
{
if(GetArea(oPC) == OBJECT_SELF) return;
oPC = GetNextPC();
}
DelayCommand(300.0, DelChests());
}
This is tested and works well but it's not very elegant and not the fastest, so:
2- You could put this in the script handling the OnEnter event of your area(s):
void main()
{
object oPC = GetEnteringObject();
if(GetIsPC(oPC) && !GetIsDM(oPC))
SetLocalInt(OBJECT_SELF, "NumPCs", GetLocalInt(OBJECT_SELF, "NumPCs")+1);
}
And then replace your initial script's code with:
void DelChests()
{
if(GetLocalInt(OBJECT_SELF, "NumPCs") > 0) return;
DestroyObject(GetObjectByTag("chest1"));
DestroyObject(GetObjectByTag("chest2"));
}
void main()
{
object oPC = GetExitingObject();
if(!GetIsPC(oPC) || GetIsDMPossessed(oPC)) return;
int nNumPCs = GetLocalInt(OBJECT_SELF, "NumPCs")-1;
if(nNumPCs < 1)
{
DeleteLocalInt(OBJECT_SELF, "NumPCs");
DelayCommand(300.0, DelChests());
}
else SetLocalInt(OBJECT_SELF, "NumPCs", nNumPCs);
}
The difference between both options is that the second one only increments/decrements and reads a variable holding the number of PCs in the area(the variable is deleted once the area is empty of PCs), instead of looping over the PCs. Furthermore, the variable holding the PC number can be useful for other systems such as area spawners and cleaners.
Kato
Modifié par Kato_Yang, 15 novembre 2011 - 09:37 .