#include "nw_i0_plot"

// Function to check combat status and change faction/despawn if not in combat
void DespawnIfNotInCombat(object oCreature)
{
    if (!GetIsInCombat(oCreature))
    {
        // Creature is not in combat, change its faction to Defender
        object oDefenderFaction = GetObjectByTag("DEFENDER_FACTION_MEMBER");
        if (GetIsObjectValid(oDefenderFaction))
        {
            ChangeFaction(oCreature, oDefenderFaction);
        }

        // Now despawn the creature
        DestroyObject(oCreature);
    }
    else
    {
        // Creature is still in combat, check again after the next combat round
        DelayCommand(6.0, DespawnIfNotInCombat(oCreature)); // 6 seconds is a typical combat round duration
    }
}

// Main script for OnCombatRoundEnd event
void main()
{
    // Call the function to check combat status and despawn if not in combat
    DespawnIfNotInCombat(OBJECT_SELF);
}
