qbcore-framework / qb-shops

Shops For QB-Core
GNU General Public License v3.0
27 stars 215 forks source link

[BUG] "Cannot hold item" I can't buy items in stores #168

Open Kashioliver777 opened 2 months ago

Kashioliver777 commented 2 months ago

I took a good look at the code and tried to break it down further to look for the error. From what I noticed, for some reason the code cannot identify the player's inventory

--- Checks if an item can be added to a inventory based on the weight and slots available. --- @param identifier string The identifier of the player or inventory. --- @param item string The item name. --- @param amount number The amount of the item. --- @return boolean - Returns true if the item can be added, false otherwise. --- @return string|nil - Returns a string indicating the reason why the item cannot be added (e.g., 'weight' or 'slots'), or nil if it can be added.

print ('this is inventory:' ..identifier) function CanAddItem(identifier, item, amount) if not Inventories[identifier] then print('dont seach inventory') return false end local Player = QBCore.Functions.GetPlayer(identifier) local itemData = QBCore.Shared.Items[item:lower()] if not itemData then return false end

local inventory, items
if Player then
    inventory = {
        maxweight = Config.MaxWeight,
        slots = Config.MaxSlots
    }
    items = Player.PlayerData.items
    print ('have slots')
elseif Inventories[identifier] then
    inventory = Inventories[identifier]
    items = Inventories[identifier].items
    print ('dont have slots')
end

local weight = itemData.weight * amount
local totalWeight = GetTotalWeight(items) + weight
if totalWeight > inventory.maxweight then
    return false, 'weight'
end

if not inventory or not items then
    print("CanAddItem: Inventory not found")
    return false
end

I added some "prints" for debug
Kashioliver777 commented 2 months ago

I spent more time looking for the error and it seems that the "CanAddItem" function is always returning false

To solve the problem temporarily I just went to qb-inventory>server>main.lua and in the callback: QBCore.Functions.CreateCallback('qb-inventory:server:attemptPurchase', function(source, cb, data)

I put the "if not CanAddItem" at the bottom of everything

madmechanic187 commented 1 month ago

same issue none of the shops work it says cannot find export in main create shops