Jump to content

Spawning a car in traffic position (+rotation)


Polyvalord

Recommended Posts

Hello,

 

I have been making scripts to spawn various vehicles and there is one issue that I can't resolve.

 

This is the part I spawn a vehicle:

:AMMUVAN_001
0001: wait 120000 ms 
00D6: if 
0256:   player $PLAYER_CHAR defined
004D: jump_if_false @AMMUVAN_200
00D6: if 
0038:   $ONMISSION == 0
004D: jump_if_false @AMMUVAN_200
0208: 7@ = random_float_in_ranges -10.0 10.0 
0007: 8@ = -100.0
0172: 9@ = actor $PLAYER_ACTOR Z_angle
04C4: store_coords_to 11@ 12@ 13@ from_actor $PLAYER_ACTOR with_offset 7@ 8@ 0.0
04D3: get_nearest_car_path_coords_from 11@ 12@ 13@ type 2 store_to 1@ 2@ 3@
0002: jump @AMMUVAN_005

// LOCATIONS
:AMMUVAN_005
00D6: if 21
00FE:   actor $PLAYER_ACTOR sphere 0 in_sphere 2422.0 -2449.0 0.0 radius 150.0 150.0 150.0
00FE:   actor $PLAYER_ACTOR sphere 0 in_sphere 726.0 -1400.0 0.0 radius 150.0 150.0 150.0
004D: jump_if_false @AMMUVAN_200
0002: jump @AMMUVAN_009

:AMMUVAN_009
054C: use_GXT_table 'TC'
03E5: show_text_box 'AMMUV1'
0002: jump @AMMUVAN_010

:AMMUVAN_010
0247: load_model #MALE01
0247: load_model #WMYAMMO
0247: load_model #FLATBED
0247: load_model #COLT45
0247: load_model #M4
0247: load_model 1242
0002: jump @AMMUVAN_020

:AMMUVAN_020
0001: wait 10 ms
00D6: if 25
8248:   not model #MALE01 available
8248:   not model #WMYAMMO available
8248:   not model #FLATBED available
8248:   not model #COLT45 available
8248:   not model #M4 available
8248:   not model 1242 available
004D: jump_if_false @AMMUVAN_030
0002: jump @AMMUVAN_020

:AMMUVAN_030
0506: set_car_model #FLATBED next_variation 0 0
00A5: 5@ = create_car #FLATBED at 1@ 2@ 3@
0175: set_car 5@ Z_angle_to 9@
02AC: set_car 5@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
0519: set_car 5@ locked 1
053F: set_car 5@ tires_vulnerability 0
0423: set_car 5@ improved_handling_to 1.0
0852: set_car 5@ damages_visible 1
0186: 10@ = create_marker_above_car 5@
0165: set_marker 10@ color_to 0
0224: set_car 5@ health_to 1500
0229: set_car 5@ primary_color_to 91 secondary_color_to 1
020A: set_car 5@ door_status_to 1
09C4: set_car 5@ gas_tank_explosion_enabled 0
0249: release_model #FLATBED
0002: jump @AMMUVAN_040

 

'get_nearest_car_path_coords_from' has been working super well to get the nearest path position.

 

Now the issue is how do I place the vehicle on the right side of the road with the right rotation?

 

Using player's rotation is not that great to be fair.

Any help appreciated.

Link to comment
Share on other sites

@Polyvalord 

Have you tried the opcode 03D3
 

03D3: get_route_nearest_for 1@ 2@ 3@ store_to 4@ 5@ 6@ Z_angle_to 7@    //  GET_CLOSEST_CAR_NODE_WITH_HEADING

It should work similar as the 04D3 since they have similar command names (...CLOSEST_CAR_NODE).
Quote:
Returns the position and heading of the closest vehicle path node to the specified position. 
Where heading means an angle.

Also about these lines here:

if 21
if 25

It's an old cond. statement definition. Use either 

if and

or:

if or

I'm not sure what 21 and 25 stand for since those are obsolete.

Link to comment
Share on other sites

22 minutes ago, Jack said:

@Polyvalord 

Have you tried the opcode 03D3
 

03D3: get_route_nearest_for 1@ 2@ 3@ store_to 4@ 5@ 6@ Z_angle_to 7@    //  GET_CLOSEST_CAR_NODE_WITH_HEADING

It should work similar as the 04D3 since they have similar command names (...CLOSEST_CAR_NODE).
Quote:
Returns the position and heading of the closest vehicle path node to the specified position. 
Where heading means an angle.

Also about these lines here:

if 21
if 25

It's an old cond. statement definition. Use either 

if and

or:

if or

I'm not sure what 21 and 25 stand for since those are obsolete.

Ok this is exactly what I needed.

 

For these statements they are OR conditions read from the main script, obsolete but works.

Thanks for the good and quick answer!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.