GetPlayersInRange

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 14:37, 11 October 2026 by QCherry (talk | contribs) (Document upcoming 0.1.8 character dimensions: six server APIs, three events and creator guide; not a release announcement)
Jump to navigation Jump to search

getPlayersInRange

Finds connected players around another player's latest position.

Syntax

table getPlayersInRange(int sourcePlayerId, number radiusMeters [, bool includeSource = true])

Parameters

Name Type Required Description
sourcePlayerId int yes The player at the centre of the search.
radiusMeters number yes Search radius in metres.
includeSource bool no Whether to include the centre player in the result.

Returns

Returns a 1-indexed array of player identifiers within the radius.

Examples

Send local chat to players within 20 metres:

for _, nearbyPlayer in ipairs(getPlayersInRange(playerId, 20, true)) do
    outputChatBox("[Local] " .. message, nearbyPlayer)
end

Notes

  • Available only in server-side resource scripts.

Dimension-aware query (from 0.1.8, currently in testing)

Only players in the same dimension as sourcePlayerId are included. Radius and includeSource retain their existing meaning. This is a behavior change in 0.1.8, not in public 0.1.7.

getPlayersWithinRange remains coordinate-based without an implicit dimension, and getPlayers remains global. See Character dimensions before adapting custom local chat, trade or interaction code.