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

0000: NOP 

script_name "Startgta4" 

0AF2: 28@ = get_float_from_ini_file "cleo\startconfig.ini" section "settings" key "Volume"
24@ = 3.0
25@ = 6.0
26@ = 15

const
    Check = 21@
end

while true
wait 0 
if
   Player.Defined($PLAYER_CHAR) 
then
    if and
        $ONMISSION == 0
        8741:   not actor $PLAYER_ACTOR busted
        not actor.Dead($PLAYER_ACTOR)
        not Actor.Driving($PLAYER_ACTOR)
        0E49: is_char_entering_any_car $PLAYER_ACTOR
        not is_char_exiting_any_car $PLAYER_ACTOR
    then
        27@ = 0
        while 0EA8: get_any_car_no_save_recursive 27@ progress_to 27@ car_to 6@
        0E12: get_vehicle 6@ subclass_to 1@
            if or
                1@ == 0
                1@ == 9
                1@ == 2
            then
                0A97: 20@ = car 6@ struct
                0A8E: 22@ = 20@ + 0x428 // int
                0A8D: 23@ = read_memory 22@ size 1 virtual_protect 0
                    if or
                        23@ == 0 // garage car engine off
                        23@ == 128 // street car engine off
                        23@ == 160 //  street bike engine off
                        23@ == 32  // garage bike engine off
                    then
                        if and
                            0EE5: locate_char_distance_to_car $PLAYER_ACTOR car 6@ radius 6.0
                            not Car.Wrecked(6@)
                            81F4:   not car 6@ flipped
                            82BF:   not car 6@ sunk
                            8495:   not car 6@ burning
                        then
                            0A97: 1@ = vehicle 6@ struct
                            1@ += 0x138
                            1@ += 0xA4

                    repeat
                    wait 0
                        if
                            056E:   car 6@ defined
                        then
                            067F: set_car 6@ lights 1
                            
                            if
                                0E49: is_char_entering_any_car $PLAYER_ACTOR
                            then
                                0A8C: write_memory 1@ size 1 value 0 virtual_protect 0
                            end

                            //
                            if or
                                23@ == 128
                                23@ == 0
                            then
                                if
                                    00DB:   actor $PLAYER_ACTOR in_car 6@
                                then
                                    0A8C: write_memory 1@ size 1 value 1 virtual_protect 0
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                    0ABF: set_car 6@ engine_state_to 0
                                    041E: set_radio_station 12

                                repeat
                                wait 0
                                04ED: load_animation  "startgta4"
                                until 04EE:   animation "startgta4" loaded

                            // 
                            if
                                23@ == 128
                            then
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_drive"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_L"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_R"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4LOW" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                else
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta41" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                end
                                
                            0AC1: 14@ = load_audio_stream_with_3d_support "CLEO/starter/STARTER.mp3" // IF and SET
                            0AC5: link_3d_audio_stream 14@ to_car 6@
                            0006: TIMERA = 0
                            29@ = 0
                                
                            repeat
                            wait 0
                               if and
                                    0019:   TIMERA > 500
                                    29@ == 0
                                then
                                    29@ = 1
                                    0AAD: set_audio_stream 14@ state 1
                                    0ABC: set_audio_stream 14@ volume 28@
                                end
                                
                                if
                                    0019:   TIMERA > 2100
                                then
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                    0ABF: set_car 6@ engine_state_to 1
                                    067F: set_car 6@ lights 0
                                    wait 500
                                        if
                                            056E:   car 6@ defined
                                        then
                                            0209: 7@ = random_int_in_ranges 0 12
                                            041E: set_radio_station 7@
                                        end
                                    0AAD: set_audio_stream 14@ state 0
                                    0AAE: remove_audio_stream 14@
                                    break
                                end
                                    gosub @In_Car
                                        if
                                            check == false
                                        then
                                            break
                                        end
                            until not player.Defined(0)
                                gosub @Wrong
                                    break
                                
                                
                            // 
                            else
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "KART_drive"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_L"
                                    Actor.Animation($PLAYER_ACTOR) == "KART_R"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4KartG" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                end

                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "CAR_Lsit"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_L"
                                    Actor.Animation($PLAYER_ACTOR) == "Drive_LO_R"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4LOWG" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                else
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4garage" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                end
                                
                            0006: TIMERA = 0

                            repeat
                            wait 0
                                if
                                    0019:   TIMERA > 700
                                then
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                    067F: set_car 6@ lights 0
                                    0ABF: set_car 6@ engine_state_to 1
                                    wait 500
                                        if
                                            056E:   car 6@ defined
                                        then
                                            0209: 7@ = random_int_in_ranges 0 12
                                            041E: set_radio_station 7@
                                        end
                                    break
                                end
                                    gosub @In_Car
                                        if
                                            check == false
                                        then
                                            break
                                        end
                            until not player.Defined(0)
                                gosub @Wrong
                                    break
                            end
                        end
                    end


                            // 
                            if or
                                23@ == 32
                                23@ == 160
                            then
                                if
                                    00DB:   actor $PLAYER_ACTOR in_car 6@
                                then
                                    0A8C: write_memory 1@ size 1 value 1 virtual_protect 0
                                    06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 1
                                    041E: set_radio_station 12
                                    02D4: car 6@ turn_off_engine
                                    
                                repeat
                                wait 0
                                04ED: load_animation  "startgta4"
                                until 04EE:   animation "startgta4" loaded
                                
                                
                                    if or
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Still"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Ride"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Right"
                                        Actor.Animation($PLAYER_ACTOR) == "BIKES_Left"
                                    then
                                        0209: 19@ = random_int_in_ranges 1 3
                                            if
                                                19@ == 1
                                            then
                                                0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes1" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                            else
                                                0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes11" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                            end

                                    0006: TIMERA = 0
                                    29@ = 0


                                    repeat
                                    wait 0
                                            if
                                                0019:   TIMERA > 1050
                                            then
                                                06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                                0209: 7@ = random_int_in_ranges 0 12
                                                041E: set_radio_station 7@
                                                0ABF: set_car 6@ engine_state_to 1
                                                067F: set_car 6@ lights 0
                                                wait 500
                                                    if
                                                        056E:   car 6@ defined
                                                    then
                                                        072A: put_actor $PLAYER_ACTOR into_car 6@ driverseat
                                                        0209: 7@ = random_int_in_ranges 0 12
                                                        041E: set_radio_station 7@
                                                    end
                                                break
                                            end
                                                gosub @In_Car
                                                    if
                                                        check == false
                                                    then
                                                        break
                                                    end
                                                    04BA: set_car 6@ speed_to 0.0
                                    until not player.Defined(0)
                                        gosub @Wrong
                                            break

                            else
                                 0AD1: show_formatted_text_highpriority "bike 2" time 1000
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEH_Left"
                                then
                                    0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes3" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                end
                                
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKEV_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Pizza" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Pizza2" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                    
                                 if or
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "WF_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4Wayfare2" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                if or
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Still"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Ride"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Right"
                                    Actor.Animation($PLAYER_ACTOR) == "BIKED_Left"
                                then
                                    0209: 19@ = random_int_in_ranges 1 3
                                        if
                                            19@ == 1
                                        then
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes2" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        else
                                            0605: actor $PLAYER_ACTOR perform_animation "startgta4bikes22" IFP "startgta4" framedelta 4.0 loop 0 lockX 0 lockY 0 lockF 0 time -1
                                        end
                                    end
                                    
                                0006: TIMERA = 0
                                29@ = 0

                                repeat
                                wait 0
                                        if
                                            0019:   TIMERA > 1050
                                        then
                                            06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
                                            0ABF: set_car 6@ engine_state_to 1
                                            067F: set_car 6@ lights 0
                                            wait 500
                                                if
                                                    056E:   car 6@ defined
                                                then
                                                    072A: put_actor $PLAYER_ACTOR into_car 6@ driverseat
                                                    0209: 7@ = random_int_in_ranges 0 12
                                                    041E: set_radio_station 7@
                                                end
                                            break
                                        end
                                            gosub @In_Car
                                                if
                                                    check == false
                                                then
                                                    break
                                                end
                                                04BA: set_car 6@ speed_to 0.0
                                until not player.Defined(0)
                                    gosub @Wrong
                                        break
                                end
                            end
                        end


                        else
                        break
                        end
                        until not locate_char_distance_to_car $PLAYER_ACTOR car 6@ radius 6.0
                        end
                    end
                end
            end
        end
    end
end

:Wrong
    if
        056E:   car 6@ defined
    then
        067F: set_car 6@ lights 0
    end
06AB: set_actor $PLAYER_ACTOR all_weapons_hidden 0
0687: clear_actor $PLAYER_ACTOR task
0AAE: remove_audio_stream 14@
04EF: release_animation "startgta4"
return
   
   
:In_Car
Check = true
    if or
        Actor.Dead($PLAYER_ACTOR)
        0741:   actor $PLAYER_ACTOR busted
        not Actor.Driving($PLAYER_ACTOR)
        00E1:   player 0 pressed_key 26@
        0E4A: is_char_exiting_any_car $PLAYER_ACTOR
        856E:   not car 6@ defined
    then
        Check = false
    end
return
   
   