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
| Resource | es_extended (implemented in esx_lib) |
| Side | Client |
| 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)| Name | Type | Description |
|---|---|---|
name | string | Unique name. Registering the same name again replaces the old interaction. |
onPress | function | Runs when the key is pressed and the condition passes. |
condition | function? | Returns true when the interaction is allowed. Default: always true. Errors in it count as false. |
Returns: nothing
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)| Name | Type | Description |
|---|---|---|
name | string | Name 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.
Related
Frequently asked questions
Independent documentation
Last updated on
ESX.Game
ESX.Game client reference for ESX Legacy - spawn and delete vehicles and objects, find the closest player or vehicle, and get or set vehicle properties.
Scaleform
ESX.Scaleform functions show GTA scaleforms like the wasted shard, breaking news and popup warnings, plus helpers to load movies and call scaleform methods.