OPX//77
opx_infinityneeds

Server

Last updated on

The needs contract on the server — the one way anything moves a character's hunger, thirst, stamina or street cred.

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

From server code inside opx_infinity. The server owns every value: it decays them, raises them, stores them and sends them to the player's client. Every function answers a Result and may yield (the first call for a player loads the row). Codes: Refusal codes.

  • player is a connected server id with a loaded character.
  • patch is { [needName] = number }. One unknown key or bad value refuses the whole patch; nothing is written.
  • reason (1–64 characters of letters, digits, _ . : -) travels with the change to the client and to opx:on:needs:changed. Anything else falls back to set / add.
  • Other resources use the GetNeeds, AddNeeds and SetNeeds exports, which call these with reason ext:<resource>.

GetNeeds

needs.GetNeeds(player)

Parameters

  • player: integer

Returns

  • Result — value { values, citizenId }; values is a copy
    • errors bad_player, not_loaded

SetNeeds

Sets each named need outright, clamped to MIN..MAX.

needs.SetNeeds(player, patch, reason)

Parameters

  • player: integer
  • patch: table
  • reason?: string — default set

Returns

  • Result — value { values, changed }; changed is the sorted list of keys whose value actually moved
    • errors bad_player, not_loaded, spec_must_be_a_table, unknown_need, invalid_need_value, empty_patch
Example
needs.SetNeeds(source, { hunger = 100, thirst = 100 }, 'hospital')

AddNeeds

Adds each delta (negative to take away), clamped.

needs.AddNeeds(player, patch, reason)

Parameters

  • player: integer
  • patch: table
  • reason?: string — default add

Returns

  • Result — value { values, changed }
Example
needs.AddNeeds(source, { hunger = 25, thirst = -5 }, 'use')

On this page