AI Core

ai-target for developers

The ox_target client API that ai-target answers, the option shape, what an option's handler receives, and the HandleInteract export.

For your own places, NPCs and model options use AI Core's interaction points: lib Points in TypeScript or aiLib.Points in Lua (see the lib reference). A point shows as a prompt or as a target marker, whichever the owner picked, on whichever target script runs, and the same onPressed runs either way. Call the API below only when you port a script written for ox_target.

Exports

Every export is client side, answers under both exports['ai-target'] and exports.ox_target (ai-target provides ox_target), and does not wait. Options belong to the resource that added them and are removed when it stops.

TargetOption

The option shape every add* export takes, one option or a list. An option without a label is left out.

Prop

Type

TargetResponse

What onSelect, export, event and serverEvent receive.

Prop

Type

addBoxZone

Adds a box-shaped zone with options. addSphereZone and addPolyZone work the same with other shapes.

Side: Client · Waits: no

Signature
addBoxZone(data: { coords: Vec3; size?: Vec3; rotation?: number; name?: string; options: TargetOption | TargetOption[] }): number
addSphereZone(data: { coords: Vec3; radius?: number; name?: string; options: TargetOption | TargetOption[] }): number
addPolyZone(data: { points: Vec3[]; thickness?: number; name?: string; options: TargetOption | TargetOption[] }): number
Lua
local id = exports.ox_target:addBoxZone({ coords = vec3(x, y, z), size = vec3(2, 2, 2), rotation = 0, options = { ... } })

Parameters

Prop

Type

Returns

number: the zone id. 0 when the coordinates are missing or invalid (a warning is logged).

Example

import { callExport } from "@aicore-fivem/lib/client";

const zone = callExport("ox_target", "addBoxZone", {
  coords: { x: 441.8, y: -982.0, z: 30.7 },
  size: { x: 1.5, y: 1.5, z: 2 },
  rotation: 0,
  options: [
    {
      name: "duty",
      label: "Go on duty",
      icon: "clipboard-check",
      groups: "police",
      onSelect: () => emitNet("myscript:toggleDuty"),
    },
  ],
}) as number;

on("onResourceStop", (name: string) => {
  if (name === GetCurrentResourceName()) callExport("ox_target", "removeZone", zone);
});

Zones of a resource are removed when that resource stops, so the stop handler above is optional. Remove a zone yourself when the place goes away while your resource keeps running.

removeZone

Removes a zone. Side: Client · Waits: no.

Signature
removeZone(id: number | string): void

id is the number add*Zone returned, or the zone's name.

zoneExists

Side: Client · Waits: no.

Signature
zoneExists(id: number | string): boolean

Returns true while the zone with that number or name exists.

addModel

Puts options on every entity of these models (doors of a model, ATMs, dumpsters).

Side: Client · Waits: no

Signature
addModel(models: string | number | Array<string | number>, options: TargetOption | TargetOption[]): void
removeModel(models: string | number | Array<string | number>, names?: string | string[]): void
Lua
exports.ox_target:addModel({ 'prop_atm_01', 'prop_atm_02' }, { { name = 'atm', label = 'Use ATM', icon = 'credit-card', onSelect = openAtm } })

Parameters

Prop

Type

Returns

Nothing.

addEntity and addLocalEntity

addEntity puts options on networked entities by network id (vehicles or peds the server created). addLocalEntity puts them on entities by handle (a ped or prop your client created). Each has a remove* twin taking the same ids and optional option names.

Side: Client · Waits: no

Signature
addEntity(netIds: number | number[], options: TargetOption | TargetOption[]): void
removeEntity(netIds: number | number[], names?: string | string[]): void
addLocalEntity(entities: number | number[], options: TargetOption | TargetOption[]): void
removeLocalEntity(entities: number | number[], names?: string | string[]): void

Global options by kind

Options on every ped, vehicle, object or player.

Side: Client · Waits: no

Signature
addGlobalPed(options: TargetOption | TargetOption[]): void
addGlobalVehicle(options: TargetOption | TargetOption[]): void
addGlobalObject(options: TargetOption | TargetOption[]): void
addGlobalPlayer(options: TargetOption | TargetOption[]): void
removeGlobalPed(names?: string | string[]): void   // and removeGlobalVehicle, removeGlobalObject, removeGlobalPlayer
Lua
exports.ox_target:addGlobalVehicle({
    { name = 'myscript_wash', label = 'Wash vehicle', icon = 'soap', distance = 2.0,
      canInteract = function(entity) return GetVehicleDirtLevel(entity) > 5.0 end,
      onSelect = function(data) TriggerServerEvent('myscript:wash', VehToNet(data.entity)) end },
})

addGlobalOption (an option on nothing) is not offered. It logs a warning and does nothing. Put such actions on the radial menu instead (lib radial).

disableTargeting

Turns the markers off (true) or back on (false) for this player. Side: Client · Waits: no.

Signature
disableTargeting(state: boolean): void

isActive

Side: Client · Waits: no.

Signature
isActive(): boolean

Returns true while at least one marker is near the player.

HandleInteract

ai-target's own export (not ox_target's). AI Core's interaction key asks it first: it runs the option in focus.

Side: Client · Waits: no

Signature
HandleInteract(): boolean

Returns true when an option in focus was used (or its menu opened), false when nothing is in focus, so the key goes on to the prompts. Typed in AiTargetClientExports. You do not need to call it.

Events

None for other scripts.

On this page