{$CLEO .cs}
{$USE CLEO+}
{$USE Audio}
{$USE newOpcodes}
{$USE ini}

0000: NOP

script_name "eCoj"

// By ArtemQa146

const
    car_1 = 0@
    music = 31@
    volume_ini = 30@
    price_min = 29@
    check = 28@
    car_id = 27@
    car_id_true = 26@
end

0AF2: volume_ini = read_float_from_ini_file "cleo\Door with chime.ini" section "Settings" key "Volume"
0AF0: price_min = read_int_from_ini_file "cleo\Door with chime.ini" section "Settings" key "Price Minimum"

music = -1
car_id = -1
car_id_true = -1

while true
wait 0
    if
        player.Defined(0)
    then
        0A96: 1@ = ped $PLAYER_ACTOR struct
        0D4E: 1@ = struct 1@ offset 0x58C size 4
        if
            1@ > 0
        then 
            0AEB: car_1 = vehicle_struct 1@ handle
            0E12: get_vehicle car_1 subclass_to 2@
            if and
                2@ == 0
                8119:   not car car_1 wrecked
                0EE5: locate_char_distance_to_car $PLAYER_ACTOR car car_1 radius 25.0
            then
                check = false
                
                0441: 3@ = car car_1 model
                09E1: get_car_model 3@ price_to 4@
                if
                    002D:   4@ >= price_min  // (int)
                then
                    check = true
                end
                
                if
                    car_id == -1
                then
                    0441: car_id = car car_1 model
                    0AD3: 5@v = string_format "%d" car_id
                    0AF0: car_id_true = read_int_from_ini_file "cleo\Door with chime.ini" seaction "Car ID" key 5@v
                    if
                        car_id_true == 1
                    then
                        check = true
                    else
                        if
                            car_id_true == -1
                        then
                            continue
                        end
                    end
                else
                    if
                        803B:   not 3@ == car_id  // (int)
                    then
                        car_id = -1
                    else
                        if
                            car_id_true == 1
                        then
                            check = true
                        else
                            if
                                car_id_true == -1
                            then
                                continue
                            end
                        end
                    end
                end

                
                if
                    check == true
                then
                    095F: get_car car_1 door 2 angle_to 1@
                    095F: get_car car_1 door 3 angle_to 2@
                    if or
                        1@ > 0.2
                        2@ > 0.2
                        1@ < -0.2
                        2@ < -0.2
                    then
                        if
                            music == -1
                        then
                            0AC1: music = load_audio_stream_with_3d_support "sound/dwcsound.mp3" // IF and SET
                            0AC5: link_3d_audio_stream music to_car car_1
                            0AAD: set_audio_stream music state 1
                            0ABC: set_audio_stream music volume volume_ini
                        else
                            0AB9: get_audio_stream music state_to 1@
                            if
                                1@ == -1
                            then
                                0AAD: set_audio_stream music state 1
                            end
                        end
                    else
                        gosub @Remove_Audio
                    end
                else
                    gosub @Remove_Audio
                end
            else
                gosub @Remove_Audio
            end
        end
    end
end

:Remove_Audio
if
    not music == -1
then
    0AB9: get_audio_stream music state_to 1@
    if
        1@ == -1
    then
        0AAE: remove_audio_stream music
        music = -1
    end
end
return