Draw another shop type in the screen#
The shop type has to exist in ox_inventory first, in data/shops.lua or through RegisterShop. Then add it to Config.Shops:
-- config/main.lua
Config.Shops = {
-- ...the default entries...
{ match = 'DigitalDen', icon = 'ti-devices', label = 'Digital Den', order = { 'phones', 'tools' } },
}
To open a shop only from the GTA clerk, set clerk = true on its type in data/shops.lua. With the patch applied, that shop type gets its blip but no counter zone.
Point the price surge at your restaurant#
-- config/clerks.lua
Config.Clerks.FoodJobs = { 'uwucafe', 'pizzeria' } -- your restaurant job names
Config.Clerks.Mult = 2
Config.Clerks.Items = { 'water', 'sprunk', 'coffee', 'sandwich', 'burger' }
-- or turn it off
Config.Clerks.FoodJobs = {}
Open a shop from your own resource#
-- client
local opened = exports['glitch-stores']:OpenShop('General', 1)
shopId is the location index for shop types with several counters. The server runs ox_inventory's group, distance and openShop hook checks first. A shop type that is not in Config.Shops, or an unpatched ox_inventory, opens ox_inventory's own window instead.
Tags and limits on an armoury#
Call this on the server before you open a shop you registered for one player:
exports['glitch-stores']:SetCardTags(src, shopType,
{ WEAPON_PISTOL = 'Patrol', WEAPON_CARBINERIFLE = 'SWAT' }, -- tag, top left of the card
{ WEAPON_PISTOL = 1, ['ammo-9'] = 0 }) -- "Max N", 0 shows no limit
exports['glitch-stores']:SetCardTags(src, nil) -- clear
The tags only change what the cards show. Enforce limits in your own ox_inventory buyItem hook.
A supplier paid from a business account#
-- server, in your resource
exports['glitch-stores']:OpenBusiness(src, {
label = 'Packaging Supplier',
icon = 'ti-truck-delivery',
coords = vec3(0.0, 0.0, 0.0), -- the screen closes when the player walks away from here
account = 'My Business',
balance = 25000,
items = { { name = 'burger_box', price = 2 } },
handler = { resource = GetCurrentResourceName(), export = 'SupplierBuy' },
})
exports('SupplierBuy', function(src, lines)
-- lines = { { slot, name, count, price } }, prices from your items table
-- check job and distance again, take the money from the business account,
-- then give the items, for example with exports.ox_inventory:AddItem(src, line.name, line.count)
return { bought = bought, spent = spent, error = nil, balance = newBalance }
end)
A vending machine your resource runs#
exports['glitch-stores']:OpenCustom(src, {
label = 'Vending Machine',
icon = 'ti-bottle',
coords = machineCoords,
items = {
{ name = 'water', price = 5, count = 12 }, -- count = stock left, nil = no limit
{ name = 'sprunk', price = 6, was = 8, tag = 'Deal' }, -- was = price before a discount
},
hideSoldOut = true,
discountLabel = 'Happy hour',
handler = { resource = GetCurrentResourceName(), export = 'MachineSale' },
})
exports('MachineSale', function(src, lines, payment)
-- lines = { { slot, name, count } }, slot = index in items
-- payment is 'cash', 'card' or 'take'. Look prices up from your own list,
-- and refuse 'take' for anything that costs money.
return { bought = bought, spent = spent, error = nil, items = freshItems }
end)
How a purchase works#
flowchart LR
C["Clerk, shop zone or OpenShop"] --> O["ox_inventory open checks"]
O --> S["Screen with a session token"]
S -->|"basket + token"| B["Server re-checks"]
B --> X["GlitchBuyItem and buyItem hooks"]
X --> I["Changed slots sent to the player"]
The basket is sent back as { slot, count, price } lines with the screen's token. The server reads the shop again, adds repeated lines together and caps each item at maxPerLine. A line whose price changed since the screen was drawn is refused, and the screen redraws with the new prices. The server only compares the price the client sends with its own, and ox_inventory charges its own price. Items that do not stack, like weapons, are bought one per slot. When the shop has less stock than the basket asks for, ox_inventory sells what it has, and the player is told and charged for that amount.
Like ox_inventory, the group re-check looks at job and grade, not duty. A shop that needs staff on duty checks that in its own buyItem hook.
Security#
| Area | What the server does |
|---|---|
| Sessions | Each screen has a token. A purchase from a screen the server no longer knows is refused. A player can hold up to four sessions. |
| Prices | Read from ox_inventory on every purchase. A changed price refuses that line. |
| Access | Groups are checked again on every purchase. Distance is checked against where the screen opened, with Config.BuySlack extra for lag. |
| Flooding | Opening is limited to once per 500 ms and paying to once per 250 ms per player. One purchase runs at a time per player, and a purchase that throws an error still releases the lock. |
| Payment | A failed payment takes the item back and puts the stock back (in the patch). |
| Card tags | Kept on the server. A value a client writes to its own state bag is ignored. |
Performance#
- The screen checks distance every 400 ms, only while it is open.
- The fallback clerk scan runs every 2 s near a counter and every 5 s elsewhere.
- Clerk target answers are cached for a second.
- The server has no loops and no database access. Item definitions are cached until ox_inventory restarts.