# Interact (Target)

{% hint style="info" %}
If you're using [supported interact resource](https://none-fivem.gitbook.io/nonem/resources/supported-resources#interact-target) you dont have to make any changes in this section.
{% endhint %}

> You can override interact actions from `no-base/configure/client/interact.lua`

## Types

***

### Entry

| Field      | Type    | Description                   |
| ---------- | ------- | ----------------------------- |
| id         | string  | Unique id for entry           |
| label      | string  | Label for entry               |
| icon       | string? | Font awesome icon name        |
| event      | string  | Client event to trigger       |
| parameters | any?    | Parameters to pass with event |

### Distance

| Field  | Type    | Description                        |
| ------ | ------- | ---------------------------------- |
| radius | number? | Distance between entity and player |

### Options

| Field     | Type                      | Description                              |
| --------- | ------------------------- | ---------------------------------------- |
| distance  | [Distance](#distance)?    | Distance data                            |
| isEnabled | function(entity: number)? | Function to check is entity interactable |

## Examples

***

{% hint style="info" %}
This is an example of how we handle qb-target. Since we support qb-target internally you don't need to make any changes if you use qb-target.
{% endhint %}

{% hint style="warning" %}
Make sure to trigger the given event as in the example.
{% endhint %}

```lua
AddEventHandler("no-base:interact:qb", function(response)
    TriggerEvent(response.data.event, response.data.parameters, response.entity)
end)

Config.Interact = {
    AddEntryByModel = function(models, entries, options)
        local function canInteract(entity)
            return not options.isEnabled or options.isEnabled(entity)
        end

        local _entries = {}

        for _, entry in pairs(entries) do
            _entries[#_entries + 1] = {
                icon = "fas fa-" .. entry.icon,
                label = entry.label,
                event = "no-base:interact:qb",
                data = {event = entry.event, parameters = entry.parameters},
                distance = options.distance?.radius,
                bones = options.bone and {options.bone} or options.bones,
                canInteract = canInteract
            }
        end

        local resource = GetInvokingResource()
        local handler
        handler = AddEventHandler("onResourceStop", function(resName)
            if resName ~= resource then return end
            RemoveEventHandler(handler)

            local labels = {}

            for _, entry in pairs(_entries) do
                labels[#labels + 1] = entry.label
            end

            exports["qb-target"]:RemoveTargetModel(models, labels)
        end)

        return exports["qb-target"]:AddTargetModel(models, {
            options = _entries,
            distance = options.distance?.radius
        })
    end,
    AddEntryBySphereZone = function(coords, radius, entries, options)
        local zoneId = entries[1] and entries[1].id

        if not zoneId then return end

        local function canInteract(entity)
            return not options.isEnabled or options.isEnabled(entity)
        end

        local _entries = {}

        for _, entry in pairs(entries) do
            _entries[#_entries + 1] = {
                icon = "fas fa-" .. entry.icon,
                label = entry.label,
                event = "no-base:interact:qb",
                data = {event = entry.event, parameters = entry.parameters},
                distance = options.distance?.radius,
                bones = options.bone and {options.bone} or options.bones,
                canInteract = canInteract
            }
        end

        exports["qb-target"]:AddCircleZone(zoneId, coords, radius, {
            name = zoneId,
            useZ = true
        }, {
            options = _entries,
            distance = options.distance?.radius
        })

        local resource = GetInvokingResource()
        local handler
        handler = AddEventHandler("onResourceStop", function(resName)
            if resName ~= resource then return end
            RemoveEventHandler(handler)
            exports["qb-target"]:RemoveZone(zoneId)
        end)
    end
}
```

<details>

<summary>AddEntryByModel</summary>

Adds interaction to passed models.

### Parameters

* models: number\[]
* entries: [Entry](#entry)\[]
* options:[ Options](#options)

</details>

<details>

<summary>AddEntryBySphereZone</summary>

Adds interaction for sphere zone.

### Parameters

* coords: vector3
* radius: number
* entries: [Entry](#entry)\[]
* options:[ Options](#options)

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://none-fivem.gitbook.io/nonem/resources/no-base/configuration/interact-target.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
