Multi Theft Auto: Wiki:GetNearestVehicle: Difference between revisions
Jump to navigation
Jump to search
(Created page with "==Syntax== <syntaxhighlight lang="lua">vehicle getNearestVehicle( element thePlayer )</syntaxhighlight> ===Required Arguments=== * '''thePlayer''': The player you want to get...") |
m (Pirulax moved page GetNearestVehicle to Multi Theft Auto: Wiki:GetNearestVehicle) |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua">vehicle getNearestVehicle( element thePlayer )</syntaxhighlight> | <syntaxhighlight lang="lua">vehicle getNearestVehicle( element thePlayer, float distance )</syntaxhighlight> | ||
===Required Arguments=== | ===Required Arguments=== | ||
* '''thePlayer''': The player you want to get the nearest vehicle of. | * '''thePlayer''': The player you want to get the nearest vehicle of. | ||
* '''distance''': The distance to search for vehicles in. | |||
===Returns=== | |||
Return a vehicle element if success, returns false if thers no vehicles in the specified distance. | |||
==Code== | ==Code== | ||
<section name="Server- and/or clientside Script" class="both" show="true"> | <section name="Server- and/or clientside Script" class="both" show="true"> | ||
<syntaxhighlight lang="lua"> | |||
function getNearestVehicle(player,distance) | function getNearestVehicle(player,distance) | ||
local lastMinDis = distance-0.0001 | local lastMinDis = distance-0.0001 | ||
local nearestVeh = false | local nearestVeh = false | ||
local pint = getElemnetInterior(player) | |||
local pdim = getElementDimension(player) | |||
local px,py,pz = getElementPosition(player) | local px,py,pz = getElementPosition(player) | ||
for _,v in pairs(getElementsByType("vehicle")) do | for _,v in pairs(getElementsByType("vehicle")) do | ||
local vx,vy,vz = getElementPosition(v) | local vx,vy,vz = getElementPosition(v) | ||
local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) | local dis = getDistanceBetweenPoints3D(px,py,pz,vx,vy,vz) | ||
if dis < distance then | local vdim = getElementDimension(v) | ||
local vint = getElemnetInterior(v) | |||
if dis < distance and vint == pint and vdim == pdim then | |||
if dis < lastMinDis then | if dis < lastMinDis then | ||
lastMinDis = dis | lastMinDis = dis | ||
Line 26: | Line 31: | ||
return nearestVeh | return nearestVeh | ||
end | end | ||
</syntaxhighlight></section> | </syntaxhighlight></section> |
Latest revision as of 19:25, 19 July 2017
Syntax
vehicle getNearestVehicle( element thePlayer, float distance )
Required Arguments
- thePlayer: The player you want to get the nearest vehicle of.
- distance: The distance to search for vehicles in.
Returns
Return a vehicle element if success, returns false if thers no vehicles in the specified distance.
Code
Click to collapse [-]
Server- and/or clientside Scriptfunction getNearestVehicle(player,distance) local lastMinDis = distance-0.0001 local nearestVeh = false local pint = getElemnetInterior(player) local pdim = getElementDimension(player) 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) local vdim = getElementDimension(v) local vint = getElemnetInterior(v) if dis < distance and vint == pint and vdim == pdim then if dis < lastMinDis then lastMinDis = dis nearestVeh = v end end end return nearestVeh end