Vehicle

class pysamp.vehicle.Vehicle(id: int)

Bases: object

A class that represents server vehicles.

Parameters

id – The ID of the vehicle.

Edit and work on them using this class. This class represents all drivable vehicles (Planes, boats, bikes, trains, trailers ++)

A car that explodes or dies, will be respawned at its original coordinates where it was created.

To create a new vehicle, check out create()

add_component(component_id: int) bool

Adds a component (often referred to as a modification) to a vehicle.

Valid components can be found here: https://open.mp/docs/scripting/resources/carcomponentid

NB: Using an invalid component ID crashes the player’s game. There are no internal checks for this.

change_color(color_1: int, color_2: int) bool

Change a vehicle’s primary and secondary colors.

Some vehicles have only a primary color and some can not have the color changed at all. A few (cement, squallo) have 4 colors, of which 2 can not be changed in SA:MP.

change_paintjob(paint_job_id: int) bool

Change a vehicle’s paintjob.

If vehicle is black, it may not show.

classmethod create(model: int, x: float, y: float, z: float, rotation: float, color1: int, color2: int, respawn_delay: int, add_siren: bool = False) Vehicle

Create a new vehicle with the given model, position, colors and settings.

Parameters
  • model – The model of the car (400-622).

  • x (float) – The x coordinate to spawn the vehicle.

  • y (float) – The y coordinate to spawn the vehicle.

  • z (float) – The z coordinate to spawn the vehicle.

  • rotation (float) – Set the vehicle heading.

  • color1 (int) – Primary color (0-255).

  • color2 (int) – Secondary color (if available) (0-255).

  • respawn_delay (int) – How long it should take for it to automatically respawn.

  • add_siren (optional bool) – Set if the car should have a siren. Defaults to False.

Returns

An instance of Vehicle.

destroy() bool

Removes the vehicle from the server.

detach_trailer() bool

Detach a trailer from the vehicle, if any.

get_component_in_slot(slot: int) int

Retrieves the installed component ID in the specific slot.

get_damage_status() Tuple[int, int, int, int]

This method returns information to you about if parts of the car has been damaged, or tires has been deflated.

Please refer to: https://open.mp/docs/scripting/resources/damagestatus

The returned values in the tuple are 4 bits each. For example the tires are represented as 4 bits, where a flat tire is 0 and a normal tire is represented by 1.

get_distance_from_point(x: float, y: float, z: float) float

Check how far away the vehicle is from a given coordinate.

get_health() float

Get the vehicle’s health. Vehicle starts burning at < 250.0.

get_model() int

Get the vehicle model.

get_params_car_doors() Tuple[int, int, int, int]

Allows you to retrieve the current state of a vehicle’s doors

Returns -1 if the door state is not set, like on a bike or a 2-door. Otherwise, it will return 0 (closed) or 1 (open).

The tuple contains information about doors in this order: (driver, passenger, back_left, back_right)

get_params_car_windows() Tuple[int, int, int, int]

Check if windows are available and if they are closed / open.

get_params_ex() Tuple[int, int, int, int, int, int, int]

Get the vehicle’s params.

get_params_siren_state() int

Check if the sirens are on or off.

Returns -1 if the siren hasn’t been set up. Otherwise, it will return 0 (off) or 1 (on).

get_position() Tuple[float, float, float]

Get the vehicle’s current position.

get_rotation_quat() Tuple[float, float, float, float]

Returns a vehicle’s rotation on all axes as a quaternion

get_trailer() Optional[Vehicle]

Get the Vehicle of the trailer that the vehicle is pulling.

Returns

An instance of Vehicle that is the trailer, or None if no trailer found.

get_velocity() Tuple[float, float, float]

Get the vehicle velocity. Vector is relative to the car axis

get_virtual_world() int

Find out which virtual world ID the vehicle is currently in.

get_z_angle() float

Returns the heading the vehicle has. Can be >= 0.0 and < 360.

is_streamed_in(for_player: Player) bool

Lets you know if a specific player has streamed in the vehicle.

is_trailer_attached() bool

Check if a trailer is attached to the vehicle.

is_valid() bool

Check if the vehicle is valid

Link the vehicle to a specific interior id.

Only if the players are in the same interior, they can interact with and see the vehicle.

classmethod on_damage_status_update(vehicleid: int, playerid: int)
classmethod on_death(vehicleid: int, killerid: int)
classmethod on_mod(playerid: int, vehicleid: int, componentid: int)
classmethod on_paintjob(playerid: int, vehicleid: int, paintjobid: int)
classmethod on_respray(playerid: int, vehicleid: int, color1: int, color2: int)
classmethod on_siren_state_change(playerid: int, vehicleid: int, newstate: int)
classmethod on_spawn(vehicleid: int)

When a vehicle is respawning only.

classmethod on_stream_in(vehicleid: int, forplayerid: int)
classmethod on_stream_out(vehicleid: int, forplayerid: int)
classmethod on_trailer_update(playerid: int, trailerid: int)
classmethod on_unoccupied_update(vehicleid: int, playerid: int, passenger_seat: int, new_x: float, new_y: float, new_z: float, vel_x: float, vel_y: float, vel_z: float)
remove_component(component_id: int) bool

Remove an added component by its component id.

repair() bool

Fully repairs the vehicle - including health

set_angular_velocity(vector: Tuple[float, float, float]) bool

Set the angular velocity of a vehicle.

This is set relative to world space and not vehicle’s local space.

set_damage_status(param: Tuple[int, int, int, int]) bool

Set vehicle damage status.

Please refer to: https://open.mp/docs/scripting/resources/damagestatus

set_health(health: float) bool

Set the vehicle’s health.

When the vehicle’s health decreases the engine will produce smoke, and finally fire when it decreases to less than 250.0 (25%).

set_number_plate(number_plate: str) bool

Set the vehicle number plate text.

Note

This method has no internal error checking.

Do not assign custom number plates to vehicles without plates (boats, planes, etc) as this will result in some unneeded processing time on the client. The vehicle must be re-spawned or re-streamed for the changes to take effect. There’s a limit of 32 characters on each number plate (including embedded colors). The text length that can be seen on the number plate is around 9 to 10 characters. More characters will cause the text to split. Some vehicle models has a backward number plate, e.g. Boxville (498).

Parameters

number_plate (str) – The text you want to set.

Returns

No return value.

set_params_car_doors(doors: Tuple[int, int, int, int]) bool

Open and close vehicle doors.

The doors tuple should be in this order: (driver, passenger, back_left, back_right)

Setting an unavailable door to 0 or 1, has no effect.

set_params_car_windows(windows: Tuple[int, int, int, int]) bool

Allows you to open and close the windows of a vehicle.

set_params_ex(param: Tuple[int, int, int, int, int, int, int]) bool

Set additional parameters on the vehicle.

set_params_for_player(player: Player, objective: int, doors_locked: int) bool

Set the parameters on the vehicle.

set_position(position: Tuple[float, float, float]) bool

Sets the vehicle position directly on the passed position.

set_to_respawn() bool

Respawn the vehicle. It will spawn at its created coordinates.

set_velocity(vector: Tuple[float, float, float]) bool

Set the car velocity. Relative to the car axis.

set_virtual_world(world_id: int) bool

Set the virtual world ID that the vehicle should be visible in.

set_z_angle(z_angle: float) bool

Set the vehicle’s heading hangle. 0.0 => z_angle < 360.0