ox_lib quick reference
The ox_lib calls people look up most, with the exact arguments and a minimal example you can paste. Below the reference: an AI that writes ox_lib code from the real API instead of guessing function names.
Setup and the most used calls
Client and server notes are marked in each snippet. Official docs: overextended.dev.
shared_script '@ox_lib/init.lua'
Load ox_lib in your resource. This gives you the lib, cache and require globals.
-- fxmanifest.lua
fx_version 'cerulean'
game 'gta5'
lua54 'yes'
shared_script '@ox_lib/init.lua'
server_script '@oxmysql/lib/MySQL.lua' -- only if you use the MySQL globalox_lib needs lua54 'yes'. Start ox_lib before your resource in server.cfg.
lib.notify(data)
Show a notification on the client. type is info, success, warning or error.
-- client
lib.notify({
title = 'Vehicle stored',
description = 'Your car is in the garage.',
type = 'success',
duration = 5000,
position = 'top-right',
})
-- server: send it to one player
TriggerClientEvent('ox_lib:notify', source, {
description = 'Welcome back',
type = 'info',
})lib.notify(playerId, data) on the server is deprecated in ox_lib. 'inform' is an old v3 name; the current types are info, success, warning and error.
lib.registerContext(context) + lib.showContext(id)
Build a context menu, then open it. Registering it does not open it.
lib.registerContext({
id = 'garage_menu',
title = 'Garage',
options = {
{
title = 'Spawn vehicle',
icon = 'car',
onSelect = function()
TriggerServerEvent('garage:spawn')
end,
},
},
})
lib.showContext('garage_menu')Give a submenu menu = 'parent_id' to get a back button to the parent.
lib.callback.register / lib.callback.await
Ask the other side for a value and wait for the answer. Works in both directions.
-- server
lib.callback.register('bank:getBalance', function(source, account)
return GetBalance(source, account)
end)
-- client: the 2nd argument is a delay in ms or false, not a player id
local balance = lib.callback.await('bank:getBalance', false, 'checking')
-- server asking a client: here the 2nd argument is the player id
local coords = lib.callback.await('myres:getCoords', source)lib.skillCheck(difficulty, inputs)
Blocking skill check. Returns true on success, false on fail. Difficulty is 'easy', 'medium', 'hard' or { areaSize, speedMultiplier }.
local success = lib.skillCheck({ 'easy', 'easy', 'hard' }, { 'w', 'a', 's', 'd' })
if success then
-- player passed every check
endlib.progressBar(data) / lib.progressCircle(data)
Blocking progress with optional animation and prop. Returns true when finished, false when cancelled.
if lib.progressBar({
duration = 5000,
label = 'Repairing',
canCancel = true,
disable = { car = true, move = true, combat = true },
anim = { dict = 'mini@repair', clip = 'fixing_a_ped' },
}) then
-- finished
else
-- cancelled
endlib.inputDialog(heading, rows, options)
Form dialog. Returns an array of values in row order, or nil if the player closed it.
local input = lib.inputDialog('Transfer money', {
{ type = 'number', label = 'Amount', min = 1, required = true },
{ type = 'input', label = 'Note' },
})
if not input then return end
local amount, note = input[1], input[2]lib.alertDialog(data, timeout)
Confirm dialog. Returns 'confirm', 'cancel' or nil.
local answer = lib.alertDialog({
header = 'Sell vehicle?',
content = 'You get $12,000. This cannot be undone.',
centered = true,
cancel = true,
})
if answer == 'confirm' then
TriggerServerEvent('dealer:sell')
endMySQL.query.await / single / scalar / insert (oxmysql)
Awaitable oxmysql queries: many rows, one row, one value, or an insert id.
-- server, with server_script '@oxmysql/lib/MySQL.lua' in the fxmanifest
local rows = MySQL.query.await('SELECT * FROM vehicles WHERE owner = ?', { owner })
local row = MySQL.single.await('SELECT * FROM users WHERE identifier = ?', { identifier })
local name = MySQL.scalar.await('SELECT name FROM users WHERE id = ?', { id })
local insertId = MySQL.insert.await('INSERT INTO logs (msg) VALUES (?)', { msg })Without the MySQL global, the matching exports are exports.oxmysql:query_async and friends. There is no query_await export. fetchAll, fetchScalar and execute are legacy aliases.
ox_target and ox_inventory together
Two calls most ox_lib resources need next to the library itself.
exports.ox_target:addBoxZone
-- client
exports.ox_target:addBoxZone({
coords = vec3(-47.4, -1757.3, 29.4),
size = vec3(1.5, 1.5, 2.0),
rotation = 0,
debug = false,
options = {
{
name = 'shop:open',
label = 'Open shop',
icon = 'fa-solid fa-basket-shopping',
distance = 1.8,
onSelect = function()
lib.showContext('shop_menu')
end,
},
},
})ox_inventory stash
-- server: register once on resource start
exports.ox_inventory:RegisterStash('gang_stash_ballas', 'Ballas Stash', 50, 100000)
-- client: open it
exports.ox_inventory:openInventory('stash', 'gang_stash_ballas')Mistakes AI-written ox_lib code makes
Each one loads without an error and then does nothing, or fails the first time the code path runs.
Invented ox_lib functions
Calls like ox_lib.notify_player or lib.createMenu do not exist. The generator looks calls up in the indexed ox_lib source while it writes, so it uses functions the library has.
Server notify through lib.notify
lib.notify(playerId, data) still works on the server but is marked deprecated in ox_lib. Use TriggerClientEvent('ox_lib:notify', source, data) instead.
Mixing up callback arguments
On the client the second argument of lib.callback.await is a delay or false. Passing a player id there, as you would on the server, silently rate-limits the call.
Opening an inventory from the wrong side
ox_inventory:openInventory is a client event. A client calling TriggerServerEvent with it does nothing; use exports.ox_inventory:openInventory on the client.
Generate ox_lib code with SwisserAI
Describe the resource in a sentence. The generator writes it against the ox_lib, ox_target and ox_inventory APIs above and checks every call it uses.
lib.notify
Client notifications with title, description, type, duration, icon and position. From the server through the ox_lib:notify event.
lib.callback
register and await on both sides. The client passes a delay as the second argument, the server passes the player id.
lib.registerContext
Context menus with submenus, onSelect handlers, icons and a back link through the parent menu id.
lib.addRadialItem
Radial menu items with removeRadialItem and clearRadialItems so nothing stays behind when the resource stops.
ox_inventory integration
RegisterStash, openInventory on the client, item definitions and inventory hooks through exports.ox_inventory:registerHook.
ox_target zones and models
addBoxZone, addSphereZone, addModel, addEntity and the global ped and vehicle targets, with distance, canInteract and onSelect.
Frequently Asked Questions
ox_lib is a free FiveM and RedM library from Overextended. It adds a lib global with notifications, context and radial menus, progress bars, skill checks, input dialogs, callbacks, zones, points and caching helpers. Load it with shared_script '@ox_lib/init.lua' and lua54 'yes' in your fxmanifest.
At overextended.dev. The old coxdocs.dev addresses now redirect there. The source is on GitHub under overextended/ox_lib, and its annotations are what this page was checked against.
Yes. ox_lib is framework-agnostic. You can generate ox_lib-only code without selecting a framework, and the generator sticks to the ox_lib API without assuming a player object.
The generator works from the indexed Overextended ox_lib source and looks up calls while it writes, so it uses functions the library really has instead of guessing from the name. How the grounding works.
The current Overextended release. If your server pins an older version, say so in the prompt and the generator keeps to that version.
Yes: item definitions for data/items.lua, usable items, stashes through RegisterStash and inventory hooks through exports.ox_inventory:registerHook.
Paste the relevant part of the ox_lib source or docs into your prompt and the generator uses it as the source of truth. For gaps that affect many people, write to support@swisser.dev.
AI for other FiveM frameworks
SwisserAI generates idiomatic code for every major FiveM framework. Explore the others:
Write ox_lib code without guessing
250 free credits when you sign up. No card needed.