OPX//77
opx_infinityneeds

Client

Last updated on

The needs contract on the client — read the needs the server sent, add and remove status chips.

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

From client code inside opx_infinity. Every function answers a Result ({ ok = true, value } or { ok = false, error, detail }). None yields. Codes: Refusal codes.

  • The needs are read only here: the client draws what the server sends. To move one, use the server contract (or, from another resource, the server exports AddNeeds / SetNeeds). SetNeeds and AddNeeds are no longer on the client contract.
  • owner is the caller's own name (1–64 characters of letters, digits, _ : - .). It groups chips and lets the module drop them when the owner stops. If owner names a running Open77 resource, its chips are dropped when that resource stops or reloads. A module name inside opx_infinity is never swept this way.

GetNeeds

The values as the server last sent them.

needs.GetNeeds()

Returns

  • Result — value { values, citizenId, ready = true }; values is a copy
    • errors no_character, not_loaded (detail = the citizen id)

AddEffect

Adds a chip, or replaces the owner's chip with the same id (start time and countdown restart).

needs.AddEffect(owner, spec)

Parameters

Returns

  • Result — value { id }
Example
local r = needs.AddEffect('mymodule', {
  id = 'bleeding', label = 'Bleeding', tone = 'bleed',
  priority = 80, durationMs = 30000, event = 'mymodule:bleedEnded',
})
if not r.ok then print(r.error) end

UpdateEffect

Patches one of the owner's chips. Absent fields keep their value. Without durationMs the countdown keeps running; with it, it restarts.

needs.UpdateEffect(owner, id, patch)

Parameters

  • owner: string
  • id: string
  • patch: table — any effect spec fields

Returns

  • Result — value true
Example
needs.UpdateEffect('mymodule', 'bleeding', { tone = 'warn', progress = 0.5 })

RemoveEffect

Removes the chip and raises its removed event.

needs.RemoveEffect(owner, id)

Parameters

  • owner: string
  • id: string

Returns

  • Result — value true

ClearEffects

Removes every chip of the owner. Raises no event.

needs.ClearEffects(owner)

Parameters

  • owner: string

Returns

  • Result — value { removed }

Effect spec

The chip format.

FieldTypeRule
idstringRequired. 1–64 characters of letters, digits, _ : - .. Unique per owner.
labelstringRequired. Cleaned and cut to 32 characters; empty after cleaning is refused.
iconstringOptional. Cut to 2 characters.
tonestringOptional. One of ok, warn, bad, accent, bleed, burn, shock, chem.
prioritynumberOptional, default 0. Higher draws first.
durationMsnumberOptional. 1..3600000. The chip expires on its own after this.
progressnumberOptional. Clamped to 0..1.
eventstringOptional. A local event name (max 96 characters) raised when the chip is removed or expires.
datatableOptional. Opaque data handed back in the event. At most 64 nodes and 4 levels deep.
  • One owner may hold 24 chips.
  • The strip is ordered by priority (highest first), then newest first.
  • Only MAX_VISIBLE chips are published; the rest are counted in hidden.

On this page