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)| Parameter | Type | Description |
|---|---|---|
| entity | number | Entity handle |
| options | table | Array of target option tables |
| distance | number | Interaction 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)| Parameter | Type | Description |
|---|---|---|
| name | string | Unique zone name |
| coords | vector3 | Zone center position |
| size | vector3 | Zone dimensions |
| heading | number | Zone heading/rotation |
| options | table | Array of target options |
| useZ | boolean | Use Z-axis for detection (optional) |
AddGlobalPlayer
Adds targeting options to all players.
Bridge.Target.AddGlobalPlayer(options)| Parameter | Type | Description |
|---|---|---|
| options | table | Array of target options |
AddGlobalVehicle
Adds targeting options to all vehicles.
Bridge.Target.AddGlobalVehicle(options)| Parameter | Type | Description |
|---|---|---|
| options | table | Array of target options |
AddModel
Adds targeting options to all entities of a specific model.
Bridge.Target.AddModel(model, options, distance)| Parameter | Type | Description |
|---|---|---|
| model | string | number | Model name or hash |
| options | table | Array of target options |
| distance | number | Interaction distance |
RemoveLocalEntity
Removes targeting from a specific entity.
Bridge.Target.RemoveLocalEntity(entity)| Parameter | Type | Description |
|---|---|---|
| entity | number | Entity handle |
RemoveZone
Removes a targeting zone by name.
Bridge.Target.RemoveZone(name)| Parameter | Type | Description |
|---|---|---|
| name | string | Zone name |
RemoveGlobalPlayer
Removes global player targeting options.
Bridge.Target.RemoveGlobalPlayer(labels)| Parameter | Type | Description |
|---|---|---|
| labels | table | Array of option labels to remove |
RemoveGlobalVehicle
Removes global vehicle targeting options.
Bridge.Target.RemoveGlobalVehicle(labels)| Parameter | Type | Description |
|---|---|---|
| labels | table | Array of option labels to remove |
RemoveModel
Removes targeting from a model.
Bridge.Target.RemoveModel(model, labels)| Parameter | Type | Description |
|---|---|---|
| model | string | number | Model name or hash |
| labels | table | Array 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| Parameter | Type | Description |
|---|---|---|
| id | string | Unique 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| Parameter | Type | Description |
|---|---|---|
| callback | function | Function 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| Parameter | Type | Description |
|---|---|---|
| id | string | Interaction handler ID |
| … | any | Arguments 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| Parameter | Type | Description |
|---|---|---|
| options | table | Array of target option tables |
Returns: table - Processed options array with normalized callbacks
Description: Normalizes target options by:
- Converting
actioncallbacks toonSelect - Converting entity arguments to handle different target system signatures
- Processing
canInteractcallbacks 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)