void SpawnFloor(string sResRef, string sSpawnTag, object oArea)
{
    // Get the waypoint to spawn at within the specified area
    object oWaypoint = GetNearestObjectByTag(sSpawnTag, oArea);

    // Check if the waypoint is valid
    if (GetIsObjectValid(oWaypoint))
    {
        // Create the placeable at the waypoint
        CreateObject(OBJECT_TYPE_PLACEABLE, sResRef, GetLocation(oWaypoint));
    }
}

void main()
{
    // Define the tag of the placeable to check
    string sTagToCheck = "I_CAS_FLOOR";
    string sSpawnTag = "SPAWN_FLOOR_HERE";
    string sResRef = "cas_floortile";

    // Get the area of the speaker (usually the NPC or the player)
    object oArea = GetArea(OBJECT_SELF);

    // Get the object to be checked
    object oPlaceable = GetNearestObjectByTag(sTagToCheck, OBJECT_SELF);

    // Check if the object is valid and in the same area
    if (GetIsObjectValid(oPlaceable) && GetArea(oPlaceable) == oArea)
    {
        // Delete the existing placeable
        DestroyObject(oPlaceable);

        // Set a delay to spawn a new placeable
        DelayCommand(2.0, SpawnFloor(sResRef, sSpawnTag, oArea));
    }
    else
    {
        // If no placeable is found, spawn a new one immediately
        SpawnFloor(sResRef, sSpawnTag, oArea);
    }
}

// Function to spawn a floor tile

