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 ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end 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.") return false, Prints.Error("This Inventory Has Not Been Bridged For A ClearStash Feature.")
end end
+2 -2
View File
@@ -65,7 +65,6 @@ Inventory.GetPlayerInventory = function(src)
end end
---Returns the specified slot data as a table. ---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count} ---format {weight, name, metadata, slot, label, count}
---@param src number ---@param src number
---@param slot number ---@param slot number
@@ -153,7 +152,7 @@ end
---@param identifier string ---@param identifier string
---@param items table ---@param items table
---@return boolean ---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items) Inventory.AddTrunkItems = function(identifier, items)
if type(items) ~= "table" then return false end 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.") 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 end
@@ -163,6 +162,7 @@ end
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end 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.") return false, print("ClearInventory is not implemented in codem-inventory, because of this we dont have a way to clear a stash.")
end end
+2 -1
View File
@@ -198,7 +198,7 @@ end
---@param identifier string ---@param identifier string
---@param items table ---@param items table
---@return boolean ---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items) Inventory.AddTrunkItems = function(identifier, items)
if type(items) ~= "table" then return false end 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.") 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 end
@@ -208,6 +208,7 @@ end
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end 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.") return false, print("ClearInventory is not implemented in core_inventory, because of this we dont have a way to clear a stash.")
end end
+2 -1
View File
@@ -100,7 +100,7 @@ end
---@param identifier string ---@param identifier string
---@param items table ---@param items table
---@return boolean ---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items) Inventory.AddTrunkItems = function(identifier, items)
if type(items) ~= "table" then return false end 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.") 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 end
@@ -110,6 +110,7 @@ end
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end 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.") return false, print("ClearInventory is not implemented in jpr-inventory, because of this we dont have a way to clear a stash.")
end end
+10 -10
View File
@@ -52,12 +52,12 @@ Inventory.AddTrunkItems = function(identifier, items)
end end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly. ---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
---@param id string ---@param identifier string
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(identifier, _type)
if type(id) ~= "string" then return false end if type(identifier) ~= "string" then return false end
local inventory = origin:getInventory(id, _type) if Inventory.Stashes[identifier] then Inventory.Stashes[identifier] = nil end
if not inventory then return false end local id = identifier
if _type == "trunk" then if _type == "trunk" then
id = "trunk_"..id id = "trunk_"..id
elseif _type == "glovebox" then elseif _type == "glovebox" then
@@ -65,9 +65,12 @@ Inventory.ClearStash = function(id, _type)
elseif _type == "stash" then elseif _type == "stash" then
id = "stash_"..id id = "stash_"..id
end 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 if v.slot then
origin:removeItem(id, v.name, v.count) origin:removeItem(id, v.name, v.amount, nil, v.slot)
end end
end end
return true return true
@@ -89,9 +92,7 @@ Inventory.GetItemInfo = function(item)
} }
end end
---This will return the count of the item in the players inventory, if not found will return 0. ---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. ---if metadata is passed it will find the matching items count.
---@param src number ---@param src number
---@param item string ---@param item string
@@ -109,7 +110,6 @@ Inventory.GetPlayerInventory = function(src)
end end
---Returns the specified slot data as a table. ---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count} ---format {weight, name, metadata, slot, label, count}
---@param src number ---@param src number
---@param slot number ---@param slot number
+1 -2
View File
@@ -52,6 +52,7 @@ end
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end if type(id) ~= "string" then return false end
ox_inventory:ClearInventory(_type..id, nil) ox_inventory:ClearInventory(_type..id, nil)
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
return true return true
end end
@@ -205,9 +206,7 @@ end
---UNUSED: ---UNUSED:
---This will return generic item data from the specified inventory, with the items total count. ---This will return generic item data from the specified inventory, with the items total count.
---
---format without metadata { count, stack, name, weight, label } ---format without metadata { count, stack, name, weight, label }
---
---fortmat with metadata { count, stack, name, weight, label, metadata } ---fortmat with metadata { count, stack, name, weight, label, metadata }
---@param src number ---@param src number
---@param item string ---@param item string
@@ -46,6 +46,7 @@ end
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end 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.") return false, print("ClearInventory is not implemented in ps-inventory, because of this we dont have a way to clear a stash.")
end end
+22 -13
View File
@@ -44,25 +44,32 @@ end
---@param identifier string ---@param identifier string
---@param items table ---@param items table
---@return boolean ---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items) Inventory.AddTrunkItems = function(identifier, items)
if type(items) ~= "table" then return false end if type(items) ~= "table" then return false end
local fullTrunkId = "trunk-"..identifier local fullTrunkId = "trunk-"..identifier
local repacked_items = {} local repacked_items = {}
local slot = 0
for _, item in pairs(items) do for _, item in pairs(items) do
table.insert(repacked_items, { slot = slot + 1
repacked_items[slot] = {
name = item.item, name = item.item,
amount = item.count, amount = item.count,
info = item.metadata or {} info = item.metadata,
}) type = item.type or "item",
slot = slot,
}
end end
local newVersion = getInventoryNewVersion()
if getInventoryNewVersion() then if newVersion then
qbInventory:addTrunkItems(fullTrunkId, repacked_items) qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId })
else Wait(1000)
if not qbInventory:GetInventory(fullTrunkId) then for i = 1, #repacked_items do
qbInventory:CreateInventory(fullTrunkId, { label = fullTrunkId, slots = 20, maxweight = 10000 }) local v = repacked_items[i]
qbInventory:AddItem(fullTrunkId, v.name, v.amount, v.slot, v.info, "community_bridge, adding items to trunk")
end 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 end
return true return true
end end
@@ -77,7 +84,10 @@ Inventory.ClearStash = function(id, _type)
elseif _type == "glovebox" then elseif _type == "glovebox" then
id = "glovebox-"..id id = "glovebox-"..id
end 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 return true
end end
@@ -98,7 +108,6 @@ Inventory.GetItemInfo = function(item)
end end
---Returns the specified slot data as a table. ---Returns the specified slot data as a table.
---
---format {weight, name, metadata, slot, label, count} ---format {weight, name, metadata, slot, label, count}
---@param src number ---@param src number
---@param slot number ---@param slot number
+16 -4
View File
@@ -35,14 +35,21 @@ end
---@param identifier string ---@param identifier string
---@param items table ---@param items table
---@return boolean ---@return boolean
Inventory.AddItemsToTrunk = function(identifier, items) Inventory.AddTrunkItems = function(identifier, items)
if type(items) ~= "table" then return false end if type(items) ~= "table" then return false end
return false
--[[
for k, v in pairs(items) do for k, v in pairs(items) do
local count = v.count or 1 --
local metadata = v.metadata or {} In testing this inventory allowed it on owned vehicle but not unowned vehicles,
quasar:AddToTrunk(identifier, nil, nil, v.item, count, metadata, nil) 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 end
return true return true
--]]
end end
---This will clear the specified inventory, will always return true unless a value isnt passed correctly. ---This will clear the specified inventory, will always return true unless a value isnt passed correctly.
@@ -50,8 +57,13 @@ end
---@return boolean ---@return boolean
Inventory.ClearStash = function(id, _type) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end if type(id) ~= "string" then return false end
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
return false
--[[
quasar:ClearOtherInventory(_type, id) quasar:ClearOtherInventory(_type, id)
return true return true
--]]
end end
---This will return a table with the item info, {name, label, stack, weight, description, image} ---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) Inventory.ClearStash = function(id, _type)
if type(id) ~= "string" then return false end if type(id) ~= "string" then return false end
tgiann:DeleteInventory(_type, id) tgiann:DeleteInventory(_type, id)
if Inventory.Stashes[id] then Inventory.Stashes[id] = nil end
return true return true
end end