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
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