GetVehiclePassenger: Difference between revisions

From Onset Developer Wiki
No edit summary
28days (talk | contribs)
Add client support for v1.1.0
 
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server & Client|1.0}}


{{FuncDescription|Get any occupant of a vehicle at a given seat.}}
{{FuncDescription|Get any occupant of a vehicle at a given seat.}}

Latest revision as of 20:47, 7 March 2020

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