CreateVehicle
Description:
Function CreateVehicle creates a vehicle in the world. Can be used in place of AddStaticVehicleEx at any time in the script.
Trains can only be added with AddStaticVehicle and AddStaticVehicleEx. |
Parameters:
(vehicletype, Float:x, Float:y, Float:z, Float:rotation, color1, color2, respawn_delay, addsiren)
int | vehicletype | The model for the vehicle. |
float | X | The X coordinate for the vehicle. |
float | Y | The Y coordinate for the vehicle. |
float | Z | The Z coordinate for the vehicle. |
float | rotation | The facing angle for the vehicle. |
int | color1 | The primary color ID. |
int | color2 | The secondary color ID. |
int | respawn_delay | The delay until the car is respawned without a driver in seconds. Using -1 will prevent the vehicle from respawning. |
bool | addsiren | Added in 0.3.7; will not work in earlier versions. Has a default value 0. Enables the vehicle to have a siren, providing the vehicle has a horn. |
Return Values:
- The vehicle ID of the vehicle created (1 to MAX_VEHICLES).
- INVALID_VEHICLE_ID (65535) if vehicle was not created (vehicle limit reached or invalid vehicle model ID passed).
- 0 if vehicle was not created (IDs 538 or 537 passed, which is trains).
Examples:
public OnGameModeInit() { // Add a Hydra (520) to the game with a respawn time of 60 seconds CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, -1, -1, 60); return 1; }
Related Functions
The following functions may be useful, as they are related to this function in one way or another.
- DestroyVehicle: Destroy a vehicle.
- AddStaticVehicle: Add a static vehicle.
- AddStaticVehicleEx: Add a static vehicle with custom respawn time.
- GetVehicleParamsSirenState: Check whether a vehicle's siren is on or off.
Related Callbacks
The following callbacks might be useful as well, as they are related to this callback in one way or another.
- OnVehicleSpawn: Called when a vehicle respawns.
- OnVehicleSirenStateChange: Called when a vehicle's siren is toggled on/off.