void ExecuteAdjustReputationAndAttack(string sTargetTag)
{
    object oTarget = GetObjectByTag(sTargetTag);

    if(GetIsObjectValid(oTarget))
    {
        SendMessageToPC(GetFirstPC(), "ExecuteAdjustReputationAndAttack: Target found - " + GetName(oTarget));

        // Ensure AI is active
        SetAILevel(OBJECT_SELF, AI_LEVEL_DEFAULT);
        SetAILevel(oTarget, AI_LEVEL_DEFAULT);

        // Clear any current actions
        ClearAllActions();

        // Adjust reputation to make them hostile towards each other
        AdjustReputation(OBJECT_SELF, oTarget, -100);

        // Reconfirm target validity
        if(GetIsObjectValid(oTarget))
        {
            // Command to attack the target
            AssignCommand(OBJECT_SELF, ActionAttack(oTarget));
            SendMessageToPC(GetFirstPC(), "Issued attack command against " + GetName(oTarget));
        }
        else
        {
            SendMessageToPC(GetFirstPC(), "Target became invalid: " + sTargetTag);
        }
    }
    else
    {
        SendMessageToPC(GetFirstPC(), "No valid target found with tag: " + sTargetTag);
    }
}

void AdjustReputationAndAttack(string sTargetTag)
{
    SendMessageToPC(GetFirstPC(), "AdjustReputationAndAttack: Waiting 2 seconds before executing...");

    // Delay the retrieval of the target object and subsequent actions
    DelayCommand(2.0, ExecuteAdjustReputationAndAttack(sTargetTag));
}

void main()
{
    SendMessageToPC(GetFirstPC(), "OnSpawn script triggered.");

    // Retrieve the tag of the target from the local string variable
    string sTagOfTarget = GetLocalString(OBJECT_SELF, "CAS_ATTACKMOB");
    SendMessageToPC(GetFirstPC(), "Target tag to look for: " + sTagOfTarget);

    // Check if the tag is not empty
    if(sTagOfTarget != "")
    {
        SendMessageToPC(GetFirstPC(), "Starting AdjustReputationAndAttack in 6 seconds.");
        
        // Delay 6 seconds, then adjust reputation and attack
        DelayCommand(1.0, AdjustReputationAndAttack(sTagOfTarget));
    }
    else
    {
        SendMessageToPC(GetFirstPC(), "No target tag set on this creature.");
    }
} 
