void RandomSelectAndAnnounce(array aPlayers);


void RandomSelectAndAnnounce(array aPlayers)
{
    int nRandomIndex = Random(GetArraySize(aPlayers));
    string sSelectedPlayer = GetArrayString(aPlayers, nRandomIndex);
    object oBottle = OBJECT_SELF;

    PrintString("Selected player: " + sSelectedPlayer); // Debug message

    // Announce the selected player
    AssignCommand(oBottle, ActionSpeakString(sSelectedPlayer + " has been chosen!"));
}


void main()
{
    object oBottle = OBJECT_SELF; // Assuming this script is attached to the bottle object
    float fRange = 5.0; // Range of 5 meters
    object oPlayer;
    string sPlayerNames = "";
    int i = 1;

    SendMessageToPC(oPlayer,"Bottle script started."); // Debug message

    // Scan for players within 5 meters and build the player names string
    while ((oPlayer = GetNearestObject(OBJECT_TYPE_CREATURE, oBottle, i)) != OBJECT_INVALID)
    {
        if (GetDistanceBetween(oBottle, oPlayer) <= fRange && GetIsPC(oPlayer))
        {
            if (sPlayerNames != "") sPlayerNames += ";";
            sPlayerNames += GetName(oPlayer);
         //   SendMessageToPC(oPlayer,"Added player: " + GetName(oPlayer)); // Debug message
        }
        i++;
    }

    // Convert the string to an array
    array aPlayers = StringToArray(sPlayerNames, ";");
    SendMessageToPC(oPlayer,"Number of players found: " + IntToString(GetArraySize(aPlayers))); // Debug message

    if (GetArraySize(aPlayers) > 0)
    {
        // Announce the bottle spin
        AssignCommand(oBottle, ActionSpeakString("The bottle spins..."));
        DelayCommand(5.0, RandomSelectAndAnnounce(aPlayers)); // Delay of 5 seconds
    }
    else
    {
        SendMessageToPC(oPlayer,"No players found within range."); // Debug message
    }
}
*/

/*

void RandomSelectAndAnnounce(array aPlayers);


void RandomSelectAndAnnounce(array aPlayers)
{
    int nRandomIndex = Random(GetArraySize(aPlayers));
    string sSelectedPlayer = GetArrayString(aPlayers, nRandomIndex);
    object oBottle = OBJECT_SELF;
    object oSpinner = GetPlaceableLastClickedBy();
    string sSpinnerName = GetName(oSpinner);

    PrintString("Selected player: " + sSelectedPlayer); // Debug message

    if(GetLocalInt(oBottle,"Rerolls")>=3)
    {
        AssignCommand(oBottle, ActionSpeakString("No valid targets found!"));
        SetLocalInt(oBottle,"Rerolls",0);
    }
    if(sSelectedPlayer==sSpinnerName)
    {
       RandomSelectAndAnnounce(aPlayers);
       SetLocalInt(oBottle,"Rerolls",GetLocalInt(oBottle,"Rerolls")+1);
    }

    // Announce the selected player
    AssignCommand(oBottle, ActionSpeakString(sSelectedPlayer + " has been chosen! "+sSpinnerName+", tell them if you want a Truth or Dare!"));
    SetLocalInt(oBottle,"Rerolls",0);
}


void main()
{
    object oBottle = OBJECT_SELF; // Assuming this script is attached to the bottle object
    float fRange = 5.0; // Range of 5 meters
    object oPlayer;
    string sPlayerNames = "";
    int i = 1;

    SendMessageToPC(oPlayer,"Bottle script started."); // Debug message

    // Scan for players within 5 meters and build the player names string
    while ((oPlayer = GetNearestObject(OBJECT_TYPE_CREATURE, oBottle, i)) != OBJECT_INVALID)
    {
        if (GetDistanceBetween(oBottle, oPlayer) <= fRange && GetIsPC(oPlayer))
        {
            if (sPlayerNames != "") sPlayerNames += ";";
            sPlayerNames += GetName(oPlayer);
         //   SendMessageToPC(oPlayer,"Added player: " + GetName(oPlayer)); // Debug message
        }
        i++;
    }

    // Convert the string to an array
    array aPlayers = StringToArray(sPlayerNames, ";");
    SendMessageToPC(oPlayer,"Number of players found: " + IntToString(GetArraySize(aPlayers))); // Debug message

    if (GetArraySize(aPlayers) > 0)
    {
        // Announce the bottle spin
        AssignCommand(oBottle, ActionSpeakString("The bottle spins..."));
        DelayCommand(2.0, RandomSelectAndAnnounce(aPlayers)); // Delay of 2 seconds
    }
    else
    {
        SendMessageToPC(oPlayer,"No players found within range."); // Debug message
    }
}

*/

