GetPlayersInRange: Difference between revisions

From Wiki G1R-MP G1 Remake Multiplayer
Jump to navigation Jump to search
Complete Lua function catalog
Release 0.1.8 / BUILD210 / Protocol 40: dimensions API availability, loading and UI fixes
 
(One intermediate revision by the same user not shown)
Line 36: Line 36:
[[Category:Server Functions]]
[[Category:Server Functions]]
[[Category:Player Functions]]
[[Category:Player Functions]]
<!-- dimensions018:start -->
== Dimension-aware query (since 0.1.8) ==
Only players in the same dimension as <code>sourcePlayerId</code> are included. Radius and <code>includeSource</code> 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.
<!-- dimensions018:end -->

Latest revision as of 21:03, 11 October 2026

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 (since 0.1.8)

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.