diff --git a/server/functions.lua b/server/functions.lua index 1153a701..dba3fa4c 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -661,8 +661,9 @@ exports('RemoveInventory', RemoveInventory) --- @param slot number (optional) The slot to add the item to. If not provided, it will find the first available slot. --- @param info table (optional) Additional information about the item. --- @param reason string (optional) The reason for adding the item. +--- @param vehicleClass number (optional) The class of the vehicle if its being added to a newly created vehicle. Used in detecting the number of slots. --- @return boolean Returns true if the item was successfully added, false otherwise. -function AddItem(identifier, item, amount, slot, info, reason) +function AddItem(identifier, item, amount, slot, info, reason, vehicleClass) local itemInfo = QBCore.Shared.Items[item:lower()] if not itemInfo then print('AddItem: Invalid item') @@ -671,9 +672,16 @@ function AddItem(identifier, item, amount, slot, info, reason) local inventory, inventoryWeight, inventorySlots local player = QBCore.Functions.GetPlayer(identifier) + local vehicle = nil + local word = QBCore.Shared.SplitStr(identifier, '-')[1] + if word == "trunk" or word == "glovebox" then + vehicle = word + end if player then + local src = player.PlayerData.source inventory = player.PlayerData.items - inventoryWeight = Config.MaxWeight + local value = exports["dw_skillsystem"]:GetSkillValue(src, "maxWeight") + inventoryWeight = Config.MaxWeight * value inventorySlots = Config.MaxSlots elseif Inventories[identifier] then inventory = Inventories[identifier].items @@ -683,6 +691,20 @@ function AddItem(identifier, item, amount, slot, info, reason) inventory = Drops[identifier].items inventoryWeight = Drops[identifier].maxweight inventorySlots = Drops[identifier].slots + elseif vehicle then + Inventories[identifier] = {} + Inventories[identifier].items = {} + inventory = Inventories[identifier].items + local storageConfig = VehicleStorage[vehicleClass] or VehicleStorage.default + if vehicle == "trunk" then + Inventories[identifier].maxweight = storageConfig.trunkWeight + Inventories[identifier].slots = storageConfig.trunkSlots + else + Inventories[identifier].maxweight = storageConfig.gloveboxWeight + Inventories[identifier].slots = storageConfig.gloveboxSlots + end + inventoryWeight = Inventories[identifier].maxweight + inventorySlots = Inventories[identifier].slots end if not inventory then