GetNearestVehicle: Difference between revisions
Jump to navigation
Jump to search
(Redirected page to Multi Theft Auto: Wiki:GetNearestVehicle) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Useful Function}} | {{Useful Function}} | ||
==Syntax== | |||
<syntaxhighlight lang="lua">vehicle getNearestVehicle( element thePlayer )</syntaxhighlight> | |||
===Required Arguments=== | |||
* '''thePlayer''': The player you want to get the nearest vehicle of. | |||
===Returns=== | |||
Return a vehicle element if success, false if there's no vehicles in a 10meter circle.. | |||
==Code== | |||
<section name="Server- and/or clientside Script" class="both" show="true"> | |||
<syntaxhighlight lang="lua"> | |||
function getNearestVehicle(player,distance) | |||
local tempTable = {} | |||
local lastMinDis = distance-0.0001 | |||
local nearestVeh = false | |||
local px,py,pz = getElementPosition(player) | |||
for _,v in pairs(getElementsByType("vehicle")) do | |||
local vx,vy,vz = getElementPosition(v) | |||
local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) | |||
if dis < distance then | |||
if dis < lastMinDis then | |||
lastMinDis = dis | |||
nearestVeh = v | |||
end | |||
end | |||
end | |||
return nearestVeh | |||
end | |||
</syntaxhighlight></section> |
Revision as of 19:29, 19 July 2017
Syntax
vehicle getNearestVehicle( element thePlayer )
Required Arguments
- thePlayer: The player you want to get the nearest vehicle of.
Returns
Return a vehicle element if success, false if there's no vehicles in a 10meter circle..
Code
Click to collapse [-]
Server- and/or clientside Scriptfunction getNearestVehicle(player,distance) local tempTable = {} local lastMinDis = distance-0.0001 local nearestVeh = false local px,py,pz = getElementPosition(player) for _,v in pairs(getElementsByType("vehicle")) do local vx,vy,vz = getElementPosition(v) local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) if dis < distance then if dis < lastMinDis then lastMinDis = dis nearestVeh = v end end end return nearestVeh end