GetPedContactElement: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
m (Change in example error... *Before: client side. *After: server side)
(3 intermediate revisions by 3 users not shown)
Line 6: Line 6:
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element getPedContactElement ( ped thePed )
element getPedContactElement ( ped thePed )
</syntaxhighlight>  
</syntaxhighlight>
{{OOP||[[ped]]:getContactElement|contactElement}}


===Required Arguments===  
===Required Arguments===  
Line 15: Line 16:


==Example==
==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.
<section name="Server" class="server" show="true">
This function outputs the name of the vehicle the specified player is standing on, or a message saying he isn't on one.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputContactVehicleMessage ( thePlayer )
function outputContactVehicleMessage ( thePlayer )
     local elementStandingOn = getPedContactElement( thePlayer )
     local elementStandingOn = getPedContactElement ( thePlayer )
     if elementStandingOn ~= false and getElementType( elementStandingOn ) == "vehicle" then
     if elementStandingOn and getElementType ( elementStandingOn ) == "vehicle" then
         local vehicleName = getVehicleName( elementStandingOn )
         local vehicleName = getVehicleName ( elementStandingOn )
         outputChatBox( "The player is standing on a " .. vehicleName .. "." )
         outputChatBox( "You're standing on a " .. vehicleName .. "." )
     else
     else
         outputChatBox( "The player isn't standing on any vehicle." )
         outputChatBox( "You're not standing on any vehicle." )
     end
     end
end
end
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Ped functions}}
{{Ped functions}}
[[hu:getPedContactElement]]

Revision as of 10:26, 11 April 2020

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

Syntax

element getPedContactElement ( ped thePed )

OOP Syntax Help! I don't understand this!

Method: ped:getContactElement(...)
Variable: .contactElement


Required Arguments

  • thePed: The ped of which you want to get the element he is standing on.

Returns

Returns an object or a vehicle if the ped is standing on one, false if he is touching none or an invalid element was passed.

Example

Click to collapse [-]
Server

This 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 = getPedContactElement ( thePlayer )
    if elementStandingOn and getElementType ( elementStandingOn ) == "vehicle" then
        local vehicleName = getVehicleName ( elementStandingOn )
        outputChatBox( "You're standing on a " .. vehicleName .. "." )
    else
        outputChatBox( "You're not standing on any vehicle." )
    end
end

See Also