mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
GetPlayersFromCoords - Converted from qb/esx
gets all players within an area
This commit is contained in:
@@ -10,6 +10,28 @@ function NDCore.Functions.GetCharacters()
|
|||||||
return NDCore.Characters
|
return NDCore.Characters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function NDCore.Functions.GetPlayersFromCoords(coords, distance)
|
||||||
|
local players = GetActivePlayers()
|
||||||
|
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
|
||||||
|
distance = distance or 5
|
||||||
|
local closePlayers = {}
|
||||||
|
for _, player in pairs(players) do
|
||||||
|
local target = GetPlayerPed(player)
|
||||||
|
local targetCoords = GetEntityCoords(target)
|
||||||
|
local targetdistance = #(targetCoords - coords)
|
||||||
|
if targetdistance <= distance then
|
||||||
|
closePlayers[#closePlayers + 1] = player
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return closePlayers
|
||||||
|
end
|
||||||
|
|
||||||
-- Callbacks are licensed under LGPL v3.0
|
-- Callbacks are licensed under LGPL v3.0
|
||||||
-- <https://github.com/overextended/ox_lib>
|
-- <https://github.com/overextended/ox_lib>
|
||||||
NDCore.callback = {}
|
NDCore.callback = {}
|
||||||
@@ -56,4 +78,4 @@ function NDCore.callback.register(name, callback)
|
|||||||
RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...)
|
RegisterNetEvent(("ND:%s_cb"):format(name), function(key, ...)
|
||||||
TriggerServerEvent("ND:callbacks", key, callback(...))
|
TriggerServerEvent("ND:callbacks", key, callback(...))
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user