GetVehicleController: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 16: Line 16:
==Example==  
==Example==  
<section name="Server" class="server" show="true">
<section name="Server" class="server" show="true">
This example does...
This example outputs a chatbox message when a vehicle gets a trailer attached.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function scriptOnTrailerAttach ( towedBy )
function scriptOnTrailerAttach ( towedBy )
   thePlayer = getVehicleController ( source ) -- get the controller of the towing vehicle
   thePlayer = getVehicleController ( source ) -- get the controller of the towing vehicle
   if ( thePlayer ) then
   if ( thePlayer ) then
     outputChatBox ( getClientName ( thePlayer ).. " attached a trailer" )
     outputChatBox ( getPlayerName ( thePlayer ).. " attached a trailer" )
   else
   else
     outputChatBox ( "trailer attached" )
     outputChatBox ( "trailer attached" )

Revision as of 12:20, 27 August 2009

This function is used to get the player in control of the specified vehicle.

Syntax

player getVehicleController ( vehicle theVehicle )            

Required Arguments

  • theVehicle: The vehicle you want to get the 'controller' of.

Returns

Returns a player object, if there isn't a driver, it will search the 'trailer chain' for the front driver, false otherwise.

Example

Click to collapse [-]
Server

This example outputs a chatbox message when a vehicle gets a trailer attached.

function scriptOnTrailerAttach ( towedBy )
  thePlayer = getVehicleController ( source ) -- get the controller of the towing vehicle
  if ( thePlayer ) then
    outputChatBox ( getPlayerName ( thePlayer ).. " attached a trailer" )
  else
    outputChatBox ( "trailer attached" )
  end
end
addEventHandler ( "onTrailerAttach", getRootElement(), scriptOnTrailerAttach )

See Also