I realize that the problem I ran into is probably rather unique, but I still think it might be worth talking about. In the process of creating a new script I ended up with a new item that I wanted to be able to have different names. Like, thousands of different names (I probably went a little overboard in this script but it works). With that I didn't want to have to add thousands of different items because really these are all the same item, just with a different display name. Currently this isn't possible in qb-inventory.
My main use case for this was a drug script I wrote where weed has many different strains, but all strains should be treated the same way.
Ideal solution
My proposed solution is to make a few changes to qb-inventory/server/main.lua in order to display a single "item" as multiple different items in the player's inventory. I am willing to put out a PR for these changes myself, but I wanted to add the suggestion to get thoughts before doing so. The changes are as follows:
Change all locations where label and description are set to first check for info.label and info.description respectively
label = item.info?.label or itemInfo['label'],
description = item.info?.description or itemInfo['description'] or '',
Add new exported function to allow the ability to get the first slot of an item from the inventory by info.label
local function GetFirstSlotByItemForLabel(items, itemName, label)
if not items then return nil end
for slot, item in pairs(items) do
if item.name:lower() == itemName:lower() and item.label:lower() == label:lower() then
return tonumber(slot)
end
end
return nil
end
exports("GetFirstSlotByItemForLabel", GetFirstSlotByItemForLabel)
Update the AddItem function to use this new exported function above to get the slot number as to not combine items of the same type, but with different info.label values
Orignal
amount = tonumber(amount) or 1
slot = tonumber(slot) or GetFirstSlotByItem(Player.PlayerData.items, item)
info = info or {}
New
amount = tonumber(amount) or 1
slot = tonumber(slot) or GetFirstSlotByItem(Player.PlayerData.items, item)
if info ~= nil and info.label ~= nil then
slot = GetFirstSlotByItemForLabel(Player.PlayerData.items, item, info.label)
end
info = info or {}
These changes should prevent, or at least drastically reduce, the chances of breaking existing expected functionality, while expanding on the functionality to allow for the same item type to be displayed differently in the UI, without each variation requiring a new item entirely.
The problem
I realize that the problem I ran into is probably rather unique, but I still think it might be worth talking about. In the process of creating a new script I ended up with a new item that I wanted to be able to have different names. Like, thousands of different names (I probably went a little overboard in this script but it works). With that I didn't want to have to add thousands of different items because really these are all the same item, just with a different display name. Currently this isn't possible in qb-inventory.
My main use case for this was a drug script I wrote where weed has many different strains, but all strains should be treated the same way.
Ideal solution
My proposed solution is to make a few changes to qb-inventory/server/main.lua in order to display a single "item" as multiple different items in the player's inventory. I am willing to put out a PR for these changes myself, but I wanted to add the suggestion to get thoughts before doing so. The changes are as follows:
Change all locations where
label
anddescription
are set to first check forinfo.label
andinfo.description
respectivelyAdd new exported function to allow the ability to get the first slot of an item from the inventory by info.label
Update the
AddItem
function to use this new exported function above to get the slot number as to not combine items of the same type, but with different info.label valuesslot = tonumber(slot) or GetFirstSlotByItem(Player.PlayerData.items, item) if info ~= nil and info.label ~= nil then slot = GetFirstSlotByItemForLabel(Player.PlayerData.items, item, info.label) end
info = info or {}
These changes should prevent, or at least drastically reduce, the chances of breaking existing expected functionality, while expanding on the functionality to allow for the same item type to be displayed differently in the UI, without each variation requiring a new item entirely.
Alternative solutions
No response
Additional context
No response