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 2 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
39 changes: 35 additions & 4 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -671,12 +671,40 @@ 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, fromslot, itemName, amount, info, created, vehicleName, vehicleClass)
Luke20201 marked this conversation as resolved.
Show resolved Hide resolved
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()
if not created then
itemInfo['created'] = os.time()
else
itemInfo['created'] = created
end
info = info or {}
itemInfo['created'] = created or time
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 -- if already occupied, add amount
Trunks[plate].items[slot].amount = Trunks[plate].items[slot].amount + amount
else
local itemInfo = QBCore.Shared.Items[itemName:lower()]
Expand All @@ -698,7 +726,7 @@ local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, create
else
if Trunks[plate].items[slot] and Trunks[plate].items[slot].name == itemName then
local itemInfo = QBCore.Shared.Items[itemName:lower()]
Trunks[plate].items[otherslot] = {
Trunks[plate].items[fromslot] = {
name = itemInfo["name"],
amount = amount,
info = info or "",
Expand All @@ -710,7 +738,7 @@ local function AddToTrunk(plate, slot, otherslot, itemName, amount, info, create
useable = itemInfo["useable"],
image = itemInfo["image"],
created = created,
slot = otherslot,
slot = fromslot,
}
else
local itemInfo = QBCore.Shared.Items[itemName:lower()]
Expand All @@ -732,6 +760,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 +778,7 @@ local function RemoveFromTrunk(plate, slot, itemName, amount)
end
end

exports("RemoveFromTrunk", RemoveFromTrunk)

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