Skip to content

GetPlayersInRange

The players in the world within a radius of a point, nearest first.

A role-play mode’s “who hears this”: every spawned player within radius metres of x, y, z, the nearest first. With world only the players of that virtual world count; without it, every world. The point may be a player’s own position - they are in the list then.

GetPlayersInRange(x, y, z, radius [, world])
Parameter Type
x number metres
y number metres
z number metres
radius number metres
world number a virtual world; nil = any (optional)

table - a list of pids, nearest first

-- those within 20 m see the speaker's chat bubble; the line itself goes out with SendClientMessageInRange
local x, y, z = GetPlayerPos(pid)
for _, other in ipairs(GetPlayersInRange(x, y, z, 20, GetPlayerVirtualWorld(pid))) do
if other ~= pid then Log(GetPlayerName(other) .. " hears " .. GetPlayerName(pid)) end
end

GetPlayers · GetPlayerPos · SendClientMessageInRange · SetPlayerChatBubble · the Players group of the index