-
Notifications
You must be signed in to change notification settings - Fork 193
Description
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