-- Function to get nearby players
function GetPlayersInRadius(position, radius)
local players_in_radius = {}
local all_players = GetActivePlayers()
for _, player in ipairs(all_players) do
local player_ped = GetPlayerPed(player)
local player_pos = GetEntityCoords(player_ped)
local distance = #(position - player_pos)
if distance <= radius then
table.insert(players_in_radius, player)
end
end
return players_in_radius
end
-- Trigger this function with your event (for example, onCommand or onKeyPressed)
function TriggerEventInRadius(position, radius)
local players_in_radius = GetPlayersInRadius(position, radius)
for _, player in pairs(players_in_radius) do
TriggerClientEvent('your_event_name_here', player)
end
end
-- Replace vec3 with your actual Vector3
local vec3_position = vector3(0.0, 0.0, 0.0)
-- Trigger the event for players in a 30m radius from a Vector3 position
TriggerEventInRadius(vec3_position, 30)
In the example above, replace 'your_event_name_here' with the actual event name you want to trigger, and vector3(0.0, 0.0, 0.0) with the actual Vector3 position. Don't forget to also implement the event on the client side (i.e., create an event with the same name).