Esc to clear, Enter to open the best match, click an export to open it in its page
Jobs & Shops

Shops API

Server and client exports for shops. New to shops? Read Shops first.

Finding shops

GetShop(ref)SERVER#

One shop, by id or by what you hold, as GetVehicle takes a reference.

ParamTypeDescription
refnumber|tableA shop id, { key = }, or { containerId = } (the shop whose stock that container is)
Returns: table|nil: { shopId, key, name, mode, jobId, containerId, npcModel, prop, x, y, z, heading, blipSprite, blipColor, catalog, settings }
local shop = exports.whip_core:GetShop({ key = 'burgershot' })
GetShops(filter?)SERVER#

Every shop, sorted by shopId, or one job's: a job can own several.

ParamTypeDescription
filtertable?{ job = }, by key or jobId
Returns: table[]; {}, 'No such job' for an unknown job
GetShopViewers(shopId)SERVER#

The players browsing a shop now.

ParamTypeDescription
shopIdnumberShop ID
Returns: number[]: sources

Creating and changing shops

EnsureShop(key, data)SERVERWAITS#

A shop declared by key, safe on every start (example). The same declaration again changes nothing, so an admin's edits stand; a changed one applies your fields and clears a link you dropped (jobId, containerId, npcModel, prop, blipSprite). Another running resource's key is refused.

ParamTypeDescription
keystringStable shop id
datatable{ name, mode, npcModel?, prop?, x, y, z, heading, catalog?, jobId?, containerId?, blipSprite?, blipColor?, settings? }; jobId takes a jobId or key
Returns: table: the shop, its declaration in settings.ensured; or false, reason (a bad catalog, no x/y/z, no such job or container, another resource's key, a database error)
OpenShop(source, ref, opts)SERVERWAITS#

Open a shop declared by the calling resource for a living, loaded player. Another resource's shop is refused. Purchases keep the shop's normal stock, payment and access checks.

ParamTypeDescription
sourcenumberOnline player server id
refnumber|tableShop id, { id = n }, { key = 'my_shop' } or { containerId = n }
optstable?range: metres, default 3, greater than 0 and at most 20. authorize(source): optional server check, must return true; checked again during the session

A physical shop opens within range of its coordinates. A virtual shop anchors the session at the player's opening position; moving out of range ends access. Validate who may open it in your server handler.

Returns: boolean opened, string|nil reason
local ok, why = exports.whip_core:OpenShop(source, { key = 'my_shop' }, { range = 3 })
CreateShop(data)SERVERWAITS#

Creates a shop on every call, without a key check: a pop-up stall for one event, say. Fires whip_core:shop:created with { shopId, shop }.

ParamTypeDescription
datatableAs EnsureShop's
Returns: table: the shop with shopId, or false, reason
UpdateShop(shopId, data)SERVERWAITS#

Changes the fields you include; false clears jobId, containerId, npcModel, prop, blipSprite or key. Fires whip_core:shop:updated with { shopId, shop }.

ParamTypeDescription
shopIdnumberShop ID
datatableShop fields. catalog ({ [itemKey] = price }) replaces an infinite or npc shop's whole catalog; for one price, use AddCatalogItem
Returns: boolean, string|nil: false, 'Shop not found' for an unknown id. Refused for another running resource's shop, as DeleteShop
DeleteShop(shopId)SERVERWAITS#

Deletes a shop, closes it for anyone browsing and despawns its entity. Fires whip_core:shop:deleted with { shopId }.

ParamTypeDescription
shopIdnumberShop ID
Returns: boolean, string|nil: false, 'Shop not found' for an unknown id. Refused for a shop another running resource made or declares; one made in /whip, or whose resource isn't running, is open to any
SetShopLayout(shopId, { categories, layout })SERVERWAITS#

Sets a shop's tabs and where its goods sit, as Edit Shelf does for its managers and WHIP's admins. Lower order comes first; unplaced goods follow, A to Z. Both fields can also sit in a shop's settings (config.lua §9, EnsureShop).

ParamTypeDescription
shopIdnumberShop ID (any mode)
categoriesstring[]?The tabs in order: 1–24 letters each, at most 12. Omitted: kept
layouttable?{ [itemKey] = { category, order } }. Each entry replaces that item's place; one with neither removes it; others keep theirs
Returns: boolean, string|nil: false for an unknown item, a tab the shop doesn't have, a tab name too long or too many tabs

Virtual shops

Set settings.virtual = true in EnsureShop, CreateShop or UpdateShop when your resource provides the interaction. WHIP creates no keeper, prop, prompt or blip for it; open it through OpenShop. The shop still needs x/y/z in its declaration and uses the same catalog, stock and payment rules.

Catalog (infinite and npc shops)

GetShopCatalog(shopId)SERVER#

An infinite or npc shop's catalog.

ParamTypeDescription
shopIdnumberShop ID
Returns: table|nil: { [itemKey] = price }, nil for no such shop
AddCatalogItem(shopId, itemKey, price)SERVERWAITS#

Adds or reprices one registered item in an infinite or npc shop's catalog, and saves it.

ParamTypeDescription
shopIdnumberShop ID
itemKeystringItem key
pricenumber≥ 0
Returns: boolean, string|nil
RemoveCatalogItem(shopId, itemKey)SERVERWAITS#

Removes one item from an infinite or npc shop's catalog, and saves it.

ParamTypeDescription
shopIdnumberShop ID
itemKeystringItem key
Returns: boolean, string|nil

Stock and prices (stocked shops)

GetShopStock(shopId)SERVERWAITS#

A stocked shop's shelf, each slot with its item's price. Loaded from the database if not cached.

ParamTypeDescription
shopIdnumberA stocked shop
Returns: table: { [slot] = { item, amount, metadata, price, forSale } }, or false, reason (not stocked, no such shop)
GetShopPrices(shopId)SERVERWAITS#

Every item price a stocked shop has, for sale or not.

ParamTypeDescription
shopIdnumberA stocked shop
Returns: table: { [itemKey] = { price, forSale } }, or false, reason (not stocked, no such shop)
SetShopItemPrice(containerId, itemKey, price, forSale)SERVERWAITS#

Prices an item on a stocked shop's shelf, or takes it off sale. One price per item, for every slot holding it; customers see it at once. Fires whip_core:shop:priceChanged with { containerId, item, price, forSale }.

ParamTypeDescription
containerIdnumber|tableThe stock container ID, or { shopId = n }, as every shop export takes
itemKeystringA registered item
pricenumberDollars (0 = free; negative becomes 0)
forSalebooleanfalse keeps the price but hides the item
Returns: boolean, string|nil: 'Unknown container', 'Unknown item', 'Invalid price' (not a number)
exports.whip_core:SetShopItemPrice({ shopId = shopId }, 'drink', 5, true)   -- water at $5

Client#

IsShopOpen()CLIENT#

Whether the shop screen is open.

Returns: boolean
GetActiveShopId()CLIENT#

The shop the player is browsing, or nil.

Returns: number|nil