Developer API
Everything here is a stable, versioned promise. Anything not listed is internal and may change.
Everything here is a stable, versioned promise. Anything not listed is internal and may change.
Server exports
lua
local price = exports.cc_boutique:GetPrice('lux_watch_gold') -- integer this week, or nil| Export | Returns | |
|---|---|---|
GetPrice(id) | integer|nil | this week's price of a piece |
GetPrices() | { [id] = { price, prev, week, median } } | every piece. prev is last week's price |
GetNextReprice() | integer | unix time of the next weekly re-price (0 in fixed mode) |
GetShelf() | { { id, label, category, use, image } } | the shelf, a copy |
Reprice() | boolean | re-price this week now (still capped against last week) |
Sell(src, id, account) | boolean, string | sell a piece to a player with every check: their money, carry space and your hooks. The string is the result's locale key ('buy.done', 'buy.short', 'buy.full', ...). Server-side only, for example for a phone shop app. It skips the counter distance check, so call it only from your own trusted code |
useItem(event, item, inventory, slot) | the ox_inventory item export. Do not call it yourself | |
getVersion() | string | '2.0.0' |
getApi() | table | a machine-readable list of exports and hooks |
registerHook(name, fn) | id | see Hooks |
removeHook(id) |
Client exports
| Export | Returns | |
|---|---|---|
OpenShop() | boolean | open the boutique. The player must stand at a counter, and the server checks |
CloseShop() | close it and release focus | |
IsOpen() | boolean |
Hooks (server)
Register from your own resource. Hooks you register are removed automatically when your resource stops.
lua
exports.cc_boutique:registerHook('cc_boutique:beforeBuy', function(p)
if p.item == 'lux_pink_diamond' and not IsPlayerAceAllowed(p.src, 'vip') then
return false -- refuse: the buyer sees "This piece can't be sold to you right now."
end
end)| Hook | Kind | Payload | Return |
|---|---|---|---|
cc_boutique:beforeBuy | cancellable | { src, item, price, account } | false refuses the sale before any money moves |
cc_boutique:bought | notify | { src, cid, item, price, account } | |
cc_boutique:use | cancellable | { src, item, use, slot, metadata } | false = you handled the use, so the built-in one does not run |
cc_boutique:repriced | notify | { week, median, source, prices = { [id] = price } } | |
cc_boutique:median | filter | (median, { source }) | a number replaces the median for this week's pricing |
cc_boutique:price | filter | (price, { item, week, median }) | a number replaces that piece's price for the week |
Keep hook handlers fast. Do not call the database or Wait inside one: a handler slower than 5 ms is named in the console.
Examples
Your own wealth source:
lua
exports.cc_boutique:registerHook('cc_boutique:median', function(median, ctx)
return MySQL.scalar.await('SELECT median FROM my_economy_stats ORDER BY id DESC LIMIT 1') or median
end)(The median filter runs once a week, so a single query is fine there.)
Give watches a real prop instead of a title:
lua
exports.cc_boutique:registerHook('cc_boutique:use', function(p)
if p.use == 'title' then
TriggerClientEvent('my_jewellery:wear', p.src, p.item)
return false
end
end)Log every sale to your own system:
lua
exports.cc_boutique:registerHook('cc_boutique:bought', function(p)
exports.my_logs:Add('boutique', p.cid, p.item, p.price)
end)Events
| Event | Side | |
|---|---|---|
cc_boutique:ready | both | fired with the version once the API is published |
cc_boutique:result | client (internal) | the result of a purchase. Do not trigger it |
cc_boutique:buy | server (internal) | guarded by cc_lib's security layer. Two integers in. Do not trigger it from other resources: use Sell |
Database
| Table | Columns |
|---|---|
cc_boutique_prices | item (PK), week, price, prev, median, updated_at |
cc_boutique_sales | id, citizenid, item, price, account, at (unix time) |
Reading them is safe. Writing cc_boutique_prices while the server runs is overwritten at the next re-price.