GetVehiclePassenger: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|GetVehiclePassenger(vehicle, seat)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{FuncPa..."
 
No edit summary
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server|1.0}}


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


{{FuncSyntax|GetVehiclePassenger(vehicle, seat)}}
{{FuncSyntax|GetVehiclePassenger(vehicle, seat)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle to get a passenger from.}}
{{FuncParam|seat|__EDIT_ME__}}
{{FuncParam|seat|The seat to the passenger.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|Returns the player identifier. If there is no passenger in that seat '''0''' is returned.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
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)
</syntaxhighlight>


{{RelatedFunctions}}
{{RelatedFunctions}}
__EDIT_ME__
{{VehicleFunctions}}

Revision as of 13:04, 22 March 2019

GetVehiclePassenger

Type: Function
Context: Server
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