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.
playeris a connected server id with a loaded character.patchis{ [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 toopx:on:needs:changed. Anything else falls back toset/add.- Other resources use the
GetNeeds,AddNeedsandSetNeedsexports, which call these with reasonext:<resource>.
GetNeeds
needs.GetNeeds(player)Parameters
- player:
integer
Returns
Result— value{ values, citizenId };valuesis a copy- errors
bad_player,not_loaded
- errors
SetNeeds
Sets each named need outright, clamped to MIN..MAX.
needs.SetNeeds(player, patch, reason)Parameters
- player:
integer - patch:
table - reason?:
string— defaultset
Returns
Result— value{ values, changed };changedis 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
- errors
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— defaultadd
Returns
Result— value{ values, changed }
needs.AddNeeds(source, { hunger = 25, thirst = -5 }, 'use')