GetVehicleDriver: Difference between revisions

From Onset Developer Wiki
Created page with "{{Info|Function|Server|1.0}} {{FuncDescription|__EDIT_ME__}} {{FuncSyntax|GetVehicleDriver(vehicle)}} {{FuncParameters}} {{FuncParam|vehicle|__EDIT_ME__}} {{FuncReturnValu..."
 
28days (talk | contribs)
Add client support for v1.1.0
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Info|Function|Server|1.0}}
{{Info|Function|Server & Client|1.0}}


{{FuncDescription|__EDIT_ME__}}
{{FuncDescription|Get the driver (player identifier) of a given vehicle. Use [[GetVehiclePassenger]] to get any vehicle occupant.}}


{{FuncSyntax|GetVehicleDriver(vehicle)}}
{{FuncSyntax|GetVehicleDriver(vehicle)}}


{{FuncParameters}}
{{FuncParameters}}
{{FuncParam|vehicle|__EDIT_ME__}}
{{FuncParam|vehicle|The vehicle identifier.}}


{{FuncReturnValue|__EDIT_ME__}}
{{FuncReturnValue|The player identifier. Returns '''false''' on error.}}


== Example ==
== Example ==
__EDIT_ME__
<syntaxhighlight lang="Lua">
function cmd_getdriver(player, vehicle)
if (vehicle == nil) then
return AddPlayerChat(player, "Usage: /getdriver <vehicle>")
end
 
if (not IsValidVehicle(vehicle)) then
return AddPlayerChat(player, "Vehicle (ID: "..vehicle..") does not exist")
end
 
local driver = GetVehicleDriver(vehicle)
local name = GetPlayerName(driver)
AddPlayerChat(player, "Vehicle "..vehicle.." driver is "..name.." ("..driver..")")
end
AddCommand("getdriver", cmd_getdriver)
</syntaxhighlight>


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

Latest revision as of 20:47, 7 March 2020

GetVehicleDriver

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

Description

Get the driver (player identifier) of a given vehicle. Use GetVehiclePassenger to get any vehicle occupant.

Syntax

GetVehicleDriver(vehicle)

Parameters

  • vehicle
    The vehicle identifier.

Return Value

  • The player identifier. Returns false on error.

Example

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

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

	local driver = GetVehicleDriver(vehicle)
	local name = GetPlayerName(driver)
	AddPlayerChat(player, "Vehicle "..vehicle.." driver is "..name.." ("..driver..")")
end
AddCommand("getdriver", cmd_getdriver)

See also