mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
fix(client/functions): GetClosestX type checking
This commit is contained in:
+21
-4
@@ -140,7 +140,11 @@ end
|
|||||||
|
|
||||||
function QBCore.Functions.GetClosestPed(coords, ignoreList)
|
function QBCore.Functions.GetClosestPed(coords, ignoreList)
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
local coords = coords or GetEntityCoords(ped)
|
if coords then
|
||||||
|
if type(coords) == 'table' then coords = vector3(coords.x, coords.y, coords.z) end
|
||||||
|
else
|
||||||
|
coords = GetEntityCoords(ped)
|
||||||
|
end
|
||||||
local ignoreList = ignoreList or {}
|
local ignoreList = ignoreList or {}
|
||||||
local peds = QBCore.Functions.GetPeds(ignoreList)
|
local peds = QBCore.Functions.GetPeds(ignoreList)
|
||||||
local closestDistance = -1
|
local closestDistance = -1
|
||||||
@@ -159,7 +163,11 @@ end
|
|||||||
|
|
||||||
function QBCore.Functions.GetClosestPlayer(coords)
|
function QBCore.Functions.GetClosestPlayer(coords)
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
local coords = coords or GetEntityCoords(ped)
|
if coords then
|
||||||
|
if type(coords) == 'table' then coords = vector3(coords.x, coords.y, coords.z) end
|
||||||
|
else
|
||||||
|
coords = GetEntityCoords(ped)
|
||||||
|
end
|
||||||
local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords)
|
local closestPlayers = QBCore.Functions.GetPlayersFromCoords(coords)
|
||||||
local closestDistance = -1
|
local closestDistance = -1
|
||||||
local closestPlayer = -1
|
local closestPlayer = -1
|
||||||
@@ -179,7 +187,12 @@ end
|
|||||||
|
|
||||||
function QBCore.Functions.GetPlayersFromCoords(coords, distance)
|
function QBCore.Functions.GetPlayersFromCoords(coords, distance)
|
||||||
local players = QBCore.Functions.GetPlayers()
|
local players = QBCore.Functions.GetPlayers()
|
||||||
local coords = coords or GetEntityCoords(PlayerPedId())
|
local ped = PlayerPedId()
|
||||||
|
if coords then
|
||||||
|
if type(coords) == 'table' then coords = vector3(coords.x, coords.y, coords.z) end
|
||||||
|
else
|
||||||
|
coords = GetEntityCoords(ped)
|
||||||
|
end
|
||||||
local distance = distance or 5
|
local distance = distance or 5
|
||||||
local closePlayers = {}
|
local closePlayers = {}
|
||||||
for _, player in pairs(players) do
|
for _, player in pairs(players) do
|
||||||
@@ -198,7 +211,11 @@ function QBCore.Functions.GetClosestVehicle(coords)
|
|||||||
local vehicles = GetGamePool('CVehicle')
|
local vehicles = GetGamePool('CVehicle')
|
||||||
local closestDistance = -1
|
local closestDistance = -1
|
||||||
local closestVehicle = -1
|
local closestVehicle = -1
|
||||||
local coords = coords or GetEntityCoords(ped)
|
if coords then
|
||||||
|
if type(coords) == 'table' then coords = vector3(coords.x, coords.y, coords.z) end
|
||||||
|
else
|
||||||
|
coords = GetEntityCoords(ped)
|
||||||
|
end
|
||||||
for i=1, #vehicles, 1 do
|
for i=1, #vehicles, 1 do
|
||||||
local vehicleCoords = GetEntityCoords(vehicles[i])
|
local vehicleCoords = GetEntityCoords(vehicles[i])
|
||||||
local distance = #(vehicleCoords - coords)
|
local distance = #(vehicleCoords - coords)
|
||||||
|
|||||||
Reference in New Issue
Block a user