Say I have an item ID module where each item I make is added and assigned an ID. One of these items could be “Iron sword” and I want each copy of the iron sword to have its own data, for example, having a Level 1 Iron sword, and a second Level 5 Iron sword, while sharing the same item ID with every other iron sword.
What’s the best way to go about doing this?
I have come up with two solutions, but would prefer if there was a better way:
Make a new item ID for every level of the item
Make the data for the item ID for each weapon equal to a table. Fill the table with a new “sub ID” for every copy of the weapon you own. However this makes the weapon hard to reference because it exists in the datastore rather than a module.
Not sure If I understood you correctly, correct me if that’s the case.
You can differentiate each item by it’s level, unless you have more than one item that it’s the same level, if that’s the case, just increase a quantity for the same item, like
local Inventory = {
["Iron Sword"] = {
Level = 1,
Id = 213123,
Quantity = 3
},
["Iron Sword"] = {
Level = 5,
Id = 213123,
Quantity = 1
}
}
local sword1
local sword2
for _, item in pairs(Inventory) do
if item.Level >= 5 then
sword2 = item
else
sword1 = item
end
end
print("Iron Sword Lvl 1", sword1)
print("Iron Sword Lvl 5", sword2)
Well the way I’ve done it is quite similar. Let’s say the id for the weapon is 14, and in my inventory datastore it looks something like
Items = {
[14] = {}
}
Then when you pick up an item it adds it to to the datastore
local wepcount = (data.Items[ID])
local wepstats = {
Rank = 0,
Level = 0,
Color = 0,
Experience = 0,
}
table.insert(data.Items[ID], #wepcount+1, wepstats)
But we run into the same problem, it’s stored in the datastore and not fixed in a module, making it hard to reference a specific sub-item of this ID, especially when it is so dynamic and can be removed/added/changed at any time, not to mention anything funky that happens with the datastore itself because of the method used to store it. I am hoping to find a way that is both easy to reference and highly variable.
(you can also automatize this proccess of multiplication)
local function getItem(Name, Lvl) -- or ID instead of name
-- get base item wherever it is from
local item = ItensToolsFolder[Name]:Cone()
-- change its properties acording to the lvl and multiplier
item.AtkSpeed.Value = ItensTable[Name][atkSpeed] + (ItensTable[Name][atkSpeed] * (ItensTable[Name][atkSpeedMultiplier] * (Lvl - 1) ))
return item
end
Just to clarify I am not asking how to accomplish the methods I have already listed, as that is the easy part. I am looking to find a better way of doing things - either by making it more variable in the case of a different ID for each level, or by making it more easily accessible in the case of instantiated IDs in a table OR a new way entirely.