void AdjustNPCReputation(string sTagNPC1, string sTagNPC2)
{
    object oNPC1 = GetNearestObjectByTag(sTagNPC1);
    object oNPC2 = GetNearestObjectByTag(sTagNPC2);

    if(GetIsObjectValid(oNPC1) && GetIsObjectValid(oNPC2))
    {
        // Adjust reputation to make them hostile towards each other
        AdjustReputation(oNPC1, oNPC2, -100);
        AdjustReputation(oNPC2, oNPC1, -100);

        // Command each NPC to attack the other
        AssignCommand(oNPC1, ActionAttack(oNPC2, TRUE));
        AssignCommand(oNPC2, ActionAttack(oNPC1, TRUE));
    }

    // Schedule this function to be called again in 12 seconds
    DelayCommand(12.0, AdjustNPCReputation(sTagNPC1, sTagNPC2));
}


#include "nw_i0_plot"


void main() {
    // Get the first player character and the area object
    object oPC = GetFirstPC();
    object oArea = GetArea(oPC);

    // Check for PCs in the area with the iAmInArena variable set
    object oCurrentPC = GetFirstPC();
    while (GetIsObjectValid(oCurrentPC)) {
        if (GetArea(oCurrentPC) == oArea) {
            if (GetLocalInt(oCurrentPC, "iAmInArena") == 1) {
                SendMessageToPC(oPC, "You cannot start a  fight if a player is already in the arena.");
                return;
            }
        }
        oCurrentPC = GetNextPC();
    }

    // Initialize the first creature to check in the area
    object oCreature = GetFirstObjectInArea(oArea);

    // Loop through all objects in the area to check for existing creatures
    while (GetIsObjectValid(oCreature)) {
        if (GetObjectType(oCreature) == OBJECT_TYPE_CREATURE) {
            string sTag = GetTag(oCreature);
            if (sTag == "CAS_ARENARED" || sTag == "CAS_ARENABLACK") {
                SendMessageToPC(oPC, "You cannot start a new fight if there is a monster currently in the arena.");
                return;
            }
        }
        oCreature = GetNextObjectInArea(oArea);
    }

    // Get the waypoints
    object oWaypointBlack = GetWaypointByTag("SPAWN_MOB_BLACK");
    object oWaypointRed = GetWaypointByTag("SPAWN_MOB_RED");

    // Check if waypoints are valid
    if(GetIsObjectValid(oWaypointBlack) && GetIsObjectValid(oWaypointRed)) {
        // Spawn the NPCs
        object oNPCBlack = CreateObject(OBJECT_TYPE_CREATURE, "CAS_ARENABLACK", GetLocation(oWaypointBlack));
        object oNPCRed = CreateObject(OBJECT_TYPE_CREATURE, "CAS_ARENARED", GetLocation(oWaypointRed));

        
        DelayCommand(5.0, AdjustNPCReputation("CAS_ARENABLACK", "CAS_ARENARED"));
    }
}

