feat(GetClosestVehicle)
---Get the closest vehicle to given coordinates ---@param coords vector3|nil ---@param distanceScope number|nil ---@param includePlayerVeh boolean|nil ---@return number|nil, vector3|nil, number|nil
This commit is contained in:
1 parent
e6cea4c1ac
commit
59d22e9fa7
1 file changed
+34
@@ -426,6 +426,40 @@ function Utility.GetClosestPlayer(coords, distanceScope, includeMe)
|
|||||||
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
|
return closestPlayer, closestDistance, GetPlayerServerId(closestPlayer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Get the closest vehicle to given coordinates
|
||||||
|
---@param coords vector3|nil
|
||||||
|
---@param distanceScope number|nil
|
||||||
|
---@param includePlayerVeh boolean|nil
|
||||||
|
---@return number|nil, vector3|nil, number|nil
|
||||||
|
function Utility.GetClosestVehicle(coords, distanceScope, includePlayerVeh)
|
||||||
|
local vehicleEntity = nil
|
||||||
|
local vehicleNetID = nil
|
||||||
|
local vehicleCoords = nil
|
||||||
|
local selfCoords = coords or GetEntityCoords(cache.ped)
|
||||||
|
local closestDistance = distanceScope or 5
|
||||||
|
local includeMyVeh = includePlayerVeh or false
|
||||||
|
local gamePoolVehicles = GetGamePool("CVehicle")
|
||||||
|
|
||||||
|
local playerVehicle = IsPedInAnyVehicle(cache.ped, false) and GetVehiclePedIsIn(cache.ped, false) or 0
|
||||||
|
|
||||||
|
for i = 1, #gamePoolVehicles do
|
||||||
|
local thisVehicle = gamePoolVehicles[i]
|
||||||
|
if DoesEntityExist(thisVehicle) and (includeMyVeh or thisVehicle ~= playerVehicle) then
|
||||||
|
local thisVehicleCoords = GetEntityCoords(thisVehicle)
|
||||||
|
local distance = #(selfCoords - thisVehicleCoords)
|
||||||
|
if closestDistance == -1 or distance < closestDistance then
|
||||||
|
vehicleEntity = thisVehicle
|
||||||
|
vehicleNetID = NetworkGetNetworkIdFromEntity(vehicleEntity) or nil
|
||||||
|
vehicleCoords = thisVehicleCoords
|
||||||
|
closestDistance = distance
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return vehicleEntity, vehicleCoords, vehicleNetID
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Deprecated point functions (no changes)
|
-- Deprecated point functions (no changes)
|
||||||
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
|
function Utility.RegisterPoint(pointID, pointCoords, pointDistance, _onEnter, _onExit, _nearby)
|
||||||
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby)
|
return Point.Register(pointID, pointCoords, pointDistance, nil, _onEnter, _onExit, _nearby)
|
||||||
|
|||||||
Reference in new issue
Block a user