Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make AddItem work with non-intitalised vehicle inventories #591

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading