From e2a8e75de6ebf1d4b70c9a1dd125d0ab3639c1a5 Mon Sep 17 00:00:00 2001 From: Luke <62490330+Luke20201@users.noreply.github.com> Date: Mon, 21 Oct 2024 19:57:26 +0100 Subject: [PATCH] Update functions.lua --- server/functions.lua | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/functions.lua b/server/functions.lua index 1eead0cd..2db0fb5b 100644 --- a/server/functions.lua +++ b/server/functions.lua @@ -586,8 +586,9 @@ exports('OpenInventory', OpenInventory) --- @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') @@ -596,6 +597,13 @@ function AddItem(identifier, item, amount, slot, info, reason) local inventory, inventoryWeight, inventorySlots local player = QBCore.Functions.GetPlayer(identifier) + local vehicle = nil + for word in string.gmatch(identifier, "([^%-]+)") do + if word == "trunk" or word == "glovebox" then + vehicle = word + break + end + end if player then inventory = player.PlayerData.items inventoryWeight = Config.MaxWeight @@ -608,6 +616,19 @@ 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 = {} + 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