mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:08:57 +00:00
fix closestObject/closestVehicle coords
In the previous version we could check the coordinates. In this, we automatically get the coordinate of the player. I hadn't noticed this yesterday when I was testing it. I am attaching this fix. Available in before "Major update" version.
This commit is contained in:
+26
-18
@@ -177,29 +177,37 @@ function QBCore.Functions.GetPlayersFromCoords(coords, distance)
|
||||
return closePlayers
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetClosestVehicle()
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
local closestDistance = -1
|
||||
local closestVehicle = -1
|
||||
for i = 1, #vehicles, 1 do
|
||||
local vehicleCoords = GetEntityCoords(vehicles[i])
|
||||
local distance = #(vehicleCoords - coords)
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestVehicle = vehicles[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestVehicle, closestDistance
|
||||
function QBCore.Functions.GetClosestVehicle(coords)
|
||||
local vehicles = GetGamePool('CVehicle')
|
||||
local closestDistance = -1
|
||||
local closestVehicle = -1
|
||||
local coords = coords
|
||||
|
||||
if coords == nil then
|
||||
local playerPed = PlayerPedId()
|
||||
coords = GetEntityCoords(playerPed)
|
||||
end
|
||||
for i=1, #vehicles, 1 do
|
||||
local vehicleCoords = GetEntityCoords(vehicles[i])
|
||||
local distance = #(vehicleCoords - coords)
|
||||
|
||||
if closestDistance == -1 or closestDistance > distance then
|
||||
closestVehicle = vehicles[i]
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestVehicle,closestDistance
|
||||
end
|
||||
|
||||
function QBCore.Functions.GetClosestObject()
|
||||
function QBCore.Functions.GetClosestObject(coords)
|
||||
local ped = PlayerPedId()
|
||||
local coords = GetEntityCoords(ped)
|
||||
local objects = GetGamePool('CObject')
|
||||
local closestDistance = -1
|
||||
local closestObject = -1
|
||||
local coords = coords
|
||||
if coords == nil then
|
||||
coords = GetEntityCoords(ped)
|
||||
end
|
||||
for i = 1, #objects, 1 do
|
||||
local objectCoords = GetEntityCoords(objects[i])
|
||||
local distance = #(objectCoords - coords)
|
||||
@@ -208,7 +216,7 @@ function QBCore.Functions.GetClosestObject()
|
||||
closestDistance = distance
|
||||
end
|
||||
end
|
||||
return closestObject, closestDistance
|
||||
return closestObject,closestDistance
|
||||
end
|
||||
|
||||
-- Vehicle
|
||||
|
||||
Reference in New Issue
Block a user