GetPlayerContactElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Client function}} <!-- Describe in plain english what this function does. Don't go into details, just give an overview --> This function detects the vehicle a player is standi...)
 
(Removed comments, updated page, improved example)
Line 1: Line 1:
__NOTOC__  
__NOTOC__
{{Client function}}
{{Client function}}
<!-- Describe in plain english what this function does. Don't go into details, just give an overview -->
This function detects the element a player is standing on. This can be a vehicle or an object.
This function detects the vehicle a player is standing on.


==Syntax==  
==Syntax==  
<!-- NOTE: don't use 'special' names for variable names, e.g. you shouldn't be writing things like 'player player, vehicle vehicle', instead write something like 'player thePlayer, vehicle vehicleToGetInto'. This is less confusing and prevents the syntax highlighting being odd -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getPlayerContactElement ( player thePlayer )
element getPlayerContactElement ( player thePlayer )
Line 11: Line 9:


===Required Arguments===  
===Required Arguments===  
<!-- List each argument one per line. This should be the argument's name as in the argument list above, NOT the argument's data type -->
*'''thePlayer:''' The [[player]] you want to get the [[element]] he is touching from.
*'''thePlayer:''' The player you want to get the vehicle he is touching from.


===Returns===
===Returns===
<!-- Make this descriptive. Explain what cases will return false. If you're unsure, add a tag to it so we can check -->
Returns an [[object]] or a [[vehicle]] if the player is standing on one, ''false'' if he is touching none or is a invalid player.
Returns a [[vehicle]] if the player is touching one, ''false'' if he is touching none or is a invalid player.


==Example==  
==Example==  
<!-- Explain what the example is in a single sentance -->
This clientside function outputs the name of the vehicle the specified player is standing on, or a message saying he isn't on one.
This example shows the name of the vehicle the player is standing on. It will output 'false' if he is not.
<!-- Add the code below, an emphasis should be on making it clear, not optimized. You could provide two versions if you wish, one clear and well commented, the other optimized -->
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local vehicle = getPlayerContactVehicle ( getLocalPlayer() )
function outputContactVehicleMessage ( thePlayer )
local name = getVehicleName(vehicle)
  local elementStandingOn = getPlayerContactElement( thePlayer )
outputChatBox(tostring(name))
  if getElementType( elementStandingOn ) == "vehicle" then
    local vehicleName = getVehicleName( elementStandingOn )
    outputChatBox( "The player is standing on a " .. vehicleName .. "." )
  else
    outputChatBox( "The player isn't standing on any vehicle." )
  end
end
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
<!-- Change FunctionArea to the area that this function is in on the main function list page, e.g. Server, Player, Vehicle etc -->
{{Player functions}}
{{Player functions}}

Revision as of 16:59, 8 August 2007

This function detects the element a player is standing on. This can be a vehicle or an object.

Syntax

element getPlayerContactElement ( player thePlayer )

Required Arguments

  • thePlayer: The player you want to get the element he is touching from.

Returns

Returns an object or a vehicle if the player is standing on one, false if he is touching none or is a invalid player.

Example

This clientside function outputs the name of the vehicle the specified player is standing on, or a message saying he isn't on one.

function outputContactVehicleMessage ( thePlayer )
  local elementStandingOn = getPlayerContactElement( thePlayer )
  if getElementType( elementStandingOn ) == "vehicle" then
    local vehicleName = getVehicleName( elementStandingOn )
    outputChatBox( "The player is standing on a " .. vehicleName .. "." )
  else
    outputChatBox( "The player isn't standing on any vehicle." )
  end
end

See Also