Hello, just keep in mind im new to OOP so no judge my code haha.
HOW MY SCRIPT WORKS
How my scripts works is that everytime a player join, it creates an player object and it contains the playerdata and the functions we have for the player we can call like PlayerObject:GiveItem(id)
so basically the player data usually goes like this
['Inventory'] = {
['1'] = {
['quantity'] = 15,
['object'] = nil,
},
['2'] = {
['quantity'] = 15,
['object'] = nil,
}
}
}
So basically the number represent the ItemID (its string because i learn that you should make data type string instead of int if you’re not doing math with it), and it have quantity and item object, which we can assign to so we can use the item function like ItemObject:Use() by calling it in player inventory like
PlayerObject.data['Inventory'][tostring(itemid)]['object']:Use()
MAIN PROBLEM
So i wanted to have a system like in minecraft dungeons where item are the same but they have different level and stats, for example, We have rare sword, dropped by a monster, and the sword is not stackable (i still dont know how to make item unstackable from my skript) and the sword that is dropped have different damage but is still the same item, for example a sword that have damage range of 500-600 when drop, it still the same item, same item id but different because of their stats
but because they have same id, (which is the key we do for player inventory) , but different value, it simply not possible to make it like this
['Inventory'] = {
['15'] = { --sword id
['quantity'] = 1;
['object'] = itemobject,--this where we store the item stats like damage
},
['15'] = { -- sword id
['quantity'] = 1;
['object'] = itemobject, --this where we store the item stats like damage
}
}
because well duplicate key are simply not possible
SOLUTION I TRIED
I dont know how to make generate a number that wont EVER duplicate so that every item differs from each other and my other skript already relies on the item id being the key value of the player inventory, i could do
['Inventory'] = {
['1:1'] = { --[itemid:ownkey], seperate the itemid and its own key
['quantity'] = 1,
['object'] = nil,
},
['1:2'] = { --[itemid:ownkey], now this have same id but different key
['quantity'] = 1,
['object'] = nil,
}
}
i could do tick() for its own key seperated by item id but what if 2 same item drop at the same time?
Any help, suggestion and guidance is appreciated.
Thanks you so much for your time.