GetNearestPlayer2D

From Onset Developer Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
GetNearestPlayer2D

Type: Function
Context: Server
Introduced: v1.0

Description

Gets the closest player in the specified range of XY. An important function which replaces the use of looping through all players and then checking if they are the closest.

Syntax

GetNearestPlayer2D(x, y)

Parameters

  • x
    The X axis
  • y
    The Y axis

Return Value

  • Returns the player identifier or false

Example

AddCommand("closest", function(player)
  local x, y, z = GetPlayerLocation(player)
  local target = GetNearestPlayer2D(x, y)

  return AddPlayerChat(player, "Closest player is: " .. GetPlayerName(target))
end)

See also