Skip to content

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
ExportReturns
GetPrice(id)integer|nilthis week's price of a piece
GetPrices(){ [id] = { price, prev, week, median } }every piece. prev is last week's price
GetNextReprice()integerunix time of the next weekly re-price (0 in fixed mode)
GetShelf(){ { id, label, category, use, image } }the shelf, a copy
Reprice()booleanre-price this week now (still capped against last week)
Sell(src, id, account)boolean, stringsell 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()tablea machine-readable list of exports and hooks
registerHook(name, fn)idsee Hooks
removeHook(id)

Client exports

ExportReturns
OpenShop()booleanopen 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)
HookKindPayloadReturn
cc_boutique:beforeBuycancellable{ src, item, price, account }false refuses the sale before any money moves
cc_boutique:boughtnotify{ src, cid, item, price, account }
cc_boutique:usecancellable{ src, item, use, slot, metadata }false = you handled the use, so the built-in one does not run
cc_boutique:repricednotify{ week, median, source, prices = { [id] = price } }
cc_boutique:medianfilter(median, { source })a number replaces the median for this week's pricing
cc_boutique:pricefilter(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

EventSide
cc_boutique:readybothfired with the version once the API is published
cc_boutique:resultclient (internal)the result of a purchase. Do not trigger it
cc_boutique:buyserver (internal)guarded by cc_lib's security layer. Two integers in. Do not trigger it from other resources: use Sell

Database

TableColumns
cc_boutique_pricesitem (PK), week, price, prev, median, updated_at
cc_boutique_salesid, 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.