#include "inc_debug"
#include "s_mmm_inc"

void main()
{
    object oArea = OBJECT_SELF;
    object oExitingCreature = GetExitingObject();

    // Check if the exiting object is a PC
    if (!GetIsPC(oExitingCreature))
    {
        return; // Only act when a player leaves
    }

    // Loop through all objects in the area to check for remaining players
    object oPlayer = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oPlayer))
    {
        if (GetIsPC(oPlayer)) // Found a PC still in the area
        {
            return; // Players are still inside, don't destroy
        }
        oPlayer = GetNextObjectInArea(oArea);
    }

    // No players left inside the area, destroy it and notify the exiting player
    DestroyArea(oArea);
    SendMessageToPC(oExitingCreature, "All players have left. The CTF Tent area has been destroyed.");
}
