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
| Label | Meaning |
|---|---|
Scope read | Allowed by SERVER.EXPORTS.READ ('*' by default). |
Scope write | Allowed by SERVER.EXPORTS.WRITERS (nobody by default). Audited with your resource name. |
| sync | Answers at once; exports.opx_infinity:Name(...) is fine. |
| must be awaited | Can wait on the database. Call it with Open77.exports.call(...) and :await(); a synchronous call answers export.mustAwait. |
| await it | A write that answers from memory today. Use the promise form anyway. |
Common arguments
| Name | Accepts |
|---|---|
source | a connected player id (number) |
citizenId | a citizen id string |
target | a connected player id or a citizen id (a citizen id reaches an offline bag and must be awaited) |
metadata | nil or a plain table |
Players
GetVersion— resource and export surface versionGetPlayerData— public view of a connected playerGetPlayerByCitizenId— public view of an online characterIsStaff— holds the staff rightGetPlayers— every loaded character, by job, gang or dutyGetJobs,GetGangs— the configured groups and their grades
Money
Types from MONEY.TYPES; amounts 1 to 9 999 999 999; reasons stored as ext:<your resource>:<reason>.
GetMoney— read · syncAddMoney— write · await itRemoveMoney— write · await itAddMoneyOffline— write · must be awaited
Jobs and gangs
HasJob,HasGang,GetJob,GetGang— read · syncSetJob,SetGang,RemoveJob,RemoveGang— write · must be awaitedSetDuty— write · sync
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
HasItem,CountItem— read · await whentargetis a citizen idAddItem,RemoveItem— write · await it (must whentargetis a citizen id)GetItem,GetItems— the catalogue · read · syncGetInventory,CanCarryItem— read · await whentargetis a citizen idRegisterItem— a new item, at runtime · writeRegisterUsableItem,UnregisterUsableItem— your export decides a use · write
Stashes
Loaded, never opened in front of a player. A new stash must be configured or named <your resource>.<name>.
CountInStash— read · must be awaitedAddToStash,RemoveFromStash— write · must be awaitedOpenStash— open one in front of a player · write · must be awaited
Chat
SendChat,BroadcastChat— write · await it
Vehicles and keys
RevokeKeys,RevokeAllKeys,SetVehicleState— write · must be awaitedGetVehicle,GetOwnedVehicles— read · must be awaitedAddVehicle,GiveKeys— write · must be awaitedHasKeys— read · sync (await for a citizen id)
Toasts and bars
Notify— a toast on one player's screen · write · syncStartProgress,StopProgress— a bar the server starts and judges · write · sync
Crafting
RegisterCraftingBench,UnregisterCraftingBench— a bench your resource owns · write · sync
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.
GetDoor,GetDoorFromName,GetAllDoors— read · syncSetDoorState,SetDoorLocked,CreateDoor,EditDoor,RemoveDoor— write · must be awaited
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.
GetFuel,GetFuelState— read · syncSetFuel— write · sync
Examples
Pay a player for a job step
-- 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
endRestock 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)