FiveM Docs
es_extendedClientImports

Points

ESX.Point creates proximity points with enter, leave and inside callbacks in ESX Legacy, replacing distance loops. Learn the options, methods and pitfalls.

ESX.Point is a small class for proximity triggers. You give it coordinates, a radius and callbacks for entering, leaving and staying inside. One shared loop does the distance checks for all points, which is cheaper than one while true loop per marker.

Overview

Resourcees_extended (implemented in esx_lib as xLib.point)
SideClient
Check interval500 ms for enter/leave, every frame while inside a point with inside

Creating a point

ESX.Point:new

local point = ESX.Point:new(properties)
PropertyTypeDescription
coordsvector3Center of the point.
distancenumberRadius in units.
hiddenboolean?Start hidden (no callbacks fire until shown).
enterfunction?function(self) when the player enters the radius.
leavefunction?function(self) when the player leaves the radius.
insidefunction?function(self, distance) every frame while inside.

Returns: the point object. It keeps coords, hidden, enter, leave, inside and an internal handle.

The callbacks are called as methods, so the first argument is the point itself and the distance is the second argument of inside.

client/main.lua
local shop = ESX.Point:new({
    coords = vector3(25.7, -1347.3, 29.5),
    distance = 2.0,
    enter = function(self)
        ESX.TextUI('[E] Open shop')
    end,
    leave = function(self)
        ESX.HideUI()
    end,
    inside = function(self, distance)
        if distance < 1.0 and IsControlJustReleased(0, 38) then
            OpenShopMenu()
        end
    end,
})

For key presses, consider ESX.RegisterInteraction instead of polling a control inside inside. Then you do not need the every-frame callback at all.

Methods

point:delete

point:delete()

Removes the point. leave is not called, so hide any UI yourself.

ESX.HideUI()
shop:delete()

point:toggle

point:toggle(hidden)
NameTypeDescription
hiddenboolean?true hides, false shows. Without an argument the state is flipped.

A hidden point is treated as out of range: if the player was inside, leave fires on the next check.

RegisterNetEvent('esx:setJob', function(job)
    shop:toggle(job.name ~= 'shopkeeper')
end)

Low-level functions

ESX.Point is built on three functions that are also exposed. You normally do not need them.

FunctionDescription
ESX.CreatePointInternal(coords, distance, hidden, enter, leave, inside)Creates a raw point. Returns a numeric handle. Callbacks get no self; inside gets distance.
ESX.RemovePointInternal(handle)Removes a raw point.
ESX.HidePointInternal(handle, hidden)Hides or shows a raw point.

Common issues

  • Errors in callbacks. An error in enter or leave is printed as point X from resource errored and the loop continues. An error in inside stops that point's inside calls until the player leaves and enters again.
  • point.currDistance is nil. That field does not exist. Use the second argument of inside.
  • Nothing happens. Check that coords is a vector3 and distance is set.

Frequently asked questions

Independent documentation

esx-fivem.com is a community project and is not affiliated with the ESX Framework team. Facts on this page were checked against the upstream source. Official resources: docs.esx-framework.org and github.com/esx-framework.
Edit on GitHub

Last updated on

On this page