ESX.Game.GetClosestPlayer

1
ESX.Game.GetClosestPlayer(coords)

This function gets the closest player.

Arguments

Argument Data Type Optional Default Value Explanation
coords vector3 Yes (player's coords) The coords to search at

ESX.Game.GetClosestPlayer Example

1
2
3
4
5
6
7
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()

if closestPlayer == -1 or closestDistance > 3.0 then
    ESX.ShowNotification('There\'s no players nearby you!')
else
    ESX.ShowNotification(('Found %s, they are %s unit(s) away'):format(GetPlayerName(closestPlayer), closestDistance))
end