ox_lib
ox_lib is a powerful library providing common functionality for FiveM resources. Declare it as a dependency, load the correct initialization file, and keep the installed version compatible across dependent resources. Server callbacks must still validate permissions and client-provided values before returning sensitive data or applying changes.
Installation
Add to fxmanifest.lua:
dependency 'ox_lib'
shared_script '@ox_lib/init.lua' -- defines the `lib` global; without it `lib` is nilCallbacks
Server Callback
The server handler receives source followed by the client’s arguments and
returns the response. There is no cb parameter: ox_lib calls the handler
with pcall(cb, source, ...) and sends back its return values
(imports/callback/server.lua).
-- Server
lib.callback.register('myresource:getData', function(source, itemId)
if type(itemId) ~= 'number' then return nil end -- never trust client input
return getData(source, itemId)
end)
-- Client: callback form
lib.callback('myresource:getData', false, function(data)
print('Received:', data)
end, 42)
-- Client: inside a thread or handler, wait for the result instead
local data = lib.callback.await('myresource:getData', false, 42)Context Menus
lib.registerContext({
id = 'mycontext',
title = 'My Menu',
options = {
{
title = 'Option 1',
onSelect = function()
print('Option 1 selected')
end
}
}
})
lib.showContext('mycontext')Locales
ox_lib loads JSON files from locales/ in your resource. en.json is the
fallback; other languages are merged over it. Enable the module in the manifest
and ship the files to clients:
-- fxmanifest.lua
shared_script '@ox_lib/init.lua'
ox_lib 'locale'
files { 'locales/*.json' }{
"welcome": "Welcome to the server, %s!",
"goodbye": "Thanks for playing!"
}Translate with the global locale() function. Extra arguments are passed to
string.format; a missing key returns the key itself.
lib.notify({
title = 'Server',
description = locale('welcome', GetPlayerName(PlayerId())),
type = 'success'
})lib.locale(key) loads a language; it does not translate a string. The
server language comes from the ox:locale convar (default en), while each
client uses its own ox_lib locale setting. Source:
imports/locale/shared.lua.
Notifications
lib.notify({
title = 'Success',
description = 'Action completed!',
type = 'success'
})Frameworks built on ox_lib
ox_lib is a hard dependency of three FiveM frameworks, and a common optional one for the other two:
- ox_core — the Overextended framework itself
- Qbox —
qbx_corerequires it - ND Core — required alongside
oxmysql
Many QBCore and ESX community resources also depend on it. Learning ox_lib is the most transferable skill across the FiveM framework landscape — see Choosing a framework.