# Seats

# Enters in vehicle SERVER

local result = veh:SV_EnterVehicle(ply)
if result >= 0 then
  -- ply is now in the vehicle.
else
  -- oops, there was a problem
end

Sits the player on the nearest available seat. The seat can be a driver or passenger seat. The operation will fail if the vehicle is locked.

Return value Type Explanations
1 OK Successfully completed
-1 ERROR No seat for this vehicle (weird but ok..)
-2 ERROR Vehicle locked
-3 ERROR No seat available (all seats are occupied by players)
-4 ERROR Error on creating seat

For optimisation reasons, seats are only created when a player wishes to sit on them. You should not use the native Player:EnterVehicle function for passenger seats. If you want to sit a player into a closed vehicle, unlock it, sit the player in, and then lock the vehicle again.

# Exit the vehicle SERVER

local result = veh:SV_ExitVehicle(ply)
if result >= 0 then
  -- ply is now in the vehicle.
else
  -- oops, there was a problem
end

Take the player out of the vehicle. The operation will fail if the vehicle is locked.

Return value Type Explanations
1 OK Successfully completed
-1 ERROR The player is not sitting in this vehicle
-2 ERROR Vehicle locked

If you want to bypass the vehicle lock, use Player:ExitVehicle instead.

# Get the last driver SERVER

local lastDriver = veh:SV_GetLastDriver(ply)
if IsValid(lastDriver) then
  -- lastDriver is the last driver of the vehicle.
  -- You have found the thief of the vehicle!
end

Returns the last driver of a vehicle. Could be nil.

You should use this information to find out who stole a vehicle, as they are often the last drivers of the vehicle.

# Is a driver seat? SHARED

if veh:SV_IsDriverSeat() then
  -- This is a driver seat.
end

Returns true if it is a driver seat, false otherwise.

# Get the driver seat SHARED

local driverSeat = veh:SV_GetDriverSeat()

Returns the driver seat of the vehicle, self if the vehicle is already the driver seat.

# Is a passenger seat? SHARED

if veh:SV_IsPassengerSeat() then
  -- This is a passenger seat.
end

Returns true if it is a passenger seat, false otherwise.

# Get the passenger seats SHARED

local passengerSeats = veh:SV_GetPassengerSeats()
for _, seat in ipairs(passengerSeats) do
  -- Do something with the seats.
end

Returns a list of all passenger seats of the vehicle.

Seats with no seated players are not created, and therefore cannot be included in this table.

# Get the players in the vehicle SHARED

local allPlayers = veh:SV_GetAllPlayers()
for _, ply in ipairs(allPlayers) do
  -- Do something with the players.
end

Returns a table with with the driver and passengers of a vehicle.