PiTyUs.Hire me

Frameworks

Adding interactions with ox_target

Use ox_target in FiveM scripts: addModel, addGlobalVehicle/Ped/Player, addLocalEntity and addEntity, box and sphere zones, option fields (label, icon, distance, groups, items, canInteract, onSelect, serverEvent), convars, removing targets and performance tips.

Updated 11 min readBy PiTyUs · FiveM developer

Overview

Targeting (the “third eye”) replaced floating “press E” prompts on most roleplay servers: players hold Alt, look at an object, ped or vehicle and pick an action from a menu. ox_target is the most widely used implementation, and adding options to it is a few lines per interaction.

Targeting models

client.lua — every ATM in the maplua
exports.ox_target:addModel({ `prop_atm_01`, `prop_atm_02`, `prop_atm_03`, `prop_fleeca_atm` }, {
    {
        name = 'bank:atm',
        label = 'Use ATM',
        icon = 'fa-solid fa-credit-card',
        distance = 1.5,
        onSelect = function(data)
            TriggerEvent('bank:openAtm', data.entity)
        end,
    },
})

Global targets

client.lua — police option on every vehiclelua
exports.ox_target:addGlobalVehicle({
    {
        name = 'police:impound',
        label = 'Impound vehicle',
        icon = 'fa-solid fa-truck-pickup',
        groups = { police = 0 },
        distance = 2.5,
        canInteract = function(entity, distance)
            return GetVehicleNumberOfPassengers(entity) == 0 and IsVehicleSeatFree(entity, -1)
        end,
        serverEvent = 'police:impound',
    },
})

groups = { police = 0 } shows the option to police of grade 0 and above (ox_target reads the job from your framework). With serverEvent, the server receives a table that includes the entity’s network ID — validate it there.

Zones

client.lualua
local id = exports.ox_target:addBoxZone({
    coords = vec3(441.2, -981.9, 30.7),
    size = vec3(1.5, 1.0, 1.2),
    rotation = 0,
    debug = false,
    options = {
        { name = 'mrpd:duty', label = 'Toggle duty', icon = 'fa-solid fa-clipboard', groups = 'police', event = 'police:toggleDuty' },
        { name = 'mrpd:armory', label = 'Armory', icon = 'fa-solid fa-gun', groups = { police = 2 }, onSelect = function() exports.ox_inventory:openInventory('shop', { type = 'PoliceArmoury' }) end },
    },
})

-- exports.ox_target:removeZone(id)

Option fields

FieldMeaning
nameUnique ID, used to remove the option
label, icon, iconColorWhat the player sees (Font Awesome icons)
distanceMax distance (default 7)
groupsJob/gang name, list, or { job = minGrade }
items / anyItemRequired item(s)
bonesOnly when aiming at these bones (e.g. vehicle doors)
canInteractFunction returning true/false
onSelect / event / serverEvent / command / exportWhat happens on click

Specific entities

addLocalEntity(entity, options) targets an entity that exists only on this client (a shop NPC you spawned locally). addEntity(netIds, options) targets networked entities by network ID so it works for everyone — see network IDs.

Convars and performance

server.cfgcfg
setr ox_target:defaultHotkey LMENU   # default key (Left Alt)
setr ox_target:leftClick 1          # select with left click
setr ox_target:toggleHotkey 0       # hold instead of toggle
setr ox_target:debug 0
  • Prefer addModel or zones over global targets with heavy canInteract functions.
  • Keep canInteract free of callbacks and database calls — it runs repeatedly while targeting.
  • Remove dynamically added options when your resource stops.

Frequently asked questions

How do I add an ox_target option to a prop?

Use exports.ox_target:addModel({ model hashes }, { options }) in a client script.

How do I limit an option to a job?

Set groups = 'police' or groups = { police = 2 } for a minimum grade.

What key opens ox_target?

Left Alt by default; change it with the ox_target:defaultHotkey convar or in the player’s key bindings.

Why does my option not appear?

Check distance, groups, items and canInteract; enable debug for zones, and make sure the model hash is right.

Need this built, not just explained?

Ten years of FiveM work, from Lua to NUI

Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.

Related guides