OPX//77
CreatorsServer exports

Server exports

Last updated on

What a server script of another resource can call on opx_infinity — players, money, jobs, metadata, needs, items, stashes, chat, vehicles, doors, fuel, toasts, bars and crafting benches.

Defined in core/server/exports.lua. Read For creators first: every export answers { ok, value | error }, the operator decides who may call it, and writes must be awaited.

Scope and await

LabelMeaning
Scope readAllowed by SERVER.EXPORTS.READ ('*' by default).
Scope writeAllowed by SERVER.EXPORTS.WRITERS (nobody by default). Audited with your resource name.
syncAnswers at once; exports.opx_infinity:Name(...) is fine.
must be awaitedCan wait on the database. Call it with Open77.exports.call(...) and :await(); a synchronous call answers export.mustAwait.
await itA write that answers from memory today. Use the promise form anyway.

Common arguments

NameAccepts
sourcea connected player id (number)
citizenIda citizen id string
targeta connected player id or a citizen id (a citizen id reaches an offline bag and must be awaited)
metadatanil or a plain table

Players

Money

Types from MONEY.TYPES; amounts 1 to 9 999 999 999; reasons stored as ext:<your resource>:<reason>.

Jobs and gangs

Metadata

Your resource's own space on a character (ext.<your resource>.<key>). A player id reaches a loaded character, a citizen id one nobody is playing. The player can read it.

  • GetMetadata — read · sync (must be awaited for a citizen id)
  • SetMetadata — write · sync (must be awaited for a citizen id)

Down and revive

Needs

The server owns hunger, thirst, stamina and street cred; a client cannot move them. Your resource moves them here.

Items

Stashes

Loaded, never opened in front of a player. A new stash must be configured or named <your resource>.<name>.

Chat

Vehicles and keys

Toasts and bars

Crafting

When your resource stops

Your use handlers, crafting benches and server-started bars go with it. The cleanup runs only if your resource is still not running or starting when the stop reaches opx_infinity (a stop arrives on a later tick): on a restart your new instance has usually registered again already, and its registrations replace the old ones rather than being wiped. Register on every start. Your runtime items stay in the catalogue (stacks of them are in bags), and everything you wrote stays written.

Doors

ox_doorlock's server exports under their ox meaning (see doorlock). A door is its integer id, or the key a seeded or carried-over door had. No answer ever carries a door's code.

Fuel

ox_fuel's tank in ox's unit, a percentage (see fuel). The vehicle's bag field fuel holds litres; read these instead of Entity(vehicle).state.fuel.

Examples

Pay a player for a job step

my_jobs/server/main.lua
-- needs `my_jobs = true` in SERVER.EXPORTS.WRITERS
RegisterNetEvent('my_jobs:delivered', function()
	local playerId = source
	CreateThread(function()
		-- re-check on the server that the delivery really happened, then:
		local pending, why = Open77.exports.call('opx_infinity', 'AddMoney',
			playerId, 'EDDIES', 350, 'delivery')
		if not pending then return print('not sent: ' .. tostring(why)) end
		local answer, failure = pending:await()
		if answer == nil then return print('call failed: ' .. tostring(failure)) end
		if answer.ok ~= true then return print('refused: ' .. tostring(answer.error)) end
		print(('paid, balance is now %d'):format(answer.value))
	end)
end)

Check a job before letting someone in

-- a read: the synchronous form is fine
local answer = exports.opx_infinity:HasJob(playerId, 'police', true, 2)
if answer.ok and answer.value then
	-- on-duty police, grade 2 or more
end

Restock a shop's back room

-- creates `my_shop.backroom` on first use (needs my_shop in WRITERS)
CreateThread(function()
	local pending = Open77.exports.call('opx_infinity', 'AddToStash',
		'my_shop.backroom', 'water', 24)
	local answer = pending and pending:await()
	if not (answer and answer.ok) then
		print('restock refused: ' .. tostring(answer and answer.error))
	end
end)

On this page