```lua
local shopfound = exports['wert-shops']:ShopCheck(QBCore.Shared.SplitStr(shopType, "_")[2])
if shopfound then
TriggerEvent("wert-shops:server:UpdateShopItems", QBCore.Shared.SplitStr(shopType, "_")[2], itemData, fromAmount)
TriggerEvent("wert-shops:server:after-buy", QBCore.Shared.SplitStr(shopType, "_")[2], price)
end
```
QBCore.Functions.CreateCallback('qb-inventory:server:attemptPurchase', function(source, cb, data)
local itemInfo = data.item
local amount = data.amount
local shop = string.gsub(data.shop, 'shop%-', '')
local price = itemInfo.price * amount
local Player = QBCore.Functions.GetPlayer(source)
if not Player then
cb(false)
return
end
local shopInfo = RegisteredShops[shop]
if not shopInfo then
cb(false)
return
end
local playerPed = GetPlayerPed(source)
local playerCoords = GetEntityCoords(playerPed)
if shopInfo.coords then
local shopCoords = vector3(shopInfo.coords.x, shopInfo.coords.y, shopInfo.coords.z)
if #(playerCoords - shopCoords) > 10 then
cb(false)
return
end
end
if not CanAddItem(source, itemInfo.name, amount) then
TriggerClientEvent('QBCore:Notify', source, 'Cannot hold item', 'error')
cb(false)
return
end
if Player.PlayerData.money.cash >= price then
Player.Functions.RemoveMoney('cash', price, 'shop-purchase')
AddItem(source, itemInfo.name, amount, nil, itemInfo.info, 'shop-purchase')
local shop_first = QBCore.Shared.SplitStr(shop, "_")[1]
if shop_first and shop_first == 'WertShop' then
local shop_preset = QBCore.Shared.SplitStr(shop, "_")[2]
local shopfound = exports['wert-shops']:ShopCheck(shop_preset)
if shopfound then
TriggerEvent("wert-shops:server:UpdateShopItems", shop_preset, itemInfo, amount)
TriggerEvent("wert-shops:server:after-buy", shop_preset, price)
end
else
TriggerEvent('qb-shops:server:UpdateShopItems', shop, itemInfo, amount)
end
cb(true)
else
TriggerClientEvent('QBCore:Notify', source, 'You do not have enough money', 'error')
cb(false)
end
end)