Talk:Useful Functions: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(19 intermediate revisions by 6 users not shown)
Line 1: Line 1:
there i wrote isElementInPhotograph()
== Pending functions ==
enjoy
Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.
[[User:Drline|Drline]] 04:44, 30 October 2012 (UTC)


== getCountPlayerInTeam ==
* https://forum.mtasa.com/topic/122958-getworldfrommapposition/ - calculating the world position on a map image
* https://forum.mtasa.com/topic/122823-help-getscreenfromworldposition/ - more powerful screen coordinate function with border support


{{Useful Function}}
--[[User:Quiret|Quiret]] ([[User talk:Quiret|talk]]) 18:58, 17 March 2020 (UTC)
__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}}

Latest revision as of 18:59, 17 March 2020

Pending functions

Here are some functions that were developed as part of the MTA forums scripting section but have not yet been added to the list. Those could be useful to advanced resource crafters.

--Quiret (talk) 18:58, 17 March 2020 (UTC)