#include "nw_i0_plot"

void DeleteCreatureByTag(string sTag)
{
    object oCreature = GetObjectByTag(sTag);

    if (GetIsObjectValid(oCreature)) 
    {
        DestroyObject(oCreature);
    }
}

void main() {
    SendMessageToPC(GetFirstPC(), "Red Warrior has died."); // This is no good unless it's just for debugging. GetFirstPC is pretty random who it'll fine. You can use SpeakString instead?
    DelayCommand(6.0, DestroyObject(OBJECT_SELF));

    object oPC = GetFirstPC();
    object oArea = GetArea(OBJECT_SELF);

    // Loop through PCs in the area and process bets
    while (GetIsObjectValid(oPC)) {
        if (GetArea(oPC) == oArea) {
            int nBetOnBlack = GetLocalInt(oPC, "I_BET_ON_BLACK");

            if (nBetOnBlack > 0) {
                SendMessageToPC(oPC, "Rewarding Tickets for Betting on BLACK: " + IntToString(nBetOnBlack));
                CreateItemOnObject("cas_ticket", oPC, nBetOnBlack);
            }

            DeleteLocalInt(oPC, "I_BET_ON_RED");
            DeleteLocalInt(oPC, "I_BET_ON_BLACK");
        }
        oPC = GetNextPC();
    }

    // Check and delete the creatures by tag
    //DeleteCreatureByTag("CAS_ARENARED");
    //DeleteCreatureByTag("CAS_ARENABLACK");
    
    object oHandler = GetLocalObject(OBJECT_SELF, "HANDLER");
    ExecuteScript("cas_clear_arena");
    //DestroyObject(GetNearestObjectByTag("CAS_ARENABLACK"), 6.0);
}