Skip to main content

VehiclePart, VehiclePartState, VehicleSeat and VehicleType

These tables describe vehicles: their moving parts such as doors and hatches (VehiclePart) and whether those are open (VehiclePartState), the seats a player can sit in (VehicleSeat), and the kind of vehicle (VehicleType).

Available on: Server, Client

Values​

VehiclePart​

The articulated (moving) parts of a vehicle. A vehicle only has some of them: a car has doors, a trunk and a hood, an airplane may have a cargo bay door or folding wings. Setting a part the vehicle doesn't have does nothing visible.

Used by (see VehicleHandle):

Any value outside 0..15 raises the Lua error invalid vehicle part <n>.

NameValueMeaning
VehiclePart.FrontLeft0The driver's door (front left).
VehiclePart.FrontRight1The front passenger's door (front right).
VehiclePart.RearLeft2The rear left passenger door.
VehiclePart.RearRight3The rear right passenger door.
VehiclePart.CenterLeft4The center left passenger door.
VehiclePart.CenterRight5The center right passenger door.
VehiclePart.TurretDoor6The turret door (hatch).
VehiclePart.Trunk7The trunk.
VehiclePart.Hood8The hood.
VehiclePart.RearDoor9The rear door.
VehiclePart.CargoBayDoor10The cargo bay door of a cargo aircraft or helicopter.
VehiclePart.FoldingWing11Folding wings.
VehiclePart.MissileHatch12The missile hatch.
VehiclePart.TrailerLandingGear13A trailer's landing gear (the legs it stands on when unhitched).
VehiclePart.VTOL14The VTOL (vertical take-off) rotors or nozzles.
VehiclePart.EngineOperated15A part that is open while the engine runs and closed while it doesn't.

VehiclePartState​

The state of a vehicle part.

Used by (see VehicleHandle):

  • vehicle:GetPartState(part) returns one of these (server and client)
  • vehicle:SetPartState(part, state) (server). It accepts the integers 0 to 4; anything else raises the Lua error invalid vehicle part state <n>. On the players' games only Open makes a difference: VehiclePartState.Open opens the part, and every other state closes it. GetPartState returns the state exactly as it was set.
  • The client event OnVehiclePartChangedState(vehicle, part, state). When the change comes from the game itself (a player opening a door, for example) state is Open or Closed.
NameValueMeaning
VehiclePartState.Open0The part is open.
VehiclePartState.Opening1The part is opening.
VehiclePartState.Closing2The part is closing.
VehiclePartState.Missing3The part is gone, for example a door that was torn off.
VehiclePartState.Closed4The part is closed.

VehicleSeat​

The seats of a vehicle, and the stunt and entry positions on it. Which ones exist depends on the vehicle model.

Used by:

NameValueMeaning
VehicleSeat.DriverSeat0The driver's seat.
VehicleSeat.PassengerSeat11The front passenger seat (next to the driver).
VehicleSeat.PassengerSeat22The seat behind the driver.
VehicleSeat.PassengerSeat33The seat behind the front passenger.
VehicleSeat.PassengerSeat44The back left seat.
VehicleSeat.PassengerSeat55The back right seat.
VehicleSeat.PassengerSeat624A sixth passenger seat.
VehicleSeat.GunnerSeat6The gunner's seat (a mounted weapon on the vehicle).
VehicleSeat.GunnerSeat27The second gunner's seat.
VehicleSeat.StuntSeat8A stunt position (standing on the vehicle).
VehicleSeat.FrontStunt9The stunt position at the front of the vehicle.
VehicleSeat.DriverSide10The driver's side entry point (counts as the driver's seat once inside).
VehicleSeat.StuntSide11The stunt position on the side of the vehicle (counts as the driver's seat once inside).
VehicleSeat.RearStunt12The stunt position at the rear of the vehicle.
VehicleSeat.LeftStunt13The stunt position on the left of the vehicle.
VehicleSeat.RightStunt14The stunt position on the right of the vehicle.
VehicleSeat.DriverOnGround15The driver's entry point from the ground (counts as the driver's seat once inside).
VehicleSeat.DriverOnGroundRight16The driver's entry point from the ground on the right side (counts as the driver's seat once inside).
VehicleSeat.DriverSideRight17The driver's entry point on the right side (counts as the driver's seat once inside).
VehicleSeat.PassengerSide18The front passenger's side entry point (counts as PassengerSeat1 once inside).
VehicleSeat.PassengerOnGround19The front passenger's entry point from the ground (counts as PassengerSeat1 once inside).
VehicleSeat.CargoBayDriverDoor28The driver's entry through the cargo bay.
VehicleSeat.GunnerDetached39A gunner position detached from the vehicle body.
VehicleSeat.GunnerDetached240A second gunner position detached from the vehicle body.
VehicleSeat.UseItem25The position for using an item mounted on the vehicle.
VehicleSeat.FakeStuntPoint41A stunt position that isn't a real seat.

VehicleType​

The kind of vehicle. The values are 32-bit hashes, not small integers: always compare against the table.

Used by:

  • vehicle:GetVehicleType() (client, while the vehicle is spawned in the player's game) returns one of these, or nil while the vehicle isn't spawned in the local game. A vehicle the game doesn't classify returns a value that is not in the table.
NameValueMeaning
VehicleType.Motorbike0x0847F3D0Motorbikes.
VehicleType.Car0x25651EF2Land vehicles: cars, trucks, tanks and other wheeled or tracked vehicles.
VehicleType.SeaVehicle0x6FA8D546Boats and other sea vehicles.
VehicleType.Airplane0xCC9B20E3Airplanes and jets.
VehicleType.Helicopter0x37777B4CHelicopters.
VehicleType.Dirigible0x30CD5569Airships.

Example

-- server: spawn a car, put a player in the driver's seat and open the trunk
Event.Add("OnPlayerJoin", function(client)
local player = client:GetPlayer()
if not player then
return
end

player = player:AsPlayer()

local car = World.SpawnVehicle("v025_car_vintagesuper_civilian_01", player:GetPosition() + vec3(5, 0, 0))

Timer.Set(function()
if player:WarpIntoVehicle(car, VehicleSeat.DriverSeat) then
car:SetPartState(VehiclePart.Trunk, VehiclePartState.Open)
end
end, 1000, 1)
end)

Event.Add("OnPlayerVehicleExit", function(player, vehicle, seat)
if seat == VehicleSeat.DriverSeat then
print("the driver got out")
end
end)
-- client: tell the kind of vehicle the local player is in
Cmd.Add("vehicletype", function()
local player = World.LocalPlayer()
local vehicle = player and player:AsPlayer():GetVehicle()

if vehicle and vehicle:GetVehicleType() == VehicleType.Helicopter then
print("you are flying a helicopter")
end
end)