![]() ![]() |
![]() ![]() Post #1 | |
Newbie In Training Posts: 17 Joined: 23-November 11 ![]() | I made a script where it will attach a searchlight to a police car and will be movable via keys defined in an .ini file. Everything works fine, I just don't know the proper coding/math involved to make the spotlight move when keys are pressed. Can someone correct it for me? CODE {$CLEO} 0000: const INI_File = "CLEO\P_Spotlight.ini" PLAYER_VEHICLE = 0@ ACTIVATE_SPLT = 1@ CAR_SPOT_X = 3@ CAR_SPOT_Y = 4@ CAR_SPOT_Z = 5@ FLOAT_X = 7@ FLOAT_Y = 8@ FLOAT_Z = 9@ KEY_LEFT = 15@ KEY_RIGHT = 16@ KEY_UP = 17@ KEY_DOWN = 18@ INI_Section = 30@s end // const gosub @checkIfINIExists while true wait 0 if Player.Defined(0) then if and // Actor.Driving($PLAYER_ACTOR) 056C: actor $PLAYER_ACTOR driving_police_car 0AB0: key_pressed ACTIVATE_SPLT then gosub @getCoordinatesFromDrivenVehicle 0407: store_coords_to FLOAT_X FLOAT_Y FLOAT_Z from_car PLAYER_VEHICLE with_offset 0.0 5.0 1.0 06C1: create_searchlight 10@ on_car PLAYER_VEHICLE with_offset CAR_SPOT_X CAR_SPOT_Y CAR_SPOT_Z radius 0.125 target FLOAT_X FLOAT_Y FLOAT_Z radius 5.0 // FLOAT_X = 0.0 // FLOAT_Y = 5.0 wait 250 while gosub @checkCarOrKey wait 0 gosub @LeftPressed gosub @RightPressed gosub @UpPressed gosub @DownPressed 0407: store_coords_to FLOAT_X FLOAT_Y FLOAT_Z from_car PLAYER_VEHICLE with_offset FLOAT_X FLOAT_Y 1.0 06B5: set_searchlight 10@ travel_to FLOAT_X FLOAT_Y FLOAT_Z speed 6.0 end 06B2: destroy_searchlight 10@ wait 250 end end end :LeftPressed if and 0AB0: key_pressed KEY_LEFT 8AB0: not key_pressed KEY_RIGHT then FLOAT_X += -0.1 end return :RightPressed if and 0AB0: key_pressed KEY_RIGHT 8AB0: not key_pressed KEY_LEFT then FLOAT_X += 0.1 end return :UpPressed if and 0AB0: key_pressed KEY_UP 8AB0: not key_pressed KEY_DOWN then FLOAT_Y += 0.1 end return :DownPressed if and 0AB0: key_pressed KEY_DOWN 8AB0: not key_pressed KEY_UP then FLOAT_Y += -0.1 end return :checkCarOrKey if Car.Wrecked(PLAYER_VEHICLE) then 059A: return_false else if and Actor.InCar($PLAYER_ACTOR, PLAYER_VEHICLE) 0AB0: key_pressed ACTIVATE_SPLT then 059A: return_false else 0485: return_true end end return :getCoordinatesFromDrivenVehicle 0811: PLAYER_VEHICLE = actor $PLAYER_ACTOR used_car if 0137: car PLAYER_VEHICLE model == #COPCARLA then 06D2: INI_Section = "COPCARLA" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARSF then 06D2: INI_Section = "COPCARSF" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARVG then 06D2: INI_Section = "COPCARVG" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARRU then 06D2: INI_Section = "COPCARRU" // @v = string else if 0137: car PLAYER_VEHICLE model == #ENFORCER then 06D2: INI_Section = "ENFORCER" // @v = string else if 0137: car PLAYER_VEHICLE model == #FBIRANCH then 06D2: INI_Section = "FBIRANCH" // @v = string else if 0137: car PLAYER_VEHICLE model == #FBITRUCK then 06D2: INI_Section = "FBITRUCK" // @v = string else 03E6: remove_text_box 0ACA: show_text_box "This vehicle is compatible with the Police Car Spotlight mod." return end end end end end end end 0AF2: CAR_SPOT_X = get_float_from_ini_file INI_File section INI_Section key "X-Pos" 0AF2: CAR_SPOT_Y = get_float_from_ini_file INI_File section INI_Section key "Y-Pos" 0AF2: CAR_SPOT_Z = get_float_from_ini_file INI_File section INI_Section key "Z-Pos" return :checkIfINIExists if 8AAB: not file_exists INI_File then 03E6: remove_text_box 0ACA: show_text_box "~r~[ERROR]~w~The file P_Spotlight.ini doesn't exist in the CLEO folder. Redownload the mod and extract it to there." 0A93: terminate else 0AF0: ACTIVATE_SPLT = get_int_from_ini_file INI_File section "Keys" key "OnOff" 0AF0: KEY_LEFT = get_int_from_ini_file INI_File section "Keys" key "Left" 0AF0: KEY_RIGHT = get_int_from_ini_file INI_File section "Keys" key "Right" 0AF0: KEY_UP = get_int_from_ini_file INI_File section "Keys" key "Up" 0AF0: KEY_DOWN = get_int_from_ini_file INI_File section "Keys" key "Down" end return |
![]() Post #2 | |
Newbie In Training Posts: 17 Joined: 23-November 11 ![]() | Heres my revised script that works better. How can I add so when the player is driving, the searchlight keeps it's position? When I drive, the searchlight moves/turns to it's target coordinates. Like in this video, when the person drives, the light is stationary. http://youtu.be/2PIqeSjI2gE CODE {$CLEO} 0000: const INI_File = "CLEO\P_Spotlight.ini" PLAYER_VEHICLE = 0@ ACTIVATE_SPLT = 1@ PVEHICLE_SPEED = 2@ CAR_SPOT_X = 3@ CAR_SPOT_Y = 4@ CAR_SPOT_Z = 5@ PVEHICLE_GEAR = 6@ TARGET_X = 7@ TARGET_Y = 8@ TARGET_Z = 9@ KEY_LEFT = 15@ KEY_RIGHT = 16@ KEY_UP = 17@ KEY_DOWN = 18@ INI_Section = 30@s end // const gosub @checkIfINIExists while true wait 0 if Player.Defined(0) then if and // Actor.Driving($PLAYER_ACTOR) 056C: actor $PLAYER_ACTOR driving_police_car 0AB0: key_pressed ACTIVATE_SPLT then // gosub @test // wait 1000000 gosub @getCoordinatesFromDrivenVehicle 0407: store_coords_to TARGET_X TARGET_Y TARGET_Z from_car PLAYER_VEHICLE with_offset 0.0 5.0 1.0 06C1: create_searchlight 10@ on_car PLAYER_VEHICLE with_offset CAR_SPOT_X CAR_SPOT_Y CAR_SPOT_Z radius 0.09 target TARGET_X TARGET_Y TARGET_Z radius 5.0 wait 250 while gosub @checkCarOrKey wait 0 if Actor.InCar($PLAYER_ACTOR, PLAYER_VEHICLE) then 0AD0: show_formatted_text_lowpriority "X: %f Z: %f" time 1 TARGET_X TARGET_Z gosub @LeftPressed gosub @RightPressed gosub @UpPressed gosub @DownPressed gosub @PlayerDriving 06B4: set_searchlight 10@ path_between TARGET_X TARGET_Y TARGET_Z and TARGET_X TARGET_Y TARGET_Z speed 10.5 end end 06B2: destroy_searchlight 10@ wait 250 end end end :test 0811: PLAYER_VEHICLE = actor $PLAYER_ACTOR used_car 0A97: 2@ = car PLAYER_VEHICLE struct 0AC7: 22@ = var 22@ offset 0AA6: call_method 0x6A2210 struct 2@ num_params 2 pop 0 var_pointer 22@ component_ID 18 // component 18 is front windshield; X Y Z stored to 22@ 23@ 24@ 0407: store_coords_to TARGET_X TARGET_Y TARGET_Z from_car PLAYER_VEHICLE with_offset 0.0 5.0 1.0 24@ += 3.0 06C1: create_searchlight 10@ on_car PLAYER_VEHICLE with_offset 22@ 23@ 24@ radius 1.1 target TARGET_X TARGET_Y TARGET_Z radius 5.0 //009A: 25@ = create_actor_pedtype 4 model #MALE01 at 22@ 23@ 24@ return :LeftPressed if and 0AB0: key_pressed KEY_LEFT 8AB0: not key_pressed KEY_RIGHT then TARGET_X += -0.1 end return :RightPressed if and 0AB0: key_pressed KEY_RIGHT 8AB0: not key_pressed KEY_LEFT then TARGET_X += 0.1 end return :UpPressed if and 0AB0: key_pressed KEY_UP 8AB0: not key_pressed KEY_DOWN then TARGET_Z += 0.1 end return :DownPressed if and 0AB0: key_pressed KEY_DOWN 8AB0: not key_pressed KEY_UP then TARGET_Z += -0.1 end return :PlayerDriving 02E3: PVEHICLE_SPEED = car PLAYER_VEHICLE speed 0AB8: get_vehicle PLAYER_VEHICLE current_gear_to PVEHICLE_GEAR if PVEHICLE_SPEED > 0.0 then if PVEHICLE_GEAR == 0 // reversing then 0063: TARGET_X -= PVEHICLE_SPEED // (float) 0063: TARGET_Y -= PVEHICLE_SPEED // (float) else 005B: TARGET_X += PVEHICLE_SPEED // (float) 005B: TARGET_Y += PVEHICLE_SPEED // (float) end // 005B: TARGET_Z += PVEHICLE_SPEED // (float) // 0407: store_coords_to 22@ 23@ 24@ from_car PLAYER_VEHICLE with_offset TARGET_X TARGET_Y TARGET_Z // 06B4: set_searchlight 10@ path_between 22@ 23@ 24@ and 22@ 23@ 24@ speed 10.5 end return :checkCarOrKey if Car.Wrecked(PLAYER_VEHICLE) then 059A: return_false else if and Actor.InCar($PLAYER_ACTOR, PLAYER_VEHICLE) 0AB0: key_pressed ACTIVATE_SPLT then 059A: return_false else 0485: return_true end end return :getCoordinatesFromDrivenVehicle 0811: PLAYER_VEHICLE = actor $PLAYER_ACTOR used_car if 0137: car PLAYER_VEHICLE model == #COPCARLA then 06D2: INI_Section = "COPCARLA" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARSF then 06D2: INI_Section = "COPCARSF" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARVG then 06D2: INI_Section = "COPCARVG" // @v = string else if 0137: car PLAYER_VEHICLE model == #COPCARRU then 06D2: INI_Section = "COPCARRU" // @v = string else if 0137: car PLAYER_VEHICLE model == #ENFORCER then 06D2: INI_Section = "ENFORCER" // @v = string else if 0137: car PLAYER_VEHICLE model == #FBIRANCH then 06D2: INI_Section = "FBIRANCH" // @v = string else if 0137: car PLAYER_VEHICLE model == #FBITRUCK then 06D2: INI_Section = "FBITRUCK" // @v = string else 03E6: remove_text_box 0ACA: show_text_box "This vehicle is compatible with the Police Car Spotlight mod." return end end end end end end end 0AF2: CAR_SPOT_X = get_float_from_ini_file INI_File section INI_Section key "X-Pos" 0AF2: CAR_SPOT_Y = get_float_from_ini_file INI_File section INI_Section key "Y-Pos" 0AF2: CAR_SPOT_Z = get_float_from_ini_file INI_File section INI_Section key "Z-Pos" return :checkIfINIExists if 8AAB: not file_exists INI_File then 03E6: remove_text_box 0ACA: show_text_box "~r~[ERROR]~w~The file P_Spotlight.ini doesn't exist in the CLEO folder. Redownload the mod and extract it to there." 0A93: terminate else 0AF0: ACTIVATE_SPLT = get_int_from_ini_file INI_File section "Keys" key "OnOff" 0AF0: KEY_LEFT = get_int_from_ini_file INI_File section "Keys" key "Left" 0AF0: KEY_RIGHT = get_int_from_ini_file INI_File section "Keys" key "Right" 0AF0: KEY_UP = get_int_from_ini_file INI_File section "Keys" key "Up" 0AF0: KEY_DOWN = get_int_from_ini_file INI_File section "Keys" key "Down" end return This post has been edited by HeresOtis: Jul 14 2012, 06:36 AM |
![]() ![]() |