#include "inc_debug"

#include "inc_x_areas"





// OnExitArea main function
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
    }

    // Check for remaining players in the area
    object oPlayer = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oPlayer))
    {
        if (GetIsPC(oPlayer)) // Found another player inside
        {
            return; // Players still inside; don't destroy the area
        }
        oPlayer = GetNextObjectInArea(oArea);
    }

    // No players left in the area, notify the exiting player and destroy the area after a delay
    float fDelay = 5.0; // Delay destruction for 5 seconds
    SendMessageToPC(oExitingCreature, "All players have left. The CTF Tent area will be destroyed in 5 seconds.");

    // Schedule the destruction of the area after the delay
    DelayCommand(fDelay, DestroyArea(oArea));
}
