void main()
{
    object oArea = GetArea(OBJECT_SELF);
    object oPlayer = GetFirstPC();
    int iStopPoint = GetLocalInt(OBJECT_SELF, "WHEEL_STOP_POINT");

    while (GetIsObjectValid(oPlayer))
    {
        if (GetDistanceBetween(OBJECT_SELF, oPlayer) < 15.0) // Proximity range
        {
            // Check for correct WHEEL_BET
            int iBet = GetLocalInt(oPlayer, "WHEEL_BET");
            if (iBet == iStopPoint)
            {
                int iBetAmount = GetLocalInt(oPlayer, "WHEEL_BET_AMOUNT");
                int iReward = iBetAmount * 8;

                // Find the I_CAS_HANDLE item
                object oHandle = GetItemPossessedBy(oPlayer, "I_CAS_CASINOHANDLE");
                if (GetIsObjectValid(oHandle))
                {
                    // Increase nCAS_TICKET variable by the amount won
                    int nCurrentTickets = GetLocalInt(oHandle, "nCAS_TICKET");
                    SetLocalInt(oHandle, "nCAS_TICKET", nCurrentTickets + iReward);

                    // Prepare and log the message
                    string sCharacterName = GetName(oPlayer);
                    string sPlayerUsername = GetPCPlayerName(oPlayer);
                    string sCDKey = GetPCPublicCDKey(oPlayer, TRUE); // TRUE for short version of CD key
                    string sLogMessage = "Character: " + sCharacterName + ", Player Name: " + sPlayerUsername + " (" + sCDKey + ") was awarded " + IntToString(iReward) + " tickets. Game: Wheel of Fire.";
                    Log(sLogMessage, "cas");

                    SendMessageToPC(oPlayer, "You won " + IntToString(iReward) + " tickets! Total tickets: " + IntToString(nCurrentTickets + iReward));
                }
                else
                {
                    SendMessageToPC(oPlayer, "No valid token handle found.");
                }
            }

            // Reset the bet variables regardless of whether the bet was correct
            DeleteLocalInt(oPlayer, "WHEEL_BET");
            DeleteLocalInt(oPlayer, "WHEEL_BET_AMOUNT");
            SendMessageToPC(oPlayer, "The number you bet on and the amount has been reset. Please place new bets.");
        }

        oPlayer = GetNextPC();
    }
}
