API and public exports
ox_target client exports verified in the 1.17.2 archive, the registerAction server export, public events, qtarget and qb-target compatibility, and the native option format.
Goal: add options from your own resources and register server actions without modifying ox_target. Where: in the code of your resources, not in ox_target’s files.
Client exports
These exports are defined in client/api.lua. Options are written in the native format (see below), not in the simplified config_interactions.lua format.
| Signature | Returns | Effect |
|---|---|---|
exports.ox_target:addBoxZone(data) | zone id (number) | ox_lib box zone (coords, size, rotation, options…). |
exports.ox_target:addSphereZone(data) | zone id (number) | ox_lib sphere zone (coords, radius, options…). |
exports.ox_target:addPolyZone(data) | zone id (number) | ox_lib polygon zone. Available through the API only: Config.ZoneInteractions only handles box and sphere. |
exports.ox_target:zoneExists(id) | boolean | Numeric id or zone name. |
exports.ox_target:removeZone(id, suppressWarning) | nothing | Removes a zone by id or name. |
exports.ox_target:addGlobalPlayer(options) | nothing | Options on every player. |
exports.ox_target:removeGlobalPlayer(names) | nothing | Removes options by name (calling resource only). |
exports.ox_target:addSelfTarget(options) | nothing | Options shown when the player targets themselves. |
exports.ox_target:removeSelfTarget(names) | nothing | Removes self options by name. |
exports.ox_target:addGlobalPed(options) | nothing | Options on every ped. |
exports.ox_target:removeGlobalPed(names) | nothing | Removes ped options by name. |
exports.ox_target:addGlobalVehicle(options) | nothing | Options on every vehicle. |
exports.ox_target:removeGlobalVehicle(names) | nothing | Removes vehicle options by name. |
exports.ox_target:addGlobalObject(options) | nothing | Options on every object. |
exports.ox_target:removeGlobalObject(names) | nothing | Removes object options by name. |
exports.ox_target:addGlobalOption(options) | nothing | Options shown on any target. |
exports.ox_target:removeGlobalOption(names) | nothing | Removes global options by name. |
exports.ox_target:addModel(models, options) | nothing | Options on one or more models (name or hash). |
exports.ox_target:removeModel(models, names) | nothing | Without names: removes every option of the model. |
exports.ox_target:addEntity(netIds, options) | nothing | Options on networked entities (netId). |
exports.ox_target:removeEntity(netIds, names) | nothing | Removes options from networked entities. |
exports.ox_target:addLocalEntity(entities, options) | nothing | Options on local entities (handle). |
exports.ox_target:removeLocalEntity(entities, names) | nothing | Removes options from local entities. |
exports.ox_target:getTargetOptions(entity, type, model) | table of applicable options | Without arguments: the current options object. |
exports.ox_target:disableTargeting(value) | nothing | true closes and blocks targeting; false allows it again. |
exports.ox_target:isActive() | boolean | Is targeting open? |
exports.ox_target:entityHasTargets(entity, entityType, model) | boolean | Does the entity have options (globals included)? |
exports.ox_target:entityHasSpecificTargets(entity, model) | boolean | Model, networked or local entity options only. |
exports.ox_target:getEntityTargetDistance(entity, entityType, model) | smallest distance (7 by default) | Minimum distance among applicable options. |
exports.ox_target:getEntitySpecificTargetDistance(entity, model) | largest distance, 0 without specific option | Used for the outline. |
Options added by a resource belong to it: remove… only removes the calling resource’s options, and they are removed automatically when that resource stops. Adding an option with a name already used by the same resource replaces the old one.
Native option format
exports.ox_target:addModel({ 'prop_vend_soda_01', 'prop_vend_soda_02' }, {
{
name = 'my_resource:soda',
label = 'Buy a drink',
icon = 'fa-solid fa-bottle-water',
distance = 1.5,
items = 'money',
onSelect = function(data)
TriggerServerEvent('my_resource:buySoda', data.coords)
end,
},
})
my_resource is an example name. Recognised native fields: name, label, icon, iconColor, distance, bones, offset, absoluteOffset, offsetSize, groups, items, anyItem, canInteract, onSelect, export, event, serverEvent, command. This edition’s NUI also reads description and separatorAfter.
Submenus in native format: openMenu = 'name' on the parent option (add isCategory = true to show the arrow) and menuName = 'name' on child options. Checkboxes (type = 'checkbox') are not available through exports: their state is managed by the engine for config_interactions.lua options only.
Here onSelect receives ox_target’s native data (entity, coords, distance, zone and the option fields), not the target object of the simplified format. With serverEvent, entity is converted to a network ID.
Server export
| Signature | Returns | Effect |
|---|---|---|
exports.ox_target:registerAction(name, def) | true when registered, false otherwise | Registers a secured server action from another resource. It is removed when that resource stops. Built-in action names are refused. |
exports.ox_target:registerAction(name, def)
name: string;def: table in theConfig.ServerActionsformat (see Hooks and server actions).- Returns
truewhen the action is registered,falseifdef.handleris not a function or ifnameis a built-in action. - An action registered by a resource is removed when that resource stops.
- A name already used by a custom action (including from
Config.ServerActions) is replaced.
CreateThread(function()
local ok = exports.ox_target:registerAction('my_garage:takeOut', {
permission = 'everyone',
jobs = { 'mechanic' },
target = 'vehicle',
maxDistance = 4.0,
cooldown = 3000,
handler = function(ctx)
TriggerEvent('my_garage:takeOutVehicle', ctx.source, ctx.netId)
end,
})
if not ok then
print('registerAction refused')
end
end)
Start your resource after ox_target. Client side, trigger the action with a type = 'server_action', action = 'my_garage:takeOut' option in config_interactions.lua: the engine’s internal network event is not a public API and is not documented.
Public events
| Event | Direction | Use |
|---|---|---|
ox_target:exitTrunk |
local client | TriggerEvent('ox_target:exitTrunk') makes the player leave the trunk. Events in Config.Vehicles.trunk.exitEvents do the same. |
ox_target:core:run |
server → client | Whitelisted routines: PlayEmote, Me, ReviveSelf, HealSelf, NativeRevive, NativeHeal. |
qtarget and qb-target compatibility
The resource declares provide 'qtarget' and provide 'qb-target'. The following exports are converted to the ox_target API:
- qtarget:
AddBoxZone,AddPolyZone,AddCircleZone,RemoveZone,AddTargetBone,AddTargetEntity,RemoveTargetEntity,AddTargetModel,RemoveTargetModel,Ped,RemovePed,Vehicle,RemoveVehicle,Object,RemoveObject,Player,RemovePlayer. - qb-target: the same zones and targets, plus
AddGlobalPed,AddGlobalVehicle,AddGlobalObject,AddGlobalPlayerand theirRemove…. - qb-target’s
AddEntityZoneandRemoveTargetBoneare not supported (no effect).
These conversions come from the original engine; test every script that uses them.
Common mistakes
- Using
menu/opensin an export: ignored; usemenuName/openMenu. - Calling an export before ox_target starts: “No such export” error. Fix the
ensureorder. - Expecting a checkbox through an export: not supported, go through
config_interactions.lua.