Notice: Failed to invoke Pygments: [Called from MediaWiki\SyntaxHighlight\SyntaxHighlight::highlightInner in /home/pi/www/gtac/wiki/wiki/extensions/SyntaxHighlight_GeSHi/includes/SyntaxHighlight.php at line 334] in /home/pi/www/gtac/wiki/wiki/includes/debug/MWDebug.php on line 507
getNearestVehicleInRange - GTA Connected

getNearestVehicleInRange

Revision as of 16:59, 3 February 2019 by Mex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Fetch the nearest vehicle from a position and range

Code

Lua, Server & Client-Side, GTAC versions 1.1.10 and newer:

function getNearestVehicleInRange(position, distance)
    distance = distance or 5
    for index, vehicle in pairs(getVehicles()) do
        if position:distance(vehicle.position) <= distance then
            return vehicle
        end
    end
    return nil
end