Merge pull request #256 from Mojito-Fivem/fix/GetClosestX

fix(client/functions): GetClosestX type checking
This commit is contained in:
Kakarot
2021-10-16 10:31:22 -06:00
committed by GitHub
+32 -6
View File
@@ -154,7 +154,11 @@ end
function QBCore.Functions.GetClosestPed(coords, ignoreList)
local ped = PlayerPedId()
local coords = coords or GetEntityCoords(ped)
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
local ignoreList = ignoreList or {}
local peds = QBCore.Functions.GetPeds(ignoreList)
local closestDistance = -1
@@ -173,7 +177,11 @@ end
function QBCore.Functions.GetClosestPlayer(coords)
local ped = PlayerPedId()
local coords = coords or GetEntityCoords(ped)
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords)
local closestDistance = -1
local closestPlayer = -1
@@ -193,7 +201,12 @@ end
function QBCore.Functions.GetPlayersFromCoords(coords, distance)
local players = QBCore.Functions.GetPlayers()
local coords = coords or GetEntityCoords(PlayerPedId())
local ped = PlayerPedId()
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
local distance = distance or 5
local closePlayers = {}
for _, player in pairs(players) do
@@ -212,7 +225,11 @@ function QBCore.Functions.GetClosestVehicle(coords)
local vehicles = GetGamePool('CVehicle')
local closestDistance = -1
local closestVehicle = -1
local coords = coords or GetEntityCoords(ped)
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
for i = 1, #vehicles, 1 do
local vehicleCoords = GetEntityCoords(vehicles[i])
local distance = #(vehicleCoords - coords)
@@ -230,7 +247,11 @@ function QBCore.Functions.GetClosestObject(coords)
local objects = GetGamePool('CObject')
local closestDistance = -1
local closestObject = -1
local coords = coords or GetEntityCoords(ped)
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
for i = 1, #objects, 1 do
local objectCoords = GetEntityCoords(objects[i])
local distance = #(objectCoords - coords)
@@ -263,7 +284,12 @@ end
function QBCore.Functions.SpawnVehicle(model, cb, coords, isnetworked)
local model = GetHashKey(model)
local coords = coords or QBCore.Functions.GetCoords(PlayerPedId())
local ped = PlayerPedId()
if coords then
coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords
else
coords = GetEntityCoords(ped)
end
local isnetworked = isnetworked or true
if not IsModelInCdimage(model) then
return