From 10a903c9e0e97d89866ee952502a221d95c1576d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Wed, 30 Aug 2017 18:04:22 +0200 Subject: [PATCH] Add ESX.GetClosestPed --- .../es_extended/client/functions.lua | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/resources/[essential]/es_extended/client/functions.lua b/resources/[essential]/es_extended/client/functions.lua index 87e53b3b..6857bae5 100644 --- a/resources/[essential]/es_extended/client/functions.lua +++ b/resources/[essential]/es_extended/client/functions.lua @@ -617,18 +617,54 @@ ESX.Game.GetVehiclesInArea = function(coords, area) return vehiclesInArea end -ESX.Game.GetPeds = function() - - local peds = {} +ESX.Game.GetPeds = function(ignoreList) + + local ignoreList = ignoreList or {} + local peds = {} for ped in EnumeratePeds() do - table.insert(peds, ped) + + local found = false + + for j=1, #ignoreList, 1 do + if ignoreList[j] == ped then + found = true + end + end + + if not found then + table.insert(peds, ped) + end + end return peds end +ESX.Game.GetClosestPed = function(coords, ignoreList) + + local ignoreList = ignoreList or {} + local peds = ESX.Game.GetPeds(ignoreList) + local closestDistance = -1 + local closestPed = -1 + + for i=1, #peds, 1 do + + local pedCoords = GetEntityCoords(peds[i]) + local distance = GetDistanceBetweenCoords(pedCoords.x, pedCoords.y, pedCoords.z, coords.x, coords.y, coords.z, true) + + if closestDistance == -1 or closestDistance > distance then + closestPed = peds[i] + closestDistance = distance + end + + end + + return closestPed, closestDistance + +end + ESX.Game.GetVehicleProperties = function(vehicle) local color1, color2 = GetVehicleColours(vehicle)