AddTrunkItems + testing across all bridged inventories

This commit is contained in:
MrNewb committed 2025-06-08 04:36:53 -04:00
1 parent 224bb24ee8
commit 63c644d277
10 files changed
+58 -33

No files matched your search

+1
View File
@@ -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
+2 -2
View File
@@ -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
+2 -1
View File
@@ -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
+2 -1
View File
@@ -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
+10 -10
View File
@@ -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
+1 -2
View File
@@ -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
@@ -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
+22 -13
View File
@@ -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
+16 -4
View File
@@ -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}
@@ -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