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:
Eralp
2021-09-26 15:44:51 +03:00
committed by GitHub
parent 39b55b27fd
commit 997f4b00ac
+26 -18
View File
@@ -177,29 +177,37 @@ function QBCore.Functions.GetPlayersFromCoords(coords, distance)
return closePlayers return closePlayers
end end
function QBCore.Functions.GetClosestVehicle() function QBCore.Functions.GetClosestVehicle(coords)
local ped = PlayerPedId() local vehicles = GetGamePool('CVehicle')
local coords = GetEntityCoords(ped) local closestDistance = -1
local vehicles = GetGamePool('CVehicle') local closestVehicle = -1
local closestDistance = -1 local coords = coords
local closestVehicle = -1
for i = 1, #vehicles, 1 do if coords == nil then
local vehicleCoords = GetEntityCoords(vehicles[i]) local playerPed = PlayerPedId()
local distance = #(vehicleCoords - coords) coords = GetEntityCoords(playerPed)
if closestDistance == -1 or closestDistance > distance then end
closestVehicle = vehicles[i] for i=1, #vehicles, 1 do
closestDistance = distance local vehicleCoords = GetEntityCoords(vehicles[i])
end local distance = #(vehicleCoords - coords)
end
return closestVehicle, closestDistance if closestDistance == -1 or closestDistance > distance then
closestVehicle = vehicles[i]
closestDistance = distance
end
end
return closestVehicle,closestDistance
end end
function QBCore.Functions.GetClosestObject() function QBCore.Functions.GetClosestObject(coords)
local ped = PlayerPedId() local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local objects = GetGamePool('CObject') local objects = GetGamePool('CObject')
local closestDistance = -1 local closestDistance = -1
local closestObject = -1 local closestObject = -1
local coords = coords
if coords == nil then
coords = GetEntityCoords(ped)
end
for i = 1, #objects, 1 do for i = 1, #objects, 1 do
local objectCoords = GetEntityCoords(objects[i]) local objectCoords = GetEntityCoords(objects[i])
local distance = #(objectCoords - coords) local distance = #(objectCoords - coords)
@@ -208,7 +216,7 @@ function QBCore.Functions.GetClosestObject()
closestDistance = distance closestDistance = distance
end end
end end
return closestObject, closestDistance return closestObject,closestDistance
end end
-- Vehicle -- Vehicle