CU Enhanced Target
Usage

Usage Examples

This page shows common usage patterns. All examples use exports.cu_enchanced_target. If you renamed the folder to ox_target or qb-target, update the export name accordingly.

Zone Examples

Sphere Zone

Create a spherical targeting zone at specific coordinates:

local zoneId = exports.cu_enchanced_target:addSphereZone({
  coords = vec3(123.45, 567.89, 21.0),
  radius = 1.5,
  name = 'stash_zone',  -- optional name for easy removal
  debug = false,         -- show debug sphere
  drawSprite = true,     -- show marker sprite
  options = {
    {
      name = 'open_stash',
      label = 'Open Stash',
      icon = 'fa-solid fa-box',
      onSelect = function(data)
        print('Opening stash at', data.coords)
        -- Your stash logic here
      end,
      distance = 2.0
    }
  }
})

Box Zone

Create a box-shaped targeting zone:

local zoneId = exports.cu_enchanced_target:addBoxZone({
  coords = vec3(100.0, 200.0, 30.0),
  size = vec3(2.0, 2.0, 2.0),
  rotation = 45.0,  -- rotation in degrees
  name = 'shop_counter',
  options = {
    {
      label = 'Purchase Items',
      icon = 'fa-solid fa-shopping-cart',
      event = 'shop:openMenu'
    }
  }
})

Polygon Zone

Create a polygon targeting zone with multiple points:

local zoneId = exports.cu_enchanced_target:addPolyZone({
  points = {
    vec3(100.0, 200.0, 30.0),
    vec3(110.0, 200.0, 30.0),
    vec3(110.0, 210.0, 30.0),
    vec3(100.0, 210.0, 30.0)
  },
  thickness = 2.0,  -- height of the zone
  name = 'parking_lot',
  options = {
    {
      label = 'Park Vehicle',
      icon = 'fa-solid fa-square-parking',
      canInteract = function(entity, distance, coords)
        return IsPedInAnyVehicle(PlayerPedId(), false)
      end,
      onSelect = function(data)
        -- Park vehicle logic
      end
    }
  }
})

Model Examples

Target Specific Models

Add targeting to specific prop models:

exports.cu_enchanced_target:addModel('prop_atm_01', {
  {
    name = 'atm_withdraw',
    label = 'Withdraw Money',
    icon = 'fa-solid fa-money-bill',
    event = 'bank:atmMenu',
    distance = 2.0
  }
})

Multiple Models

Target multiple models with the same options:

exports.cu_enchanced_target:addModel({
  'prop_vend_snak_01',
  'prop_vend_snak_01_tu',
  'prop_vend_water_01'
}, {
  {
    label = 'Buy Snacks',
    icon = 'fa-solid fa-cookie-bite',
    event = 'vending:buySnacks'
  }
})

Entity Examples

Network Entity

Target a specific networked entity (synced across clients):

local entity = GetVehiclePedIsIn(PlayerPedId(), false)
local netId = NetworkGetNetworkIdFromEntity(entity)
 
exports.cu_enchanced_target:addEntity(netId, {
  {
    name = 'check_trunk',
    label = 'Check Trunk',
    icon = 'fa-solid fa-box-open',
    bones = {'boot'},  -- target the boot/trunk bone
    onSelect = function(data)
      print('Checking trunk of vehicle', data.entity)
    end
  }
})

Local Entity

Target a local entity (client-side only):

local ped = CreatePed(4, GetHashKey('a_m_m_business_01'), x, y, z, heading, false, false)
 
exports.cu_enchanced_target:addLocalEntity(ped, {
  {
    name = 'talk_to_npc',
    label = 'Talk',
    icon = 'fa-solid fa-comment',
    distance = 2.5,
    onSelect = function()
      -- Conversation logic
    end
  }
})

Global Options

Global Ped Options

Add options to all peds (NPCs, not players):

exports.cu_enchanced_target:addGlobalPed({
  {
    name = 'greet_ped',
    label = 'Greet',
    icon = 'fa-solid fa-hand-wave',
    distance = 3.0,
    onSelect = function(data)
      print('Greeting ped', data.entity)
    end
  }
})

Global Vehicle Options

Add options to all vehicles:

exports.cu_enchanced_target:addGlobalVehicle({
  {
    name = 'check_plate',
    label = 'Check Plate',
    icon = 'fa-solid fa-id-card',
    canInteract = function(entity, distance, coords)
      return not IsPedInAnyVehicle(PlayerPedId(), false)
    end,
    onSelect = function(data)
      local plate = GetVehicleNumberPlateText(data.entity)
      print('Plate:', plate)
    end
  }
})

Global Player Options

Add options to all players:

exports.cu_enchanced_target:addGlobalPlayer({
  {
    name = 'give_cash',
    label = 'Give Cash',
    icon = 'fa-solid fa-dollar-sign',
    onSelect = function(data)
      -- Give cash logic
    end
  }
})

Advanced Examples

Using Server Events

exports.cu_enchanced_target:addSphereZone({
  coords = vec3(100.0, 200.0, 30.0),
  radius = 1.5,
  options = {
    {
      label = 'Process Materials',
      icon = 'fa-solid fa-industry',
      serverEvent = 'processing:start',  -- triggers server event
      canInteract = function()
        return exports.inventory:hasItem('raw_materials')
      end
    }
  }
})

Framework Integration (Job Restriction)

exports.cu_enchanced_target:addSphereZone({
  coords = vec3(100.0, 200.0, 30.0),
  radius = 1.5,
  options = {
    {
      label = 'Access Police Computer',
      icon = 'fa-solid fa-laptop',
      groups = {police = 0, sheriff = 0},  -- require police or sheriff job
      event = 'police:openComputer'
    }
  }
})

Item Requirement

exports.cu_enchanced_target:addModel('prop_tool_bench02', {
  {
    label = 'Craft Weapon',
    icon = 'fa-solid fa-hammer',
    items = {'metal_scrap'},  -- requires metal_scrap item
    onSelect = function()
      -- Crafting logic
    end
  }
})

Using Bone Targeting

exports.cu_enchanced_target:addGlobalVehicle({
  {
    name = 'open_hood',
    label = 'Open Hood',
    icon = 'fa-solid fa-car',
    bones = {'bonnet'},  -- only shows when targeting hood/bonnet
    onSelect = function(data)
      SetVehicleDoorOpen(data.entity, 4, false, false)
    end
  },
  {
    name = 'open_trunk',
    label = 'Open Trunk',
    icon = 'fa-solid fa-box',
    bones = {'boot'},  -- only shows when targeting trunk/boot
    onSelect = function(data)
      SetVehicleDoorOpen(data.entity, 5, false, false)
    end
  }
})

Removing Options

Remove Zone

-- By ID
exports.cu_enchanced_target:removeZone(zoneId)
 
-- By name
exports.cu_enchanced_target:removeZone('stash_zone')

Remove Model Options

exports.cu_enchanced_target:removeModel('prop_atm_01', 'atm_withdraw')

Remove Entity Options

exports.cu_enchanced_target:removeEntity(netId, 'check_trunk')

Remove Global Options

exports.cu_enchanced_target:removeGlobalPed('greet_ped')
exports.cu_enchanced_target:removeGlobalVehicle('check_plate')
exports.cu_enchanced_target:removeGlobalPlayer('give_cash')