From 63c644d277d695e6faca98c3f62a14773620c867 Mon Sep 17 00:00:00 2001 From: MrNewb <47620135+MrNewb@users.noreply.github.com> Date: Sun, 8 Jun 2025 04:36:53 -0400 Subject: [PATCH] AddTrunkItems + testing across all bridged inventories --- modules/inventory/_default/server.lua | 1 + modules/inventory/codem-inventory/server.lua | 4 +-- modules/inventory/core_inventory/server.lua | 3 +- modules/inventory/jpr-inventory/server.lua | 3 +- modules/inventory/origen_inventory/server.lua | 20 +++++------ modules/inventory/ox_inventory/server.lua | 3 +- modules/inventory/ps-inventory/server.lua | 1 + modules/inventory/qb-inventory/server.lua | 35 ++++++++++++------- modules/inventory/qs-inventory/server.lua | 20 ++++++++--- modules/inventory/tgiann-inventory/server.lua | 1 + 10 files changed, 58 insertions(+), 33 deletions(-) diff --git a/modules/inventory/_default/server.lua b/modules/inventory/_default/server.lua index 41b0a25..df4fa94 100644 --- a/modules/inventory/_default/server.lua +++ b/modules/inventory/_default/server.lua @@ -39,6 +39,7 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return false, Prints.Error("This Inventory Has Not Been Bridged For A ClearStash Feature.") end diff --git a/modules/inventory/codem-inventory/server.lua b/modules/inventory/codem-inventory/server.lua index e4c40d9..e87c299 100644 --- a/modules/inventory/codem-inventory/server.lua +++ b/modules/inventory/codem-inventory/server.lua @@ -65,7 +65,6 @@ Inventory.GetPlayerInventory = function(src) end ---Returns the specified slot data as a table. ---- ---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number @@ -153,7 +152,7 @@ end ---@param identifier string ---@param items table ---@return boolean -Inventory.AddItemsToTrunk = function(identifier, items) +Inventory.AddTrunkItems = function(identifier, items) if type(items) ~= "table" then return false end return false, print("AddItemsToTrunk is not implemented in codem-inventory, because of this we dont have a way to add items to a trunk.") end @@ -163,6 +162,7 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return false, print("ClearInventory is not implemented in codem-inventory, because of this we dont have a way to clear a stash.") end diff --git a/modules/inventory/core_inventory/server.lua b/modules/inventory/core_inventory/server.lua index 5fba66f..baf9fb5 100644 --- a/modules/inventory/core_inventory/server.lua +++ b/modules/inventory/core_inventory/server.lua @@ -198,7 +198,7 @@ end ---@param identifier string ---@param items table ---@return boolean -Inventory.AddItemsToTrunk = function(identifier, items) +Inventory.AddTrunkItems = function(identifier, items) if type(items) ~= "table" then return false end return false, print("AddItemsToTrunk is not implemented in core_inventory, because of this we dont have a way to add items to a trunk.") end @@ -208,6 +208,7 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return false, print("ClearInventory is not implemented in core_inventory, because of this we dont have a way to clear a stash.") end diff --git a/modules/inventory/jpr-inventory/server.lua b/modules/inventory/jpr-inventory/server.lua index 45eede7..53fdefb 100644 --- a/modules/inventory/jpr-inventory/server.lua +++ b/modules/inventory/jpr-inventory/server.lua @@ -100,7 +100,7 @@ end ---@param identifier string ---@param items table ---@return boolean -Inventory.AddItemsToTrunk = function(identifier, items) +Inventory.AddTrunkItems = function(identifier, items) if type(items) ~= "table" then return false end return false, print("AddItemsToTrunk is not implemented in jpr-inventory, because of this we dont have a way to add items to a trunk.") end @@ -110,6 +110,7 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return false, print("ClearInventory is not implemented in jpr-inventory, because of this we dont have a way to clear a stash.") end diff --git a/modules/inventory/origen_inventory/server.lua b/modules/inventory/origen_inventory/server.lua index c5ccd35..aa2224e 100644 --- a/modules/inventory/origen_inventory/server.lua +++ b/modules/inventory/origen_inventory/server.lua @@ -52,12 +52,12 @@ Inventory.AddTrunkItems = function(identifier, items) end ---This will clear the specified inventory, will always return true unless a value isnt passed correctly. ----@param id string +---@param identifier string ---@return boolean -Inventory.ClearStash = function(id, _type) - if type(id) ~= "string" then return false end - local inventory = origin:getInventory(id, _type) - if not inventory then return false end +Inventory.ClearStash = function(identifier, _type) + if type(identifier) ~= "string" then return false end + if Inventory.Stashes[identifier] then Inventory.Stashes[identifier] = nil end + local id = identifier if _type == "trunk" then id = "trunk_"..id elseif _type == "glovebox" then @@ -65,9 +65,12 @@ Inventory.ClearStash = function(id, _type) elseif _type == "stash" then id = "stash_"..id end - for _, v in pairs(inventory) do + local inv = origin:getInventory(identifier, _type) + if not inv then return false end + local indexed = inv.inventory + for _, v in pairs(indexed) do if v.slot then - origin:removeItem(id, v.name, v.count) + origin:removeItem(id, v.name, v.amount, nil, v.slot) end end return true @@ -89,9 +92,7 @@ Inventory.GetItemInfo = function(item) } end - ---This will return the count of the item in the players inventory, if not found will return 0. ---- ---if metadata is passed it will find the matching items count. ---@param src number ---@param item string @@ -109,7 +110,6 @@ Inventory.GetPlayerInventory = function(src) end ---Returns the specified slot data as a table. ---- ---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number diff --git a/modules/inventory/ox_inventory/server.lua b/modules/inventory/ox_inventory/server.lua index 234aaef..1bd2d3b 100644 --- a/modules/inventory/ox_inventory/server.lua +++ b/modules/inventory/ox_inventory/server.lua @@ -52,6 +52,7 @@ end Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end ox_inventory:ClearInventory(_type..id, nil) + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return true end @@ -205,9 +206,7 @@ end ---UNUSED: ---This will return generic item data from the specified inventory, with the items total count. ---- ---format without metadata { count, stack, name, weight, label } ---- ---fortmat with metadata { count, stack, name, weight, label, metadata } ---@param src number ---@param item string diff --git a/modules/inventory/ps-inventory/server.lua b/modules/inventory/ps-inventory/server.lua index 38c5ae3..d6ba99e 100644 --- a/modules/inventory/ps-inventory/server.lua +++ b/modules/inventory/ps-inventory/server.lua @@ -46,6 +46,7 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return false, print("ClearInventory is not implemented in ps-inventory, because of this we dont have a way to clear a stash.") end diff --git a/modules/inventory/qb-inventory/server.lua b/modules/inventory/qb-inventory/server.lua index 52a5924..cdefa7b 100644 --- a/modules/inventory/qb-inventory/server.lua +++ b/modules/inventory/qb-inventory/server.lua @@ -44,25 +44,32 @@ end ---@param identifier string ---@param items table ---@return boolean -Inventory.AddItemsToTrunk = function(identifier, items) +Inventory.AddTrunkItems = function(identifier, items) if type(items) ~= "table" then return false end local fullTrunkId = "trunk-"..identifier local repacked_items = {} + local slot = 0 for _, item in pairs(items) do - table.insert(repacked_items, { + slot = slot + 1 + repacked_items[slot] = { name = item.item, amount = item.count, - info = item.metadata or {} - }) + info = item.metadata, + type = item.type or "item", + slot = slot, + } end - - if getInventoryNewVersion() then - qbInventory:addTrunkItems(fullTrunkId, repacked_items) - else - if not qbInventory:GetInventory(fullTrunkId) then - qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId, slots = 20, maxweight = 10000 }) + local newVersion = getInventoryNewVersion() + if newVersion then + qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId }) + Wait(1000) + for i = 1, #repacked_items do + local v = repacked_items[i] + qbInventory:AddItem(fullTrunkId, v.name, v.amount, v.slot, v.info, "community_bridge, adding items to trunk") end - qbInventory:SetInventory(fullTrunkId, repacked_items, "Community Bridge Moving Items In Trunk") + else + -- I dont have a copy of this version to test it, if you run into issues please let me know. + TriggerEvent("inventory:server:addTrunkItems", fullTrunkId, repacked_items) end return true end @@ -77,7 +84,10 @@ Inventory.ClearStash = function(id, _type) elseif _type == "glovebox" then id = "glovebox-"..id end - qbInventory:ClearStash(id) + if qbInventory:GetInventory(id) then + qbInventory:ClearStash(id) + end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return true end @@ -98,7 +108,6 @@ Inventory.GetItemInfo = function(item) end ---Returns the specified slot data as a table. ---- ---format {weight, name, metadata, slot, label, count} ---@param src number ---@param slot number diff --git a/modules/inventory/qs-inventory/server.lua b/modules/inventory/qs-inventory/server.lua index 2fded30..f29fe20 100644 --- a/modules/inventory/qs-inventory/server.lua +++ b/modules/inventory/qs-inventory/server.lua @@ -35,14 +35,21 @@ end ---@param identifier string ---@param items table ---@return boolean -Inventory.AddItemsToTrunk = function(identifier, items) +Inventory.AddTrunkItems = function(identifier, items) if type(items) ~= "table" then return false end + return false + --[[ for k, v in pairs(items) do - local count = v.count or 1 - local metadata = v.metadata or {} - quasar:AddToTrunk(identifier, nil, nil, v.item, count, metadata, nil) + -- + In testing this inventory allowed it on owned vehicle but not unowned vehicles, + also attempted registering it as a stash with no luck. + was thinking about just forcing it in sql but there is data attached that I assume is a timestamp + kinda not sure on this one atm... + Also there is no GetInventory(identifier) only by player source + --quasar:AddToTrunk(identifier, v.count, v.metadata, v.item, v.metadata) end return true + --]] end ---This will clear the specified inventory, will always return true unless a value isnt passed correctly. @@ -50,8 +57,13 @@ end ---@return boolean Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end + return false + --[[ quasar:ClearOtherInventory(_type, id) + return true + --]] end ---This will return a table with the item info, {name, label, stack, weight, description, image} diff --git a/modules/inventory/tgiann-inventory/server.lua b/modules/inventory/tgiann-inventory/server.lua index 8dcbc62..ecca9a0 100644 --- a/modules/inventory/tgiann-inventory/server.lua +++ b/modules/inventory/tgiann-inventory/server.lua @@ -190,6 +190,7 @@ end Inventory.ClearStash = function(id, _type) if type(id) ~= "string" then return false end tgiann:DeleteInventory(_type, id) + if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end return true end