getVehicleOccupant | Multi Theft Auto: Wiki Skip to content

getVehicleOccupant

Client-side
Server-side
Shared

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function gets the player sitting/trying to enter the specified vehicle.

OOP Syntax Help! I don't understand this!

Syntax

player getVehicleOccupant ( vehicle theVehicle, [ int seat = 0 ] )
Required Arguments
  • theVehicle: the vehicle of which you wish to retrieve the driver or a passenger.
Optional Arguments

NOTE: When using optional arguments, you might need to supply all arguments before the one you wish to use.

  • seat (default: 0): the seat where the player is sitting (0 for driver, 1+ for passengers).

Returns

  • player: value

Returns the player sitting in the vehicle, or false if the seat is unoccupied or doesn't exist.

Code Examples

shared

This example announces the driver of a certain vehicle whenever it is damaged:

function onStolenVehicleDamage ( loss )
local driver = getVehicleOccupant ( source ) -- get the player sitting in seat 0
if ( driver ) then -- if the driver exists, display a message
outputChatBox ( getPlayerName ( driver ) .. " is wrecking the vehicle he stole!" )
end
end
addEventHandler ( "onVehicleDamage", stolenVehicle, onStolenVehicleDamage )

See Also

Vehicle Functions