Interact Options

Interact Options

All interact actions are formatted as an array containing objects with the following properties.

Option Type Definition

---@class InteractOption
---@field label string The display label for the option.
---@field icon? string The icon associated with the option.
---@field iconColor? string The CSS color for the icon.
---@field distance? number The maximum distance at which the option is available.
---@field holdTime? number Makes the option a press and hold and sets how long it should be held for (milliseconds).
---@field canInteract? fun(entity: number, distance: number, coords: vector3, name: string): boolean? A function to determine if the option can be interacted with.
---@field name? string A unique identifier for the option.
---@field resource? string The resource that registered the option.
---@field offset? vector3 A relative offset from the entity's position.
---@field offsetAbsolute? vector3 An absolute offset in world coordinates.
---@field color? number[] 4 numbers in an array used for RGBA, overwriting the theme color for that option.
---@field bones? string | string[] An array of bone IDs associated with the option.
---@field allowInVehicle? boolean Marks the option as being usable inside a vehicle.
---@field onSelect? fun(data: InteractResponse) A function to execute when the option is selected.
---@field cooldown? number Number of milliseconds the interact system should cooldown for after this option is selected. Prevents spam.
---@field export? string Optional export function name.
---@field event? string Client-side event to trigger.
---@field serverEvent? string Server-side event to trigger.
---@field command? string Command to execute.
---@field onActive? fun(data: InteractResponse) A function to execute when the option is active.
---@field onInactive? fun(data: InteractResponse) A function to execute when the option was active and is now inactive.
---@field whileActive? fun(data: InteractResponse) A function to execute while the option is active on a loop.

Properties

PropertyTypeRequiredDescription
labelstringYesThe display label for the option
iconstringNoFontAwesome icon name
iconColorstringNoCSS color for the icon
distancenumberNoMaximum distance at which the option is available
holdTimenumberNoPress-and-hold duration in milliseconds
canInteractfunctionNoFunction to determine if the option can be interacted with
namestringNoA unique identifier for the option
resourcestringNoThe resource that registered the option
offsetvector3NoRelative offset from the entity's position
offsetAbsolutevector3NoAbsolute offset in world coordinates
colornumber[]NoRGBA array {r, g, b, a} overriding the theme color
bonesstring | string[]NoBone ID(s) associated with the option
allowInVehiclebooleanNoAllow usage inside a vehicle
onSelectfunctionNoCallback when the option is selected
cooldownnumberNoCooldown in milliseconds after selection
exportstringNoExport function name to call
eventstringNoClient-side event to trigger
serverEventstringNoServer-side event to trigger
commandstringNoCommand to execute
onActivefunctionNoCallback when the option becomes active
onInactivefunctionNoCallback when the option becomes inactive
whileActivefunctionNoCallback that runs in a loop while the option is active

Callback Response

When a player selects an option, a single action is triggered in the following priority order:

  1. onSelect
  2. export
  3. event
  4. serverEvent
  5. command

The callback or event receives an InteractResponse table:

PropertyTypeDescription
entitynumberThe entity ID hit by the shape test. If triggering a server event, this is the network ID instead.
coordsvector3The resulting coordinates where the shape test hit a collision
distancenumberThe player's distance from the coords
zonenumber?The ID of the selected zone, if applicable

When using serverEvent, the entity value is automatically converted to a network ID so it can be resolved on the server.

Example

local options = {
    {
        label = "Talk to Ped",
        name = "talk_to_ped",
        icon = "comments",
        distance = 2.0,
        cooldown = 1500,
        onSelect = function(data)
            print("Talking to ped", data.entity)
        end,
        canInteract = function(entity, distance, coords, name)
            return distance < 2.0
        end,
    },
    {
        label = "Rob Ped",
        name = "rob_ped",
        icon = "hand-holding-dollar",
        distance = 1.5,
        holdTime = 3000,
        serverEvent = "myresource:robPed",
    },
}