GetVehiclePassenger

From Onset Developer Wiki
GetVehiclePassenger

Type: Function
Context: Server & Client
Introduced: v1.0

Description

Get any occupant of a vehicle at a given seat.

Syntax

GetVehiclePassenger(vehicle, seat)

Parameters

  • vehicle
    The vehicle to get a passenger from.
  • seat
    The seat to the passenger.

Return Value

  • Returns the player identifier. If there is no passenger in that seat 0 is returned.

Example

function cmd_passengers(player, vehicle)
	if (vehicle == nil) then
		return AddPlayerChat(player, "Usage: /passengers <vehicle>")
	end

	if (not IsValidVehicle(vehicle)) then
		return AddPlayerChat(player, "Vehicle (ID: "..vehicle..") does not exist")
	end

	for i=1, GetVehicleNumberOfSeats(vehicle) do
		local passenger = GetVehiclePassenger(vehicle, i)
		if (passenger == 0) then
			occupants[i] = "Empty"
		else
			occupants[i] = GetPlayerName(passenger).."("..passenger..")"
		end
	end

	for k, v in ipairs(occupants) do
		AddPlayerChat(player, '    Seat '..k..': '..v)
	end
end
AddCommand("passengers", cmd_passengers)

See also