Exports allow resources to share functions with other resources.
-- server.lua
exports('getPlayerData', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
return xPlayer
end)-- client.lua
exports('showNotification', function(message)
-- Show notification
end)local playerData = exports['myresource']:getPlayerData(source)exports['myresource']:showNotification('Hello!')Use resource name as namespace:
-- Good
exports['qb-core']:GetPlayer(source)
-- Bad
exports:GetPlayer(source)Before calling an export, check if the resource is started to avoid errors.
if GetResourceState('ox_inventory') == 'started' then
local items = exports.ox_inventory:Items()
else
print('ox_inventory is not started')
endUse pcall when the export might fail internally or return unexpected data.
local success, result = pcall(function()
return exports['myresource']:riskyOperation()
end)
if success then
print('Result:', result)
else
print('Export call failed:', result)
endWhen updating exports, maintain backward compatibility.
Check arguments inside the export to support multiple formats.
exports('giveItem', function(target, item, count)
if type(target) == 'table' then
-- Handle new object-style arguments
count = target.count
item = target.item
target = target.source
end
-- ... implementation
end)Create new exports for breaking changes.
exports('giveItem', function(...) end) -- v1 (Deprecated)
exports('giveItem_v2', function(opts) end) -- v2Create a test suite script to verify your exports behave as expected.
-- tests.lua
CreateThread(function()
Wait(1000) -- Wait for resources to load
print('Testing exports...')
local result = exports['myresource']:calculate(5, 5)
assert(result == 10, 'Math export failed')
print('Tests passed!')
end)Document your exports clearly in your README or code comments so other developers know how to use them.
--- @export getBalance
--- Retreives the current bank balance for a player
--- @param source number The player server ID
--- @param accountType string "bank" or "cash"
--- @return number The balance, or 0 if not found
exports('getBalance', function(source, accountType)
-- ...
end)getUser vs get.false or nil) to confirm execution.