GetNearestPlayer2D

From Onset Developer Wiki
Revision as of 14:41, 26 June 2021 by FlyingFork (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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