Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Undo revision 41683 by AboShanab (talk))
Line 2: Line 2:
enjoy
enjoy
[[User:Drline|Drline]] 04:44, 30 October 2012 (UTC)
[[User:Drline|Drline]] 04:44, 30 October 2012 (UTC)
== getCountPlayerInTeam ==
{{Useful Function}}
__NOTOC__
This function checks if a specified [[ped]] or [[player]] is driving a [[vehicle]].
==Syntax==
<syntaxhighlight lang="lua">bool, vehicle isPedDrivingVehicle ( element ped )</syntaxhighlight>
===Arguments===
* '''ped''': a [[player]] or [[ped]] to check if it's driving a [[vehicle]] or not.
===Returns===
Returns ''true'' and a vehicle if the specified ped is driving a [[vehicle]], ''false'' if it's not or a bad argument was passed.
==Code==
<section name="Function source" class="both" show="true">
<syntaxhighlight lang="lua">
function isPedDrivingVehicle(ped)
    assert(isElement(ped) and (getElementType(ped) == "ped" or getElementType(ped) == "player"), "Bad argument @ isPedDrivingVehicle [ped/player expected, got " .. tostring(ped) .. "]")
    local isDriving = isPedInVehicle(ped) and getVehicleOccupant(getPedOccupiedVehicle(ped)) == ped
    return isDriving, isDriving and getPedOccupiedVehicle(ped) or nil
end
</syntaxhighlight>
</section>
==Example==
<section name="Server" class="server" show="true">
This example adds a /amidriving command which tells the player who types it if it's driving or not.
<syntaxhighlight lang="lua">addCommandHandler ( "amidriving",
function ( player )
local driving, vehicle = isPedDrivingVehicle ( player )
if driving then
outputChatBox ( "* You are driving a "..getVehicleName(vehicle)..".", player, 255, 255, 0, true )
else
outputChatBox ( "* You are not driving.", player, 255, 0, 0, true )
end
end
)</syntaxhighlight></section>
==See also==
{{Useful_Functions}}

Revision as of 10:35, 30 August 2014

there i wrote isElementInPhotograph() enjoy Drline 04:44, 30 October 2012 (UTC)