Target

The Target module provides entity and zone targeting. Bridges ox_target, qb-target, and sleepless_interact.

Client Functions

GetResourceName

Returns the target resource name.

local name = Bridge.Target.GetResourceName()
-- Returns: string (always "default")

Description: Returns the name of the Target module resource. Used for internal identification. Always returns "default" for the built-in Target module.

AddLocalEntity

Adds targeting options to a specific entity.

Bridge.Target.AddLocalEntity(entity, options, distance)
ParameterTypeDescription
entitynumberEntity handle
optionstableArray of target option tables
distancenumberInteraction distance

Option Format

{
    label = 'Talk to NPC',
    icon = 'fa-solid fa-comments',
    onSelect = function(entity)
        print('Selected!')
    end,
    canInteract = function(entity)
        return true -- optional condition
    end
}

AddBoxZone

Creates a box zone with targeting options.

Bridge.Target.AddBoxZone(name, coords, size, heading, options, useZ)
ParameterTypeDescription
namestringUnique zone name
coordsvector3Zone center position
sizevector3Zone dimensions
headingnumberZone heading/rotation
optionstableArray of target options
useZbooleanUse Z-axis for detection (optional)

AddGlobalPlayer

Adds targeting options to all players.

Bridge.Target.AddGlobalPlayer(options)
ParameterTypeDescription
optionstableArray of target options

AddGlobalVehicle

Adds targeting options to all vehicles.

Bridge.Target.AddGlobalVehicle(options)
ParameterTypeDescription
optionstableArray of target options

AddModel

Adds targeting options to all entities of a specific model.

Bridge.Target.AddModel(model, options, distance)
ParameterTypeDescription
modelstring | numberModel name or hash
optionstableArray of target options
distancenumberInteraction distance

RemoveLocalEntity

Removes targeting from a specific entity.

Bridge.Target.RemoveLocalEntity(entity)
ParameterTypeDescription
entitynumberEntity handle

RemoveZone

Removes a targeting zone by name.

Bridge.Target.RemoveZone(name)
ParameterTypeDescription
namestringZone name

RemoveGlobalPlayer

Removes global player targeting options.

Bridge.Target.RemoveGlobalPlayer(labels)
ParameterTypeDescription
labelstableArray of option labels to remove

RemoveGlobalVehicle

Removes global vehicle targeting options.

Bridge.Target.RemoveGlobalVehicle(labels)
ParameterTypeDescription
labelstableArray of option labels to remove

RemoveModel

Removes targeting from a model.

Bridge.Target.RemoveModel(model, labels)
ParameterTypeDescription
modelstring | numberModel name or hash
labelstableArray of option labels to remove

Internal Utility Functions

These functions are used internally for target interaction and condition evaluation. They are exported for advanced use cases.

GetCanInteract

Retrieves the interaction object for a given ID.

local interact = Bridge.Target.GetCanInteract(id)
-- Returns: table | nil
ParameterTypeDescription
idstringUnique interaction ID

Returns: table containing interaction data, or nil if not found

CreateCanInteract

Creates a new interaction handler with a custom condition callback.

local id = Bridge.Target.CreateCanInteract(callback)
-- Returns: string
ParameterTypeDescription
callbackfunctionFunction that returns boolean to determine if interaction is allowed

Returns: string - Unique ID for the interaction handler

Description: Creates an interaction condition handler. The callback function should return true if the target interaction should be allowed, false otherwise. The handler auto-resets after 1 second.

Example:

local id = Bridge.Target.CreateCanInteract(function(entity)
    local ped = PlayerPedId()
    local distance = #(GetEntityCoords(ped) - GetEntityCoords(entity))
    return distance < 5 -- Only allow interaction within 5 meters
end)

CanInteract

Evaluates whether an interaction is allowed based on its condition handler.

local allowed = Bridge.Target.CanInteract(id, ...)
-- Returns: boolean
ParameterTypeDescription
idstringInteraction handler ID
…anyArguments passed to the interaction condition callback

Returns: boolean - Whether interaction is allowed (true if handler doesn’t exist)

Description: Checks the condition callback for the given interaction ID. The first time called, it executes the callback with the provided arguments. Subsequent calls within 1 second return cached result.

FixOptions

Processes target option tables to fix compatibility between different target systems.

local fixedOptions = Bridge.Target.FixOptions(options)
-- Returns: table
ParameterTypeDescription
optionstableArray of target option tables

Returns: table - Processed options array with normalized callbacks

Description: Normalizes target options by:

  • Converting action callbacks to onSelect
  • Converting entity arguments to handle different target system signatures
  • Processing canInteract callbacks through the condition handler system

Example:

local options = {
    {
        label = 'Talk',
        action = function(entity) print('Talking to ' .. entity) end,
        canInteract = function(entity) return true end
    }
}
local fixed = Bridge.Target.FixOptions(options)