Documentation

Want to improve the docs? Take a look at scripting-api-data!
Found a bug? jc3mp/bugs is a good place to let us know.

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

new 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(28454791, new Vector3f(), new Vector3f());

Properties

Name Type Description
driver Player the player driving the vehicle
position Vector3f the Vehicle's position in the game world
rotation Vector3f the vehicles rotation
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
destroyed boolean read only is the vehicle is destroyed or not (read-only)
nitroEnabled boolean whether the vehicle is equipped with bavarium nitro
turboJumpEnabled boolean whether the vehicle is equipped with the bavarium jump modification
primaryColor number the vehicles color ID
linearVelocity Vector3f the vehicles positional speed
angularVelocity Vector3f the vehicles rotational speed
aimPostion Vector3f
health number the vehicles health
modelHash number read only model hash of the Vehicle (TODO: reference to all hashes)
handling VehicleHandling read only
dimension number world dimension of the Vehicle.

Functions

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.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.SetOccupant(number seat, Player player)

Set the occupant of the given vehicle.

Note: if the player is not in the vicinity of the vehicle, he will first be teleported there automatically (slightly above the vehicle in the air).

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.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.