From 997f4b00ac2628b7fc0247e297daed51ae9ef582 Mon Sep 17 00:00:00 2001 From: Eralp Date: Sun, 26 Sep 2021 15:44:51 +0300 Subject: [PATCH 1/3] 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. --- client/functions.lua | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 6df151f..0ff2ce1 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -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 From 7bbab4ce6584f5eda1fb717bec839ea1f72ec3ad Mon Sep 17 00:00:00 2001 From: Eralp Date: Sun, 26 Sep 2021 15:49:51 +0300 Subject: [PATCH 2/3] visual editing visual editing and fix for new build --- client/functions.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 0ff2ce1..f7ff671 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -141,10 +141,11 @@ function QBCore.Functions.GetClosestPed(coords, ignoreList) end function QBCore.Functions.GetClosestPlayer(coords) + local ped = PlayerPedId() if coords == nil then - coords = GetEntityCoords(PlayerPedId()) + coords = GetEntityCoords(ped) end - local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords) + local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords) local closestDistance = -1 local closestPlayer = -1 for i=1, #closestPlayers, 1 do @@ -178,14 +179,13 @@ function QBCore.Functions.GetPlayersFromCoords(coords, distance) end function QBCore.Functions.GetClosestVehicle(coords) + local ped = PlayerPedId() local vehicles = GetGamePool('CVehicle') local closestDistance = -1 local closestVehicle = -1 local coords = coords - if coords == nil then - local playerPed = PlayerPedId() - coords = GetEntityCoords(playerPed) + coords = GetEntityCoords(ped) end for i=1, #vehicles, 1 do local vehicleCoords = GetEntityCoords(vehicles[i]) @@ -204,7 +204,7 @@ function QBCore.Functions.GetClosestObject(coords) local objects = GetGamePool('CObject') local closestDistance = -1 local closestObject = -1 - local coords = coords + local coords = coords if coords == nil then coords = GetEntityCoords(ped) end From 567289f0e0d3cd99f25b145e07176f955e2219a7 Mon Sep 17 00:00:00 2001 From: Eralp Date: Mon, 27 Sep 2021 23:24:05 +0300 Subject: [PATCH 3/3] Post-check fix Post-check fix . Fixes after the check by @AvarianKnight --- client/functions.lua | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index f7ff671..a3e96f3 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -142,9 +142,7 @@ end function QBCore.Functions.GetClosestPlayer(coords) local ped = PlayerPedId() - if coords == nil then - coords = GetEntityCoords(ped) - end + local coords = coords or GetEntityCoords(ped) local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords) local closestDistance = -1 local closestPlayer = -1 @@ -183,10 +181,7 @@ function QBCore.Functions.GetClosestVehicle(coords) local vehicles = GetGamePool('CVehicle') local closestDistance = -1 local closestVehicle = -1 - local coords = coords - if coords == nil then - coords = GetEntityCoords(ped) - end + local coords = coords or GetEntityCoords(ped) for i=1, #vehicles, 1 do local vehicleCoords = GetEntityCoords(vehicles[i]) local distance = #(vehicleCoords - coords) @@ -196,7 +191,7 @@ function QBCore.Functions.GetClosestVehicle(coords) closestDistance = distance end end - return closestVehicle,closestDistance + return closestVehicle, closestDistance end function QBCore.Functions.GetClosestObject(coords) @@ -204,10 +199,7 @@ function QBCore.Functions.GetClosestObject(coords) local objects = GetGamePool('CObject') local closestDistance = -1 local closestObject = -1 - local coords = coords - if coords == nil then - coords = GetEntityCoords(ped) - end + local coords = coords or GetEntityCoords(ped) for i = 1, #objects, 1 do local objectCoords = GetEntityCoords(objects[i]) local distance = #(objectCoords - coords) @@ -216,7 +208,7 @@ function QBCore.Functions.GetClosestObject(coords) closestDistance = distance end end - return closestObject,closestDistance + return closestObject, closestDistance end -- Vehicle