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

Add item to trunk export #119

Open
wants to merge 5 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
31 changes: 29 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,36 @@ local function SaveOwnedVehicleItems(plate, items)
Trunks[plate].isOpen = false
end

local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, created)
local function FindEmptyTrunkSlot(items, vehicleName, vehicleClass)
local slots = Config.VehicleInventories.vehicles[vehicleName] or Config.VehicleInventories.classes[vehicleClass] or Config.VehicleInventories.default
for i = 1, slots.slots do
if items[i] == nil then
return i
end
end
return nil
end

local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, created, vehicleName, vehicleClass)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While at it, splitting this method into smaller methods for readability would be nice.

if not Trunks[plate] then
Trunks[plate] = {}
Trunks[plate].items = {}
Trunks[plate].isOpen = false
Trunks[plate].label = "Trunk-" .. plate
end

if not slot then slot = FindEmptyTrunkSlot(Trunks[plate].items, vehicleName, vehicleClass) end
amount = tonumber(amount) or 1

local itemInfo = QBCore.Shared.Items[itemName:lower()]
local time = os.time()
itemInfo['created'] = created or time

info = info or {}
local ItemData = QBCore.Shared.Items[itemName]

if not ItemData.unique then
if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then
if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then
Trunks[plate].items[slot].amount = Trunks[plate].items[slot].amount + amount
else
local itemInfo = QBCore.Shared.Items[itemName:lower()]
Expand Down Expand Up @@ -732,6 +756,8 @@ local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, create
end
end

exports("AddToTrunk", AddToTrunk)

local function RemoveFromTrunk(plate, slot, itemName, amount)
amount = tonumber(amount) or 1
if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then
Expand All @@ -748,6 +774,7 @@ local function RemoveFromTrunk(plate, slot, itemName, amount)
end
end

exports("RemoveFromTrunk", RemoveFromTrunk)

-- Glovebox items
local function GetOwnedVehicleGloveboxItems(plate)
Expand Down