GetVehicleDriver: Difference between revisions

From Onset Developer Wiki
No edit summary
No edit summary
Line 11: Line 11:


== Example ==
== Example ==
<syntaxhighlight lang="Lua">
function cmd_getdriver(player, vehicle)
function cmd_getdriver(player, vehicle)
if (vehicle == nil) then
if (vehicle == nil) then

Revision as of 12:56, 22 March 2019

GetVehicleDriver

Type: Function
Context: Server
Introduced: v1.0

Description

Get the driver (player identifier) of a given vehicle.

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