This guide explains how to properly integrate the notebook item resource with the ox_inventory system.
Before following this guide, ensure you have:
-
ox_inventory properly installed and configured
- Download: ox_inventory Official Repository
- Documentation: ox_inventory Docs
-
qbx_core (qbox framework) installed
- Download: qbx_core Official Repository
-
ox_lib for UI components
- Download: ox_lib Official Repository
Our notebook item resource is designed to work seamlessly with ox_inventory's metadata system. Here's how the integration works:
You need to add our notebook item to the ox_inventory items database.
Add the item definitions from our items.txt file to your ox_inventory items.lua:
['notebook'] = {
label = 'Personal Notebook',
weight = 200,
stack = false,
close = true,
description = 'A notebook where you can write and store personal notes. Use it to add or view your notes.',
consume = 0,
client = {
export = 'notebook_item.notebook'
}
}stack = false: Each notebook is unique and can't be stackedclose = true: Closes inventory when usedconsume = 0: Item isn't consumed when usedclient.export: Links to our resource's export function
When a player uses the notebook item, ox_inventory calls our export function:
-- In notebook_item/client/main.lua
exports('notebook', function(data, slot)
-- data contains item information including metadata
-- slot is the inventory slot number
end)Our resource uses ox_inventory's metadata system through these exports:
-- Get item from slot
local item = exports.ox_inventory:GetSlot(src, slot)
-- Update item metadata
local success = exports.ox_inventory:SetMetadata(src, slot, {
note = note,
updated = os.date('%Y-%m-%d %H:%M:%S')
})-
Empty Notebook:
data.infois nil or empty -
Notebook with Note:
data.info.notecontains the saved text -
Metadata Structure:
{ note = "Player's written note", updated = "2025-06-26 15:30:45" }
Ensure proper dependency loading in your server.cfg:
# Core dependencies first
ensure oxmysql
ensure ox_lib
ensure qbx_core
# Inventory system
ensure ox_inventory
# Our notebook resource (after dependencies)
ensure notebook_itemOur resource integrates with ox_inventory's event system:
- Item Usage: Triggered when player uses notebook from inventory
- UI Integration: Uses ox_lib for dialogs (compatible with ox_inventory UI)
- Metadata Updates: Validates and saves note data
- Security Checks: Ensures only valid players can update metadata
ox_inventory handles all database operations for us:
- Automatic Persistence: Metadata is saved to ox_inventory's database
- Player Inventories: Notes persist across server restarts
- Item Tracking: Each notebook instance maintains unique metadata
/give [player_id] notebook 1- First Use: Should prompt for note input
- Write Note: Enter text and submit
- Second Use: Should display the saved note
- Server Restart: Note should persist
- Verify the export name matches exactly:
notebook_item.notebook - Check that notebook_item resource started after ox_inventory
- Ensure no typos in the item definition
- Check server console for error messages
- Verify ox_inventory is properly configured
- Ensure player has valid session in qbx_core
- Confirm ox_lib is loaded and running
- Check browser console (F12) for JavaScript errors
- Verify NUI resources are properly loaded
Add a notebook.png image to /ox_inventory/web/images/ folder.
Add to shop configurations in ox_inventory:
-- In shop config
{
name = 'notebook',
price = 50,
count = 10
}The notebook metadata can be accessed by other resources:
-- Get player's notebook data
local item = exports.ox_inventory:GetSlot(source, slot)
if item and item.metadata and item.metadata.note then
local note = item.metadata.note
-- Use the note data
end- Item added to data/items.lua
- Export function properly named
- Metadata system used correctly
- Database persistence working
- ox_inventory listed in fxmanifest.lua
- Load order correct in server.cfg
- No circular dependencies
- Server-side validation implemented
- Player verification before metadata updates
- Input sanitization working
- Clear UI feedback
- Error handling for edge cases
- Proper notifications
Here's a complete test scenario:
-
Server Setup:
ensure ox_inventory ensure notebook_item
-
Add Item Definition:
-- In ox_inventory/data/items.lua ['notebook'] = { label = 'Personal Notebook', weight = 200, stack = false, close = true, description = 'A notebook where you can write and store personal notes.', consume = 0, client = { export = 'notebook_item.notebook' } }
-
Test Commands:
/give 1 notebook 1 # Player uses notebook, writes "Test note" # Player uses notebook again, sees "Test note" # Server restart # Player uses notebook, still sees "Test note"
The integration between our notebook item resource and ox_inventory is seamless because:
- Metadata System: ox_inventory's metadata system perfectly supports our note storage needs
- Export System: Clean integration point for item usage
- Database Persistence: Automatic handling of data storage
- Framework Compatibility: Works with qbx_core through ox_inventory's bridge system
This design follows ox_inventory's patterns and provides a robust, scalable solution for metadata-based items.