OPX//77
opx_infinitytarget

Client

Last updated on

The target contract on the client — register rows on world things and steer the eye.

local target = OPX.Api.Get('target')

From client code inside opx_infinity. Every function answers a Result. None yields.

owner is your module name. A module of this runtime keeps its rows until it stops. A separate Open77 resource's rows are dropped when it stops or reloads.

Register

Registers one row definition (a table with id) or a list of up to 32, whole or not at all. Re-registering an owner's id replaces that row.

target.Register(owner, definitions)

Parameters

  • owner: string
  • definitions: table | table[]

Returns

  • Result — { token } (one) or { tokens } (list)
Example
target.RegisterVehicles('mymodule', {
  id = 'refuel', label = 'Refuel', icon = 'bolt', order = 10, distance = 4.0,
  canInteract = function(ctx) return ctx.target.vehicleId ~= nil end,
  onSelect = function(ctx) print('refuel', ctx.target.vehicleId) end,
})

Register shortcuts

Same parameters and return as Register; each forces the filter fields below, overwriting the same fields in your definitions.

FunctionSignatureForces
RegisterPlayers(owner, definitions)types = { 'player' } (other players).
RegisterSelf(owner, definitions)types = { 'player' }, allowSelf = true, selfOnly = true (own body).
RegisterVehicles(owner, definitions)types = { 'vehicle' }.
RegisterNpcs(owner, definitions)types = { 'npc' }.
RegisterProps(owner, definitions)types = { 'prop' }.
RegisterDoors(owner, definitions)types = { 'door' }.
RegisterWorld(owner, definitions)types = { 'world' } (bare surfaces).
RegisterSky(owner, definitions)types = { 'sky' } (empty space; distance is not checked).
RegisterModels(owner, records, definitions)records (list of record names).
RegisterEntities(owner, entities, definitions)entities (see row definition).
RegisterSpheres(owner, spheres, definitions)spheres: the ray's hit point must fall inside one.
Example
target.RegisterSpheres('mymodule', { { x = 10.0, y = 20.0, z = 5.0, radius = 1.5 } },
  { id = 'atm', label = 'Use ATM', icon = 'money', onSelect = function(ctx) end })

Update

Re-registers the row with the patched fields under a new token. patch.id cannot change.

target.Update(owner, token, patch)

Parameters

  • owner: string
  • token: string
  • patch: table

Returns

  • Result — { token }

Get

A copy of the stored definition.

target.Get(owner, token)

Parameters

  • owner: string
  • token: string

Returns

  • Result — { token, definition }

Unregister

Removes one row.

target.Unregister(owner, token)

Parameters

  • owner: string
  • token: string

Returns

  • Result — true

UnregisterMany

Removes up to 32 rows, all or none.

target.UnregisterMany(owner, tokens)

Parameters

  • owner: string
  • tokens: string[]

Returns

  • Result — true

Clear

Removes every row of the owner.

target.Clear(owner)

Parameters

  • owner: string

Returns

  • Result — true

SetEnabled

Switches one row on or off.

target.SetEnabled(owner, token, value)

Parameters

  • owner: string
  • token: string
  • value: boolean

Returns

  • Result — true

List

The owner's rows, sorted by id.

target.List(owner)

Parameters

  • owner: string

Returns

  • Result — { options = { { token, id, label, enabled } } }

SetTargetingEnabled

false switches the whole eye off while the owner runs (closes it if open); true lifts your own switch.

target.SetTargetingEnabled(owner, value)

Parameters

  • owner: string
  • value: boolean

Returns

  • Result — true

Close

Closes the eye.

target.Close()

Returns

  • Result — true

State

target.State()

Returns

  • Result — { ready, open, enabled, handle, target, context, rows, owners }
    • ready: this client can screen-pick
    • rows, owners: registry size

Row definition

FieldTypeDefaultRule
idstring—Required. 1–64 characters of letters, digits, _ . : -. Unique per owner.
labelstring—Required. 1–80 bytes, one line.
onSelectfunction, string or { resource, export }—Required. Called with the context when the row is chosen. A function runs in-process. A string is an export of the owner's resource; { resource, export } names another resource's export (called through OPX.Lib.Rpc.Call).
canInteractsame as onSelectnoneOptional. Called at pick time; the row is listed only if it answers true.
checkedsame as onSelectnoneOptional. Answer true/false to draw a check box.
descriptionstringnone1–180 bytes.
groupstring''1–40 bytes. Rows of one group form a folder.
iconstring'interact'A name from OPX.Glyphs (e.g. person, vehicle, door, lock, money, heal, tag, warning).
enabledbooleantrueA disabled row is never listed.
networkedbooleananyIf set, the target's networked flag must equal it.
allowSelfbooleanfalseAllow the local player's own body.
selfOnlybooleanfalseOnly the local player's body. Needs allowSelf = true and, if types is set, player in it.
dangerbooleanfalseDrawn as a dangerous action. Asks for a second click unless confirm = false.
confirmbooleandangertrue: the first click relabels the row Confirm: <label> in place (inside its folder); only a second click on the same row within 4 s runs onSelect. false on a danger row runs it in one click.
distancenumber3.0Metres from the player to the hit point, 0.1–50. Not checked for sky.
orderinteger0−1000..1000. Lower first. A group sorts at its lowest order.
typesstring listanyUp to 32 of player, vehicle, npc, prop, door, device, item, object, world, sky. sky rows must list sky.
recordsstring listanyUp to 32 record names (1–200 bytes each). The target's record must be one of them.
entitiestable listanyUp to 32 entries, each naming exactly one of playerId, vehicleId, npcId (positive integers), engineEntity or propId (digit strings).
spherestable listanyUp to 32 { x, y, z, radius }, radius 0.1–10 m.
datatablenonePlain data (no functions, max 4 levels, about 2 KB). Handed back in context.option.data.

The context

canInteract, checked and onSelect receive one table:

  • the screen-ray hit: position, direction, origin, hit, …
  • screen: { x, y } (0–1)
  • kind, playerDistance
  • target: kind, networked, isLocalPlayer, record, and the id field that applies (playerId, vehicleId, npcId, engineEntity or propId). For empty sky, { kind = 'sky', networked = false }.
  • option: { id, owner, token, data }

Before onSelect, the target and canInteract are checked again; if the target moved, the eye closes instead.

On this page