FiveM Docs
es_extendedClientModules

Interactions

Use ESX.RegisterInteraction, ESX.RemoveInteraction and ESX.GetInteractKey to bind world actions to the shared ESX interact key (E by default).

Interactions connect an action to the shared ESX interact key. You register a name, a function to run on key press and an optional condition. When the player presses the key, every interaction whose condition returns true runs. Combined with points this replaces the old while true do ... IsControlJustReleased(0, 38) loops.

Overview

Resourcees_extended (implemented in esx_lib)
SideClient
Key mapping+esx_interact, default key E, label "Interact"

Interactions are removed automatically when the resource that registered them stops.

Functions

ESX.RegisterInteraction

ESX.RegisterInteraction(name, onPress, condition)
NameTypeDescription
namestringUnique name. Registering the same name again replaces the old interaction.
onPressfunctionRuns when the key is pressed and the condition passes.
conditionfunction?Returns true when the interaction is allowed. Default: always true. Errors in it count as false.

Returns: nothing

client/main.lua
local nearArmory = false

local armory = ESX.Point:new({
    coords = vector3(452.6, -980.0, 30.7),
    distance = 1.5,
    enter = function()
        nearArmory = true
        ESX.TextUI(('[%s] Open armory'):format(ESX.GetInteractKey()))
    end,
    leave = function()
        nearArmory = false
        ESX.HideUI()
    end,
})

ESX.RegisterInteraction('police_armory', function()
    OpenArmoryMenu()
end, function()
    return nearArmory and ESX.PlayerData.job.name == 'police'
end)

Without a condition, onPress runs on every key press anywhere on the map. Always pass a condition unless that is what you want.

ESX.RemoveInteraction

ESX.RemoveInteraction(name)
NameTypeDescription
namestringName used in RegisterInteraction.

Returns: nothing

ESX.RemoveInteraction('police_armory')

ESX.GetInteractKey

ESX.GetInteractKey()

Returns: string, the label of the key currently bound to +esx_interact (for example E).

ESX.ShowHelpNotification(('Press %s to talk'):format(ESX.GetInteractKey()), true)

Common issues

  • Two interactions fire at once. Every interaction with a passing condition runs. Make conditions specific (distance, job, vehicle state).
  • Interaction stops working after a restart. It belongs to the resource that registered it. Register it again when your resource starts.

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