GetVehicleController: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}
{{Server client function}}
This function is used to get the player in control of the specified vehicle.
This function is used to get the player in control of the specified vehicle which includes somebody who is trying to enter the drivers seat.


==Syntax==  
==Syntax==  
Line 7: Line 7:
player getVehicleController ( vehicle theVehicle )             
player getVehicleController ( vehicle theVehicle )             
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[vehicle]]:getController|controller}}
===Required Arguments===  
===Required Arguments===  
*'''theVehicle:''' The vehicle you want to get the 'controller' of.
*'''theVehicle:''' the [[vehicle]] you want to get the 'controller' of.


===Returns===
===Returns===
Line 26: Line 26:
   end
   end
end
end
addEventHandler ( "onTrailerAttach", getRootElement(), scriptOnTrailerAttach )
addEventHandler ( "onTrailerAttach", root, scriptOnTrailerAttach )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Latest revision as of 09:09, 4 November 2020

This function is used to get the player in control of the specified vehicle which includes somebody who is trying to enter the drivers seat.

Syntax

player getVehicleController ( vehicle theVehicle )            

OOP Syntax Help! I don't understand this!

Method: vehicle:getController(...)
Variable: .controller


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", root, scriptOnTrailerAttach )

See Also