Hooks
Hook payload
---@meta
---@class HookPayload
---@field source number
---@field shopId string
---@field itemName string
---@field metadata table<string, any>
---@field count number
---@field price number
---@field totalPrice number buyItem hook
Called when a player is about to buy an item. You can return false to cancel the purchase.
Example
As an example, this will cancel purchase of item with name verySpecialItem.
exports.fd_shops:registerHook('buyItem', function(payload)
if payload.itemName == 'verySpecialItem' then
return false
end
end) sellItem hook
Called when a player is about to sell an item. You can return false to cancel the sale.
You can do a lot with these hooks, as an example below, a shop can be selfsustaining by refilling stock of an item when it’s sold.
Example
As an example, this will refill stock of item with name verySpecialItem.
exports.fd_shops:registerHook('sellItem', function(payload)
if payload.itemName == 'verySpecialItem' then
exports.fd_shops:addStock(payload.shopId, {
name = payload.itemName,
quantity = payload.count,
})
end
return true
end)