Table of Contents

Class Vehicle

Namespace
SampSharp.Entities.SAMP
Assembly
SampSharp.OpenMp.Entities.dll

Represents a component which provides the data and functionality of a vehicle.

public class Vehicle : WorldEntity
Inheritance
Vehicle
Inherited Members

Constructors

Vehicle(IOmpEntityProvider, IVehiclesComponent, IVehicle)

Initializes a new instance of the Vehicle class.

protected Vehicle(IOmpEntityProvider entityProvider, IVehiclesComponent vehicles, IVehicle vehicle)

Parameters

entityProvider IOmpEntityProvider
vehicles IVehiclesComponent
vehicle IVehicle

Properties

Alarm

Gets or sets a value indicating whether the alarm of this vehicle is on.

public virtual bool Alarm { get; set; }

Property Value

bool

Angle

Gets or sets the Z angle of this vehicle.

public virtual float Angle { get; set; }

Property Value

float

Bonnet

Gets or sets a value indicating whether the bonnet (hood) of this vehicle is open.

public virtual bool Bonnet { get; set; }

Property Value

bool

Boot

Gets or sets a value indicating whether the boot (trunk) of this vehicle is open.

public virtual bool Boot { get; set; }

Property Value

bool

Cab

Gets the cab (towing vehicle) currently towing this vehicle, or null if there is none.

public virtual Vehicle? Cab { get; }

Property Value

Vehicle

Color1

Gets the primary color of this vehicle.

public virtual int Color1 { get; }

Property Value

int

Color2

Gets the secondary color of this vehicle.

public virtual int Color2 { get; }

Property Value

int

Colors

Gets or sets the colors of this vehicle as a tuple of (primary, secondary) colors IDs.

public virtual (int Primary, int Secondary) Colors { get; set; }

Property Value

(int offset, int length)

Doors

Gets or sets a value indicating whether the doors of this vehicle are locked.

public virtual bool Doors { get; set; }

Property Value

bool

Driver

Gets the current driver of this vehicle, or null if there is none.

public virtual Player? Driver { get; }

Property Value

Player

Engine

Gets or sets a value indicating whether the engine of this vehicle is running.

public virtual bool Engine { get; set; }

Property Value

bool

HasBeenOccupied

Gets a value indicating whether this vehicle has ever been occupied.

public virtual bool HasBeenOccupied { get; }

Property Value

bool

HasTrailer

Gets a value indicating whether this vehicle has a trailer attached.

public virtual bool HasTrailer { get; }

Property Value

bool

Health

Gets or sets the health of this vehicle.

public virtual float Health { get; set; }

Property Value

float

HydraThrustAngle

Gets the current Hydra (jet) thrust angle of this vehicle.

public virtual uint HydraThrustAngle { get; }

Property Value

uint

Interior

Gets or sets the interior ID of this vehicle.

public virtual int Interior { get; set; }

Property Value

int

IsBackLeftDoorOpen

Gets or sets a value indicating whether the back left door of this vehicle is open.

public virtual bool IsBackLeftDoorOpen { get; set; }

Property Value

bool

IsBackLeftWindowClosed

Gets or sets a value indicating whether the back left window of this vehicle is closed.

public virtual bool IsBackLeftWindowClosed { get; set; }

Property Value

bool

IsBackRightDoorOpen

Gets or sets a value indicating whether the back right door of this vehicle is open.

public virtual bool IsBackRightDoorOpen { get; set; }

Property Value

bool

IsBackRightWindowClosed

Gets or sets a value indicating whether the back right window of this vehicle is closed.

public virtual bool IsBackRightWindowClosed { get; set; }

Property Value

bool

IsDead

Gets a value indicating whether this vehicle is dead (destroyed).

public virtual bool IsDead { get; }

Property Value

bool

IsDriverDoorOpen

Gets or sets a value indicating whether the driver door of this vehicle is open.

public virtual bool IsDriverDoorOpen { get; set; }

Property Value

bool

IsDriverWindowClosed

Gets or sets a value indicating whether the driver window of this vehicle is closed.

public virtual bool IsDriverWindowClosed { get; set; }

Property Value

bool

IsOccupied

Gets a value indicating whether this vehicle is currently occupied.

public virtual bool IsOccupied { get; }

Property Value

bool

IsOmpEntityDestroyed

Gets a value indicating whether the open.mp entity counterpart has been destroyed.

protected bool IsOmpEntityDestroyed { get; }

Property Value

bool

IsPassengerDoorOpen

Gets or sets a value indicating whether the passenger door of this vehicle is open.

public virtual bool IsPassengerDoorOpen { get; set; }

Property Value

bool

IsPassengerWindowClosed

Gets or sets a value indicating whether the passenger window of this vehicle is closed.

public virtual bool IsPassengerWindowClosed { get; set; }

Property Value

bool

IsRespawning

Gets a value indicating whether this vehicle is currently in the process of respawning.

public virtual bool IsRespawning { get; }

Property Value

bool

IsSirenOn

Gets a value indicating whether the siren of this vehicle is on.

public virtual bool IsSirenOn { get; }

Property Value

bool

IsTrailer

Gets a value indicating whether this vehicle is a trailer (i.e. is being towed by another vehicle).

public virtual bool IsTrailer { get; }

Property Value

bool

LandingGearState

Gets the current state of this vehicle's landing gear.

public virtual byte LandingGearState { get; }

Property Value

byte

LastDriverPoolID

Gets the player pool ID of the last driver of this vehicle.

public virtual int LastDriverPoolID { get; }

Property Value

int

LastOccupiedTime

Gets the timestamp at which this vehicle was last occupied.

public virtual DateTimeOffset LastOccupiedTime { get; }

Property Value

DateTimeOffset

LastSpawnTime

Gets the timestamp at which this vehicle was last spawned.

public virtual DateTimeOffset LastSpawnTime { get; }

Property Value

DateTimeOffset

Lights

Gets or sets a value indicating whether the lights of this vehicle are on.

public virtual bool Lights { get; set; }

Property Value

bool

Model

Gets the model ID of this vehicle.

public virtual VehicleModelType Model { get; }

Property Value

VehicleModelType

NumberPlate

Gets the current numberplate text of this vehicle.

public virtual string NumberPlate { get; }

Property Value

string

Objective

Gets or sets a value indicating whether the objective marker of this vehicle is on.

public virtual bool Objective { get; set; }

Property Value

bool

Paintjob

Gets or sets the paintjob of this vehicle. For solid colors, use ChangeColor(int, int) instead.

public virtual int Paintjob { get; set; }

Property Value

int

Remarks

Use 3 to remove the paintjob.

Parameters

Gets or sets the parameters of this vehicle, including the engine, lights, alarm, doors, bonnet, boot, and objective status.

public virtual VehicleParameters Parameters { get; set; }

Property Value

VehicleParameters

RespawnDelay

Gets or sets the respawn delay for this vehicle.

public virtual TimeSpan RespawnDelay { get; set; }

Property Value

TimeSpan

RotationQuaternion

Gets the rotation of this vehicle on all axes as a quaternion.

[Obsolete("Deprecated. Use Rotation instead.")]
public virtual Quaternion RotationQuaternion { get; }

Property Value

Quaternion

SpawnData

Gets or sets the spawn data of this vehicle (model, position, rotation, colors, siren, interior, respawn delay).

public virtual VehicleSpawnInfo SpawnData { get; set; }

Property Value

VehicleSpawnInfo

Trailer

Gets or sets the Vehicle trailer attached to this vehicle.

public virtual Vehicle? Trailer { get; set; }

Property Value

Vehicle

TrainSpeed

Gets the current train speed of this vehicle.

public virtual float TrainSpeed { get; }

Property Value

float

Velocity

Gets or sets the velocity at which this vehicle is moving.

public virtual Vector3 Velocity { get; set; }

Property Value

Vector3

Methods

AddCarriage(Vehicle, int)

Adds a carriage to this train at the specified position in the carriage chain.

public virtual void AddCarriage(Vehicle carriage, int pos)

Parameters

carriage Vehicle

The vehicle to add as a carriage.

pos int

The position of the carriage in the chain.

AddComponent(int)

Adds a component (modification) to this vehicle.

public virtual void AddComponent(int componentId)

Parameters

componentId int

The ID of the component to add.

ChangeColor(int, int)

Changes the primary and secondary colors of this vehicle.

[Obsolete("Use Colors property instead.")]
public virtual void ChangeColor(int color1, int color2)

Parameters

color1 int

The primary color ID to set.

color2 int

The secondary color ID to set.

ChangePaintjob(int)

Changes the paintjob of this vehicle. For solid colors, use ChangeColor(int, int) instead.

[Obsolete("Use Paintjob property instead.")]
public virtual void ChangePaintjob(int paintjobId)

Parameters

paintjobId int

The paintjob ID to apply. Use 3 to remove the paintjob.

GetCarriages()

Enumerates the carriages currently linked to this train, in order.

public virtual IEnumerable<Vehicle> GetCarriages()

Returns

IEnumerable<Vehicle>

A sequence of Vehicle components representing the carriages.

GetComponentInSlot(CarModType)

Gets the component ID installed in the specified slot of this vehicle.

public virtual int GetComponentInSlot(CarModType slot)

Parameters

slot CarModType

The component slot to check.

Returns

int

The ID of the component installed in the specified slot.

GetDamageStatus(out int, out int, out int, out int)

Retrieves the damage status of this vehicle's panels, doors, lights, and tires.

public virtual void GetDamageStatus(out int panels, out int doors, out int lights, out int tires)

Parameters

panels int

The panel damage status.

doors int

The door damage status.

lights int

The light damage status.

tires int

The tire damage status.

GetDistanceFromPoint(Vector3)

Calculates the distance between this vehicle and the specified point.

public virtual float GetDistanceFromPoint(Vector3 point)

Parameters

point Vector3

The point to calculate the distance to as a Vector3.

Returns

float

The distance from this vehicle to the specified point.

GetPassengers()

Enumerates the current passengers of this vehicle.

public virtual IEnumerable<Player> GetPassengers()

Returns

IEnumerable<Player>

A lazy sequence of Player components.

IsStreamedIn(Player)

Determines whether this vehicle is streamed in for the specified player.

public virtual bool IsStreamedIn(Player player)

Parameters

player Player

The Player to check.

Returns

bool

true if this vehicle is streamed in for the specified player; false otherwise.

LinkToInterior(int)

Links this vehicle to an interior, allowing it to be used in interior areas such as arenas or stadiums.

[Obsolete("Use the Interior property instead.")]
public virtual void LinkToInterior(int interiorId)

Parameters

interiorId int

The ID of the interior to link this vehicle to.

OnDestroyComponent()

This method is invoked before this component is destroyed and removed from its entity.

protected override void OnDestroyComponent()

RemoveComponent(int)

Removes a component from this vehicle.

public virtual void RemoveComponent(int componentId)

Parameters

componentId int

The ID of the component to remove.

Repair()

Fully repairs this vehicle, including all visual damage such as bumps, dents, scratches, and popped tires.

public virtual void Repair()

Respawn()

Respawns this vehicle to its original spawn location.

public virtual void Respawn()

SetAngularVelocity(Vector3)

Sets the angular velocity of this vehicle.

public virtual void SetAngularVelocity(Vector3 velocity)

Parameters

velocity Vector3

The angular velocity to set.

SetNumberPlate(string)

Sets the license plate text of this vehicle, which supports color embedding.

public virtual void SetNumberPlate(string numberplate)

Parameters

numberplate string

The license plate text to display. Color embedding is supported.

SetParametersForPlayer(Player, in VehicleParameters)

Sets the parameters of this vehicle for the specified player.

public virtual void SetParametersForPlayer(Player player, in VehicleParameters parameters)

Parameters

player Player

The Player to set this vehicle's parameters for.

parameters VehicleParameters

The VehicleParameters to set.

SetSiren(bool)

Sets the siren state of this vehicle.

public virtual void SetSiren(bool enable)

Parameters

enable bool

true to turn the siren on; false to turn it off.

StreamedForPlayers()

Enumerates the players for whom this vehicle is currently streamed in.

public virtual IEnumerable<Player> StreamedForPlayers()

Returns

IEnumerable<Player>

A lazy sequence of Player components.

ToString()

public override string ToString()

Returns

string

UpdateCarriage(Vector3, Vector3)

Updates the position and velocity of a carriage attached to this train.

public virtual void UpdateCarriage(Vector3 position, Vector3 velocity)

Parameters

position Vector3

The new carriage position.

velocity Vector3

The new carriage velocity.

UpdateDamageStatus(int, int, int, int, Player?)

Sets the damage status of this vehicle's panels, doors, lights, and tires.

public virtual void UpdateDamageStatus(int panels, int doors, int lights, int tires, Player? updater = null)

Parameters

panels int

The panel damage status to set.

doors int

The door damage status to set.

lights int

The light damage status to set.

tires int

The tire damage status to set.

updater Player

The player updating the vehicle damage, or null to update for all players.

Operators

implicit operator IVehicle(Vehicle?)

Performs an implicit conversion from Vehicle to IVehicle.

public static implicit operator IVehicle(Vehicle? vehicle)

Parameters

vehicle Vehicle

Returns

IVehicle