Skip to content

Commit

Permalink
Merge branch 'main' into enhance-inventory-html
Browse files Browse the repository at this point in the history
  • Loading branch information
adhershmnair authored Nov 26, 2024
2 parents 9e5f998 + 48ed1ed commit 67fbcf0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion html/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ div {
}

.custom-tooltip {
max-width: 6vw;
max-width: 20vw;
}

.custom-tooltip .tooltip-header {
Expand Down
5 changes: 5 additions & 0 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ function ClearInventory(source, filterItems)
if not player.Offline then
local logMessage = string.format('**%s (citizenid: %s | id: %s)** inventory cleared', GetPlayerName(source), player.PlayerData.citizenid, source)
TriggerEvent('qb-log:server:CreateLog', 'playerinventory', 'ClearInventory', 'red', logMessage)
local ped = GetPlayerPed(source)
local weapon = GetSelectedPedWeapon(ped)
if weapon ~= `WEAPON_UNARMED` then
RemoveWeaponFromPed(ped, weapon)
end
if Player(source).state.inv_busy then TriggerClientEvent('qb-inventory:client:updateInventory', source) end
end
end
Expand Down
13 changes: 12 additions & 1 deletion server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ QBCore.Functions.CreateCallback('qb-inventory:server:attemptPurchase', function(
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
Expand All @@ -351,12 +350,24 @@ QBCore.Functions.CreateCallback('qb-inventory:server:attemptPurchase', function(
end
end

if shopInfo.items[itemInfo.slot].name ~= itemInfo.name then -- Check if item name passed is the same as the item in that slot
cb(false)
return
end

if amount > shopInfo.items[itemInfo.slot].amount then
TriggerClientEvent('QBCore:Notify', source, 'Cannot purchase larger quantity than currently in stock', 'error')
cb(false)
return
end

if not CanAddItem(source, itemInfo.name, amount) then
TriggerClientEvent('QBCore:Notify', source, 'Cannot hold item', 'error')
cb(false)
return
end

local price = shopInfo.items[itemInfo.slot].price * amount
if Player.PlayerData.money.cash >= price then
Player.Functions.RemoveMoney('cash', price, 'shop-purchase')
AddItem(source, itemInfo.name, amount, nil, itemInfo.info, 'shop-purchase')
Expand Down

0 comments on commit 67fbcf0

Please sign in to comment.