ox_inventory shops: data/shops.lua, RegisterShop and blips
How to create a shop in ox_inventory: the data/shops.lua entry, prices and currency, locations and targets, job-locked shops, RegisterShop from another resource, and blips.
A shop in ox_inventory is a list of items with prices, and one or more places where players can open it. You can edit a file, or register the shop from your own resource. This article covers both, plus prices, currencies, job restrictions, ox_target and blips.
The shop entry in data/shops.lua
Open ox_inventory/data/shops.lua. Each shop is a table keyed by a shop type:
return {
General = {
name = 'Shop',
inventory = {
{ name = 'burger', price = 10 },
{ name = 'water', price = 5, count = 50 },
{ name = 'lockpick', price = 150 },
},
locations = {
vec3(25.7, -1347.3, 29.5),
},
},
}The key (General) is the shop type. The fields:
| Field | Meaning |
|---|---|
name |
Title shown at the top of the shop |
inventory |
The items for sale |
locations |
Coordinates where players can open the shop |
targets |
Same idea, but with ox_target boxes (see below) |
groups |
Jobs allowed to use the shop |
blip |
Map blip settings |
Check the default entries in your copy of the file: they show the exact fields your version supports, and the best way to start is to copy one and change it.
Warning: every item name in
inventorymust exist indata/items.lua. A shop that lists a missing item can fail to open or print errors. See adding items to ox_inventory.
Items, prices and currency
Each line of inventory is a small table:
inventory = {
{ name = 'water', price = 5 },
{ name = 'sandwich', price = 12, count = 20 },
{ name = 'lockpick', price = 150, currency = 'black_money' },
{ name = 'WEAPON_PISTOL', price = 2500, license = 'weapon' },
},priceis what one unit costs.countis the stock. Without it the item is unlimited, and with it the stock goes down as players buy.currencyis the item that pays for it. It defaults to money, andblack_moneyis a common alternative.licenseasks for a license item before the player may buy.graderestricts one item to a minimum job grade, when the shop usesgroups.
Opening: locations and targets
With locations, ox_inventory shows an interaction at those coordinates. With targets, it creates ox_target boxes instead, which is better for a counter or a window:
targets = {
{
loc = vec3(25.7, -1347.3, 29.5),
length = 0.7,
width = 0.5,
heading = 0.0,
minZ = 29.0,
maxZ = 31.0,
distance = 1.5,
},
},ox_target must be running for this to work, since the shop depends on it. If you only want one of the two ways, remove the other table.
Job-locked shops and blips
Restrict a shop to a job with groups, using job names and minimum grades:
Police = {
name = 'Police armory',
groups = { police = 0 },
inventory = {
{ name = 'WEAPON_STUNGUN', price = 0 },
{ name = 'ammo-9', price = 0, count = 200 },
},
locations = { vec3(480.2, -996.5, 30.7) },
},For a map blip, add a blip table to the shop:
blip = { id = 59, colour = 69, scale = 0.8 },id is the sprite number and colour the colour number. The numbers come from the GTA blip lists, and the same idea is explained in creating blips in FiveM. Restart ox_inventory to apply file changes.
Register a shop from another resource
When a shop is created by your own script, for example by a business or a job resource, do not edit data/shops.lua. Register it on the server:
-- server.lua of your resource
exports.ox_inventory:RegisterShop('Bakery', {
name = 'Bakery',
inventory = {
{ name = 'bread', price = 4 },
{ name = 'croissant', price = 6, count = 30 },
},
locations = {
vec3(-1285.7, -1127.1, 6.8),
},
})RegisterShop(type, data) takes the type string and the same table as in the file. Register it when the resource starts. If ox_inventory restarts, your resource must register the shop again, so register on onServerResourceStart for ox_inventory too:
AddEventHandler('onServerResourceStart', function(resource)
if resource == 'ox_inventory' then
registerMyShops()
end
end)Open a shop from the client
If you do not want a location or a target on the shop, or you want to open it from your own interface, use the client export:
exports.ox_inventory:openInventory('shop', { type = 'General', id = 1 })type is the shop key. id is the position of the location in the locations (or targets) list, starting at 1. If a shop has one location, use id = 1. A shop with no locations that was registered by code is opened with its type alone, so test your version if id is needed.
Tip: the server still checks the shop when you open it, so a client cannot buy from a job shop it has no job for.
Making shops without editing code
If you set up many shops, editing Lua gets repetitive. Shop Creator lets you create shops in game.
Shop CreatorBuild a shop in under a minute β owners, employees, vaults and robberies included.from β¬24.20View script β
Checklist
| Symptom | Fix |
|---|---|
| Shop does not appear | Restart ox_inventory after editing data/shops.lua |
| Shop opens empty or errors | An item in inventory is missing from data/items.lua |
| Cannot interact with the shop | Check locations or targets, and that ox_target runs |
| Wrong currency | Set currency on the item entry |
| Job shop open to everyone | Add groups = { job = grade } |
| Registered shop lost after restart | Call RegisterShop again when ox_inventory starts |
Quick answers
Where do I add a shop in ox_inventory?
In ox_inventory/data/shops.lua, as a new entry with a name, an inventory list and one or more locations or targets. Restart ox_inventory afterwards.
Can a shop take black money instead of cash?
Yes. Set currency = 'black_money' on the item entry, and the shop charges that item instead of the default money.
How do I create a shop from my own script?
Call exports.ox_inventory:RegisterShop(type, data) on the server, then open it from the client with exports.ox_inventory:openInventory('shop', { type = type }).
