Using ox_lib with ESX Legacy
Use ox_lib with ESX Legacy for notifications, progress bars and context menus, with working fxmanifest imports and fixes for global lib is nil and startup issues.
ox_lib can be used alongside ESX Legacy, providing notifications, progress indicators, context menus, callbacks and other reusable client-side utilities. It does not replace the official ESX esx_lib resource.
Install ox_lib alongside ESX
Download a maintained release from Community Ox or the appropriate maintained repository for your installation. The library must be built and include its web assets.
ensure oxmysql
ensure ox_lib
ensure esx_lib
ensure es_extended
ensure my_resourceAdd the initialization script before your own resource files:
fx_version 'cerulean'
game 'gta5'
shared_scripts {
'@ox_lib/init.lua',
'@es_extended/imports.lua',
}
client_script 'client.lua'
server_script 'server.lua'
dependencies { 'ox_lib', 'es_extended' }Use lib for ox_lib APIs and ESX for ESX APIs. They are separate global objects supplied by their respective imports.
Notifications from client and server
On the client:
lib.notify({
title = 'Delivery completed',
description = 'Your package was delivered.',
type = 'success',
duration = 3500,
})On the server, target a specific player:
RegisterCommand('testnotify', function(source)
if source == 0 then return end
TriggerClientEvent('ox_lib:notify', source, {
title = 'Test notification',
description = 'ox_lib is available on your client.',
type = 'inform',
})
end, false)Don't accidentally send a client-only notification to all players. The normal ESX equivalents, ESX.ShowNotification on the client and xPlayer.showNotification on the server, are also valid without ox_lib.
Progress bars and cancellation
The following client-side call returns true on successful completion and false when cancelled. Treat it as a user interface action, not proof that the player earned an item.
RegisterCommand('testprogress', function()
local completed = lib.progressBar({
duration = 3000,
label = 'Preparing package',
canCancel = true,
useWhileDead = false,
disable = {
move = true,
car = true,
combat = true,
},
})
if completed then
lib.notify({ description = 'Animation finished', type = 'success' })
else
lib.notify({ description = 'Cancelled', type = 'warning' })
end
end, false)lib.progressCircle accepts comparable options and presents a circular indicator. Any money, item or job change must be independently authorized by the server.
Context menus and callbacks
For context menus use lib.registerContext and lib.showContext. For asynchronous client/server interactions, consult the ox_lib callback module. These APIs have different signatures from the native ESX menu and callback APIs, so do not mix their function names.
Use the ox_lib documentation for the exact API signatures. If an existing ESX addon already uses esx_context or esx_progressbar, you do not have to replace it just to use ox_lib in a different script.
Troubleshooting
| Error | Fix |
|---|---|
attempt to index a nil value (global 'lib') | Import @ox_lib/init.lua before your scripts |
No such export from ox_lib | Check installation, build assets and startup |
| Notification works in client but not server | Use TriggerClientEvent('ox_lib:notify', source, data) |
lib.progressBar always cancels | Review player state and your cancellation/disable options |
| ESX functions are nil | Import @es_extended/imports.lua separately |
Related
Frequently asked questions
Independent documentation
Last updated on
Using ox_inventory
How to run ox_inventory with ESX Legacy, covering start order, convars, how es_extended switches to ox mode, which xPlayer methods change, and pitfalls.
Using ox_target with ESX Legacy
Integrate ox_target with ESX Legacy using job restrictions, addBoxZone and server-validated interactions, with a full FiveM fxmanifest and troubleshooting guide.