Callbacks
Implement Lua function callbacks for items that cannot be stored in the database.
Items with Lua function callbacks (add, remove, effect, buttons.action, server.cb) cannot be stored in the database. After running ItemsDB:migrate, open shared/callbacks.lua and implement the stub functions marked -- TODO.
-- shared/callbacks.lua (example)
return {
['phone'] = {
client = {
add = function(total) TriggerEvent('phone:open') end,
remove = function(total) TriggerEvent('phone:close') end,
},
},
}Preserving Custom Callbacks
The migrator overwrites shared/callbacks.lua with fresh stubs each time it runs. To avoid losing your implementations on re-migration, keep them in a separate file and require it at the bottom of callbacks.lua:
-- shared/callbacks.lua
local stubs = {
-- generated stubs...
}
local custom = require 'shared.my_callbacks'
for name, data in pairs(custom) do
stubs[name] = data
end
return stubsWhat Cannot Sync to Clients
Function callbacks are never sent over the network. If a client-side callback drives UI behavior (opening a phone, playing an animation), that logic must live in a client-side resource, not in ItemsDB's callback stubs. See Client Sync for details on what does and does not sync.