Jump to content

How to spawn cars


Recommended Posts

Simple as the topic sounds,

 

I need to spawn a car... a RANDOM car at a position.

 

How do I code the RANDOM part of the script?

 

I mean is there a get_random_car blah blah opcode?

 

P.S. this should work even if there are no other cars in the vicinity

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/
Share on other sites

Simple as the topic sounds,

 

I need to spawn a car... a RANDOM car at a position.

 

How do I code the RANDOM part of the script?

 

I mean is there a get_random_car blah blah opcode?

 

P.S. this should work even if there are no other cars in the vicinity

:CAR_504

0001: wait 0 ms

0004: $CRIMINAL_CAR = -1

04C4: store_coords_to $LC1 $LC2 $LC3 from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0

073E: get_car_in_sphere $LC1 $LC2 $LC3 radius 34.0 model -1 handle_as $CRIMINAL_CAR

00D6: if

8038: not $CRIMINAL_CAR == -1

004D: jump_if_false @CAR_504

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785721
Share on other sites

 

QUOTE (Glenstorm @ Feb 18 2010, 11:45)

Simple as the topic sounds,

 

I need to spawn a car... a RANDOM car at a position.

 

How do I code the RANDOM part of the script?

 

I mean is there a get_random_car blah blah opcode?

 

P.S. this should work even if there are no other cars in the vicinity

 

:CAR_504

0001: wait 0 ms

0004: $CRIMINAL_CAR = -1

04C4: store_coords_to $LC1 $LC2 $LC3 from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0

073E: get_car_in_sphere $LC1 $LC2 $LC3 radius 34.0 model -1 handle_as $CRIMINAL_CAR

00D6: if

8038: not $CRIMINAL_CAR == -1

004D: jump_if_false @CAR_504

 

Can you explain how that works?

 

I need a complete random spawn, not specific,for example like the firefighter or vigilante missions

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785736
Share on other sites

QUOTE (Glenstorm @ Feb 18 2010, 11:45)

Simple as the topic sounds,

 

I need to spawn a car... a RANDOM car at a position.

 

How do I code the RANDOM part of the script?

 

I mean is there a get_random_car blah blah opcode?

 

P.S. this should work even if there are no other cars in the vicinity

 

:CAR_504

0001: wait 0 ms

0004: $CRIMINAL_CAR = -1

04C4: store_coords_to $LC1 $LC2 $LC3 from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0

073E: get_car_in_sphere $LC1 $LC2 $LC3 radius 34.0 model -1 handle_as $CRIMINAL_CAR

00D6: if

8038: not $CRIMINAL_CAR == -1

004D: jump_if_false @CAR_504

 

Can you explain how that works?

 

I need a complete random spawn, not specific,for example like the firefighter or vigilante missions

what do u need to do

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785745
Share on other sites

There'd ya go.

var   $PLAYER_CHAR: player   $PLAYER_ACTOR: actor   0@: car   1@: int   2@: int   3@: float   4@: float   5@: float   6@: float   7@: float   8@: float   9@: float   10@: float   11@: float   20@: float   21@: int   22@: carendconst   RND_A = 3@   RND_X = 4@   RND_Y = 5@   RND_Z = 6@   VAN_X = 7@   VAN_Y = 8@   VAN_Z = 9@   RND_SINE = 10@   RND_COSINE = 11@   VAN_A = 20@   CARM = 21@   CAR = 22@endwhile true   wait 0   Actor.StorePos($PLAYER_ACTOR, RND_X, RND_Y, RND_Z)   RND_A = random(0.0, 180.0)   02F7: RND_SINE = sine RND_A // (float)   02F6: RND_COSINE = cosine RND_A // (float)   RND_A = random(250.0, 600.0)   RND_SINE *= RND_A                  RND_A = random(250.0, 600.0)   RND_COSINE *= RND_A   RND_X += RND_SINE   RND_Y += RND_COSINE   03D3: get_route_nearest_for RND_X RND_Y RND_Z store_to VAN_X VAN_Y VAN_Z Z_angle_to VAN_A    if       00C2:   sphere_onscreen VAN_X VAN_Y VAN_Z radius 5.0   then       continue   end      CARM = random(#LANDSTAL, #UTILTR1)   Model.Load(CARM)   while not Model.Available(CARM)       wait 0    end   Car.Create(CAR, VAN_X, VAN_Y, VAN_Z)   Car.Angle(CAR) = VAN_A   0587: enable_car CAR validate_position 0    Model.Destroy(CARM)   breakend

 

Edited by gtasearcher
Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785758
Share on other sites

There'd ya go.
var   $PLAYER_CHAR: player   $PLAYER_ACTOR: actor   0@: car   1@: int   2@: int   3@: float   4@: float   5@: float   6@: float   7@: float   8@: float   9@: float   10@: float   11@: float   20@: float   21@: int   22@: carendconst   RND_A = 3@   RND_X = 4@   RND_Y = 5@   RND_Z = 6@   VAN_X = 7@   VAN_Y = 8@   VAN_Z = 9@   RND_SINE = 10@   RND_COSINE = 11@   VAN_A = 20@   CARM = 21@   CAR = 22@endwhile true   wait 0   Actor.StorePos($PLAYER_ACTOR, RND_X, RND_Y, RND_Z)   RND_A = random(0.0, 180.0)   02F7: RND_SINE = sine RND_A // (float)   02F6: RND_COSINE = cosine RND_A // (float)   RND_A = random(250.0, 600.0)   RND_SINE *= RND_A                  RND_A = random(250.0, 600.0)   RND_COSINE *= RND_A   RND_X += RND_SINE   RND_Y += RND_COSINE   03D3: get_route_nearest_for RND_X RND_Y RND_Z store_to VAN_X VAN_Y VAN_Z Z_angle_to VAN_A    if       00C2:   sphere_onscreen VAN_X VAN_Y VAN_Z radius 5.0   then       continue   end      CARM = random(#LANDSTAL, #UTILTR1)   Model.Load(CARM)   while not Model.Available(CARM)       wait 0    end   Car.Create(CAR, VAN_X, VAN_Y, VAN_Z)   Car.Angle(CAR) = VAN_A   0587: enable_car CAR validate_position 0    Model.Destroy(CARM)   breakend

 

how do i choose only those random vehicles that are not flying, boat, or cars like utilitr1?

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785765
Share on other sites

gtasearcher just over complicates things. Also, no idea what those random A's are. And also, random(,) doesn't even register for me, just throws up errors

 

Find a way of creating a random car, then use this

 

 

:104C4: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.0 25.0 1.0 04D3: get_nearest_car_path_coords_from 1@ 2@ 3@ type 2 store_to 1@ 2@ 3@wait 1000create random car 

 

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785880
Share on other sites

Excuse me, but what's your browser then?

 

EDIT: To put the nail to it's coffin

 

IE - http://i178.photobucket.com/albums/w265/james227uk/IE.png

Firefox - http://i178.photobucket.com/albums/w265/ja...7uk/firefox.png

Chrome - http://i178.photobucket.com/albums/w265/ja...27uk/chrone.png

Opera - http://i178.photobucket.com/albums/w265/james227uk/opera.png

 

4 of the most well know and most common updated browsers displaying it incorrectly? I don't think so, as I said, those images put the nail to the coffin

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785939
Share on other sites

 

Ok, this is strange.

 

My firefox displays it correctly http://i49.tinypic.com/2zivwk1.jpg

 

And my IE does not http://i48.tinypic.com/688pjt.jpg

It's an encoding bug with GTAF, and almost always occurs to me whenever a post containing tabs is quoted - it replaces those things in front of tabs. The fact that it works differently might be due to a different locale setting, a different GTAF theme, or other. My browser also shows the 'A with accent' symbols.

 

You shouldn't blame gtasearcher for it. wink.gif

 

EDIT: the characters are 'C2 A0', where U+00C2 is the A and U+00A0 is a non-breaking space in ASCII. This conversion issue seems to occur more often than only on GTAF, and is caused by applications incorrectly converting 20 20/20 A0 to C2 A0 in UTF-8, which coincides with these characters in ASCII, and a 'non-breaking space' in UTF-8. gtasearcher, you likely have your browser hardconfigured to UTF-8, which might be due to a special language.

Edited by NTAuthority
Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059785981
Share on other sites

I guess ppl are confused with the question. Let me rephrase it.

 

In order to spawn a car, there are basically two steps

 

1. Load car model

2. Create car with the loaded model

 

Now, if I want to create a random car model, I would focus on the model since there is no spawn_random_car opcode in CLEO

 

Since CLEO allows a model IDs to be numbers (400 instead of #LANDSTAL) it opens up a possible way.

 

I can use the following method to continue

 

0@ = <get random number between 400 and 611>

 

load_model 0@

 

blah blah ...

 

But in the mod I'm making I only want cars that run on the road, and which can be driven. Therefore, boats, vortex, planes, choppers and other models like the truck trailers etc... is to be omitted when random number is generated.

 

Since I have been unable to find a shortcut way (apart from creating the car and checking it, which is time consuming from script's point of view), I was obliged to create a list of numbers which should be invalidated, from GGMM.

 

This is what I made:

 

:Get_Modelwait 0 ms0209: 0@ = random_int_in_ranges 400 612if and   0@ <> 416   .   .   .   0@ <> 441jf @Get_Model //Only 9 conditions per ifif and   0@ <> 450   .   .   .   0@ <> 500jf @Get_Model...

 

Please do not put the above in Sannybuilder and compile. It's just illustration smile.gif

 

This will manually check for unwanted cars and get another number if invalidated. If number found valid, the script will proceed to spawn it. But for some weird reason, this if thing does not work, I've got boats to RC planes spawning where it's only supposed to be cars. What's wrong?

 

 

 

 

 

 

 

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059786051
Share on other sites

Back2Basics...

 

 

You can create random car park cars with this...

 

 

03C5: create_random_car_for_carpark 2077.872 2398.657 9.8203 z_angle 89.6383

 

 

 

To load a random model, whilst ensuring it is a certain type:

 

 

:LOOPwait 00209: 0@ = random_int_in_ranges 400 611if and   881E:   not model 0@ boat // make sure the model is not a boat.   8820:   not model 0@ heli // and not a heli.   881F:   not model 0@ plane // and not a plane.      // Add lines like this to specify that the car can not be a certain model ID/Name...   //8039:   not model 0@ == #AMBULAN      // Make sure it has 4 wheels?   // 0A01:   model 0@ minimum_4wheels_vehicleelse_jump @LOOP0247: load_model 0@while 8248:   not model 0@ available   wait 0end00A5: 1@ = create_car 0@ at 0.0 0.0 0.0

 

 

8039: not model 1@ == #AMBULAN - simply checks the random number and makes sure it isn't a specified value.

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059786373
Share on other sites

Back2Basics...

 

 

You can create random car park cars with this...

 

 

03C5: create_random_car_for_carpark 2077.872 2398.657 9.8203 z_angle 89.6383

 

 

 

To load a random model, whilst ensuring it is a certain type:

 

 

:LOOPwait 00209: 0@ = random_int_in_ranges 400 611if and   881E:   not model 0@ boat // make sure the model is not a boat.   8820:   not model 0@ heli // and not a heli.   881F:   not model 0@ plane // and not a plane.      // Add lines like this to specify that the car can not be a certain model ID/Name...   //8039:   not model 0@ == #AMBULAN      // Make sure it has 4 wheels?   // 0A01:   model 0@ minimum_4wheels_vehicleelse_jump @LOOP0247: load_model 0@while 8248:   not model 0@ available   wait 0end00A5: 1@ = create_car 0@ at 0.0 0.0 0.0

 

 

8039: not model 1@ == #AMBULAN - simply checks the random number and makes sure it isn't a specified value.

Yes, that's what I was looking for.. Thanks a bunch colgate.gif

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059786835
Share on other sites

 

This edits the .scm file right? and you have to start a new game, isn't it?

A Cleo script file get then the file extension, which is written in the Cleo Script directive at the beginning of the script

{$CLEO .cs} = Cleo directive will be compiled to *.cs

if not, sanny compiles the script as main.scm

 

read CLEO Script Tutorial

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059787267
Share on other sites

 

My firefox displays it correctly http://i49.tinypic.com/2zivwk1.jpg

 

And my IE does not http://i48.tinypic.com/688pjt.jpg

It's an encoding bug with GTAF, and almost always occurs to me whenever a post containing tabs is quoted - it replaces those things in front of tabs. The fact that it works differently might be due to a different locale setting, a different GTAF theme, or other. My browser also shows the 'A with accent' symbols.

 

EDIT: the characters are 'C2 A0', where U+00C2 is the A and U+00A0 is a non-breaking space in ASCII. This conversion issue seems to occur more often than only on GTAF, and is caused by applications incorrectly converting 20 20/20 A0 to C2 A0 in UTF-8, which coincides with these characters in ASCII, and a 'non-breaking space' in UTF-8. gtasearcher, you likely have your browser hardconfigured to UTF-8, which might be due to a special language.

terrible, now I have it also

first I thought it's caused by gtasearchers browser

yesterday night I posted a script here and it looked fine

now I have it in all my posted scripts

I have question marks at Tab positions

I believe I had a firefox update in the last 2 days

and hey, gtasearchers script of first page looks now clean for me

 

I can correct the wrong display by set the coding to westlich (ISO-8859-1)

but I must do it for each page

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059790614
Share on other sites

I can correct the wrong display by set the coding to westlich (ISO-8859-1)

but I must do it for each page

Until GTAForums fixes it, the Firefox options contain a 'default encoding' setting hidden somewhere deep.

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059790617
Share on other sites

 

I can correct the wrong display by set the coding to westlich (ISO-8859-1)

but I must do it for each page

Until GTAForums fixes it, the Firefox options contain a 'default encoding' setting hidden somewhere deep.

you mean settings>content>advanced:charackter encoding?

user posted image

it was allready set to west(ISO 8859-1)

a bug of the last firefox update?

 

I hope gtaf can fix it

Link to comment
https://gtaforums.com/topic/441089-how-to-spawn-cars/#findComment-1059790636
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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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