Skip to content

Commit 3b3b923

Browse files
feat(hooks): add item bought hook and builder
1 parent 358fcf9 commit 3b3b923

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

server/functions.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,23 @@ local function buildMovedData(fromInventory, toInventory, fromId, toId, fromSlot
965965
}
966966
end
967967

968+
local function buildShopData(shopType, shopId, itemSlot, amount, toId)
969+
local shopData = RegisteredShops[shopId]
970+
local itemData = shopData.items[itemSlot]
971+
return {
972+
shopType = shopType,
973+
shop = shopData,
974+
toId = toId,
975+
item = itemData,
976+
amount = amount,
977+
total = itemData.price * amount,
978+
}
979+
end
980+
968981
function buildHookData(hookType, ...)
969982
if hookType == 'ItemMoved' then
970983
return buildMovedData(...)
984+
elseif hookType == 'ItemBought' then
985+
return buildShopData(...)
971986
end
972987
end

server/main.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ QBCore.Functions.CreateCallback('qb-inventory:server:attemptPurchase', function(
375375

376376
local price = shopInfo.items[itemInfo.slot].price * amount
377377
if Player.PlayerData.money.cash >= price then
378+
local hookData = buildHookData('ItemBought', 'shop', shop, itemInfo.slot, amount, source)
379+
if TriggerHook('ItemBought', 'shop', hookData) == false then cb(false) return end
378380
Player.Functions.RemoveMoney('cash', price, 'shop-purchase')
379381
AddItem(source, itemInfo.name, amount, nil, itemInfo.info, 'shop-purchase')
380382
shopInfo.items[itemInfo.slot].amount -= amount

0 commit comments

Comments
 (0)