Documentation

Vehicle

Constructible This class can be instantiated from your script. You can find more information on the Constructor below. Auto Destroy To delete an instance of this class, use the `Destroy` function of this class. You can find the function definition below. Custom Properties You can extend instances of this class with your own properties.

Vehicle

Constructor

Vehicle(number modelHash, Vector3f position, Vector3f rotation)

  • modelHash: the model hash (not name!) of the vehicle
  • position: the desired position of the vehicle
  • rotation: optional the desired rotation of the vehicle

Example

var vehicle = new Vehicle();

Properties

Name Type Description
driver Player the player driving the vehicle
modelHash number model hash of the Vehicle (TODO: reference to all hashes)
health number the vehicles health
destroyed boolean read only is the vehicle is destroyed or not (read-only)
networkId number read only the network id of this entity. It is not unique across different entities and will be re-assigned once this entity was destroyed
position Vector3f the Vehicle's position in the game world
aimPosition Vector3f the position the vehicles turret is aiming at
rotation Vector3f the vehicles rotation
linearVelocity Vector3f the vehicles positional speed
angularVelocity Vector3f the vehicles rotational speed
primaryColor number the vehicles color ID
dimension number world dimension of the Vehicle.
nitroEnabled boolean whether the vehicle is equipped with bavarium nitro
turboJumpEnabled boolean whether the vehicle is equipped with the bavarium jump modification

Functions

Vehicle.SetOccupant(number seat, Player player)

Set the occupant of the given vehicle

Parameter

Name Type Description
seat number the vehicles seat
player Player the player entity

Example

jcmp.events.Add('PlayerReady', player => {
  var vehicle = new Vehicle(28454791, player.position, player.rotation); //Spawn the vehicle at the players position
 vehicle.SetOccupant(0, player); //Assign the player to the driver seat
});

Vehicle.GetOccupant(number seat)

Get the occupant of a vehicle seat

returns: Player or undefined

Parameter

Name Type Description
seat number the vehicles seat

Example

jcmp.events.Add('PlayerExitVehicle', (player, vehicle) => {
  if (vehicle.GetOccupant(0)) {
    console.log('There is still a driver in the vehicle.');
  }
});

Vehicle.Repair()

This function is marked as unstable and is not recommended for use in production environments. It is not guaranteed to work at all (we're sorry).

Fully repairs the given vehicle

Example

jcmp.events.Add('VehicleDestroyed', vehicle => {
  vehicle.Repair();
});

Vehicle.Respawn()

This function is marked as unstable and is not recommended for use in production environments. It is not guaranteed to work at all (we're sorry).

Respawns the vehicle at its initial spawning position

Example

jcmp.events.Add('VehicleDestroyed', vehicle => {
  vehicle.Respawn();
});

Vehicle.Destroy()

Destroys the Vehicle

Stay informed

By becoming the newest member of our growing forums, we and hundreds of other players will always keep you up to date on everything JC3:MP related.