GetVehicleOccupant: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__  
{{Server client function}}
__NOTOC__
This function gets the player sitting in the specified vehicle.
This function gets the player sitting in the specified vehicle.


Line 8: Line 9:


===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The vehicle from which you wish to retrive the player.
*'''theVehicle:''' The vehicle of which you wish to retrieve the driver or a passenger.


===Optional Arguments===  
===Optional Arguments===  
Line 20: Line 21:
This example announces the driver of a certain vehicle whenever it is damaged:
This example announces the driver of a certain vehicle whenever it is damaged:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler ( "onVehicleDamage", stolenVehicle, "onStolenVehicleDamage" )
function onStolenVehicleDamage ( loss )
function onStolenVehicleDamage ( loss )
  driver = getVehicleOccupant ( source ) -- get the player sitting in seat 0
    local driver = getVehicleOccupant ( source ) -- get the player sitting in seat 0
  if ( driver ) then -- if the driver exists, display a message
    if ( driver ) then -- if the driver exists, display a message
    outputChatBox ( getClientName ( driver ) .. " is wrecking the vehicle he stole!" )
        outputChatBox ( getClientName ( driver ) .. " is wrecking the vehicle he stole!" )
  end
    end
end
end
addEventHandler ( "onVehicleDamage", stolenVehicle, onStolenVehicleDamage )
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Vehicle_functions}}
{{Vehicle_functions}}

Revision as of 18:05, 17 August 2007

This function gets the player sitting in the specified vehicle.

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. For more information on optional arguments, see optional arguments.

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

Returns

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

Example

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 ( getClientName ( driver ) .. " is wrecking the vehicle he stole!" )
    end
end
addEventHandler ( "onVehicleDamage", stolenVehicle, onStolenVehicleDamage )

See Also