void main()
{
    object oSelf = OBJECT_SELF;
    object oCasinoArea = GetArea(oSelf);

    int nLastGameTime = GetLocalInt(oCasinoArea, "LAST_GAME_TIME");
    int nCurrentTime = GetTime();

    // Check if 45 seconds have passed
    if(nCurrentTime - nLastGameTime < 45)
    {
        SendMessageToPC(GetFirstPC(), "Please wait before starting a new game.");
        return;
    }


{
    object oSelf = OBJECT_SELF;
    object oCasinoArea = GetArea(oSelf); // Get the area of the casino

    effect eLightSmall = EffectVisualEffect(VFX_COM_HIT_FIRE);
    effect eFinalEffect = EffectVisualEffect(769); // Big combust effect

    vector vPos;
    vector vPC = GetPosition(oSelf);

    location lStar;

    int iCount;
    int iRand = d4(1) + 2; // This can be adjusted if needed
    int iStopPoint = Random(12) + 1; // Random stop point between 1 and 12

    float fD;
    float fS = 2.5;
    float fTimer = 0.08;
    float fDelay = 0.03;

    // Set stop point on self for reference in reward script
    SetLocalInt(OBJECT_SELF, "WHEEL_STOP_POINT", iStopPoint);

    // Calculate the time to announce and apply the final effect
    float fAnnounceTime = fTimer + (iRand * 360.0 / 18.0 * fDelay);

    // Schedule the announcement and final effect
    DelayCommand(fAnnounceTime, ActionSpeakString("The fires have ended on the number " + IntToString(iStopPoint) + "!"));
    DelayCommand(fAnnounceTime, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eFinalEffect, Location(oCasinoArea, GetPosition(oSelf), 0.0)));

    // Execute the reward script for each player in the casino area at the end
    DelayCommand(fAnnounceTime, ExecuteScript("cas_wheelreward", OBJECT_SELF));

    for (iCount = 0; iCount < iRand; iCount++)
    {
        for(fD = 0.0; fD < 360.0; fD += 18.0)
        {
            vPos = Vector(vPC.x + sin(fD) * fS,
                         vPC.y + cos(fD) * fS, vPC.z + 0.1);

            lStar = Location(oCasinoArea, vPos, 0.0);

            DelayCommand(fTimer, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eLightSmall, lStar));

            fDelay = fDelay * 1.02;

            if (fDelay < 0.01) fDelay = 0.01;

            fTimer += fDelay;
        }
    }
}
}



// Additional Script: reward_script.nss
/* 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) < 10.0) // Assuming 10.0 as the proximity range
        {
            // Delete WHEEL_BET variable
            DeleteLocalInt(oPlayer, "WHEEL_BET");
            SendMessageToPC(oPlayer, "WHEEL_BET variable deleted.");

            // Check for correct WHEEL_BET
            int iBet = GetLocalInt(oPlayer, "WHEEL_BET");
            if (iBet == iStopPoint)
            {
                int iBetAmount = GetLocalInt(oPlayer, "WHEEL_BET_AMOUNT");
                int iReward = iBetAmount * 4;
                // Implement your reward logic here, for example:
                // GiveGoldToCreature(oPlayer, iReward);
                SendMessageToPC(oPlayer, "You won " + IntToString(iReward) + " tickets!");
            }
        }
        oPlayer = GetNextPC();
    }
}
 */