Skip to content

Commit

Permalink
Update functions.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke20201 authored Oct 21, 2024
1 parent 9afdc87 commit e2a8e75
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e2a8e75

Please sign in to comment.