Hello everyone!
This one I’ve been looking for some time but I didn’t find an answer.
I’ve created a function to get all players in a specific radius. Now I want to display a UI to all thoose players, but only when the “local player” press a key.
Here is my code (client side script)
local ped
local radius = 20.0
local keybind = 20 -- Z (keyboard)
function GetPlayersInRadius()
if not ped then return end
local players = GetPlayers()
local coords = GetEntityCoords(ped)
for _,v in pairs(players) do
local nearPed = GetPlayerPed(v)
if nearPed ~= ped then
local nearCoords = GetEntityCoords(nearPed)
if GetDistanceBetweenCoords(coords.x, coords.y, coords.z, nearCoords.x, nearCoords.y, nearCoords.z, true) <= radius then
return nearPed
end
end
end
return false
end
CreateThread(function()
while true do
Wait(0)
ped = PlayerPedId()
if IsControlJustPressed(0, keybind) then
local nearPed = GetPlayersInRadius()
if nearPed then
SendNUIMessage({ var1: "test" })
-- I want this UI to appear only to 'nearPed'
end
end
end
end)
I believe I need to create a thread specific to that player… but how?
Thanks for reading!