This tutorial is about an essential part of the game: cars. There are two ways of spawning cars: cargenerators, which spawn multiple times or just cars that spawn once. I will explain both.
Cars that spawn multiple times
Cargenerators are more easy to spawn then cars that spawn once, because you don't have to load and unload the models of the cars. This way the permanent cars in the game are spawned.
The lines for the cargenerator:
> 014B: $PARKED_RHINO = init_parked_car_generator #RHINO -1 -1 1 alarm 0 door_lock 0 0 10000 at 2435.302 -1671.848 12.8007 angle 90.0
014C: set_parked_car_generator $PARKED_RHINO cars_to_generate_to 101
We will analyse this code. The first line:
$PARKED_RHINO: a variable to which the car is assigned.
#RHINO: model name of the car that you want to spawn.
First -1: first color of the car. ( -1 = random color )
Second -1: secondary color of the car. ( -1 = random color )
The 1: the police thinks that it is your car. If it's a 0, then the police knows that you stole it.
Alarm 0: the chance that the alarm will sound is 0%. If you make it 50, the chance is 50%.
Door_Lock 0: the door isn't locked. Make it 1 and the car is locked.
At the end are the x, y and z coords, and the angle of the car.
$PARKED_RHINO: the variable holding the car that the opcode is meant for.
101: the car will spawn. If you make it a 0, the car won't spawn.
You have to do this line always when you are making a cargenerator!
Example in the stripped file
There is another variant, which you can use to give the car a numberplate:
> 09E2: $grove = parked_car_generator_w_numberplate #GREENWOO 59 34 0 alarm 0 door_lock 0 0 10000 plate "GROVE4L_" at 2508.4824 -1670.6813 13.3812 angle 0.0
014C: set_parked_car_generator $grove cars_to_generate_to 101
The only differences are the code (09E2 instead of 014B), init_parked_car_generator instead of parked_car_generator_w_numberplate (it doesn't even matter!) and of course the "Plate...". After plate you can write what you want to have on the numberplate.(8 characters)
Cars that spawn once
This looks a lot like spawning an actor:
> //Load models
0247: load_model #GREENWOO
8248: not model #GREENWOO available
wait 0 ms
When you read the other tutorials, I think you don't need any explanation.
$greenwood = Car.Create(#GREENWOO, 2458.2483, -1659.0264, 13.3047)
With this code you will spawn a Greenwood. The variable ("handle") of the car is "$greenwood". The model name is #GREENWOO (you can look it up in the vehicles.ide). After that are the x, y and z coord. The second line is angle of the vehicle.
> 0249: release_model #GREENWOO
Of course we have to release the model.
There are all kind of codes for cars that spawn only once. A few examples:
> 0674: set_car_model #GREENWOO numberplate "ABCDEFG"
You can set a special numberplate. You have to use this opcode right before you create the car.
> 0119: car $greenwood wrecked
You can ask if the car is wrecked, most used in a if-structure. With the $ you have to use the variable (handle) of the car.
> 0224: set_car $greenwood health_to 10000
When the number is higher, the car can take more damage. Of course you can vary with this. The greenwood is smoking when the number is 500. When it is 250, one small crash is enough to blow up the car (black smoke). When it is less then 250, the car explode without doing anything. 1000 is a realistic number for the car. The $greenwood is the variable of the car, defined by spawning the car.
> 00A6: destroy_car $greenwood
With this car you can remove the car from the game. Just like with actors, a release model doesn't delete the car. For that, you have to use this opcode.
Of course there are many more commands that's got to do with cars, because it is an essential part of the game. So when you want to do something with a car that isn't explained here, and that you don't know how to use it, feel free to ask!