This is actually a very good question because games like the Diablo series from Blizzard-Activision do this. The only way this would work is if you make it so players cannot drop items because if they do, it would destroy the item. So in your basic weapon definition you would define a range of random values for a stat. You would ID this item only. Then when the player acquires the weapon, soul bind it so it cannot be traded. It can only be sold to a vendor or destroyed. Then within the player’s inventory, you would set a table which contains the actual values. Something like what @ew_iscool said. So something like this:
local function immolatePlayer(player: Player, target: Player, itemId: number, params: {})
-- Code to light the target player on fire.
end
-- Enumerations
local enums = {
-- Enumeration: Item Quality
ItemQuality = {
Poor = 0; -- Grey
Common = 1; -- White
Uncommon = 2; -- Green
Rare = 3; -- Blue
Epic = 4; -- Purple
Legendary = 5; -- Orange
Artifact = 6; -- Yellow
Moderator = 7 -- Red
Developer = 8; -- Cyan
Variable = 9; -- Based on item qualities above.
};
-- Enumeration: Item Type
ItemType = {
Melee = 100;
Range = 102;
Thrown = 103;
Shield = 104;
Head = 200;
Neck = 201;
Shoulder = 202;
Chest = 203;
Arm = 204;
Wrist = 205;
Finger = 206;
Leg = 207;
Feet = 208;
Back = 209;
Material = 300;
Vanity = 400;
Offhand = 500;
Other = 600;
};
}
-- Abilities Database
local abilityDatabase = {
[#4B03003A] = {
text = "Chance on hit: Sets the player on fire for %duration seconds dealing %damage fire damage."
handler = immolatePlayer;
};
}
-- Global Item Database
local itemDatabase = {
[#0278F223] = {
name = "Sword of Immolation";
image = "rbxassetid://";
mesh = "rbxassetid://";
itemPath = "game.ServerStorage.Items.Weapons.Melee.SwordOfImmolation-0278F223"
itemQuality = enums.itemQuality.Variable;
variableQualityStats = {
-- Common Quality
[enums.ItemQuality.Common] = {
damage = Vector2.new(9, 15); -- Base weapon damage range (before modifiers)
durability = Vector2.new(30, 30); -- Current/Max weapon durability (0 = broken)
vendorValue = 25;
stats = {
stamina = Vector2.new(3, 7); -- Random stamina value.
strength = Vector2.new(3, 7); -- Random strength value.
agility = 5;
intelligence = 0;
spirit = 3;
};
specialAbilities = {
[#4B03003A] = {
parameters = {
chance = 5;
duration = 10;
damage = 10;
tick = 2;
cooldown = 15;
timestamp = 0; -- Unix timestamp (tick) of last activation time.
};
};
};
};
-- Rare Quality
[enums.ItemQuality.Common] = {
damage = Vector2.new(25, 37); -- Base weapon damage range (before modifiers)
durability = Vector2.new(90, 90); -- Current/Max weapon durability (0 = broken)
vendorValue = 175;
stats = {
stamina = 15
strength = 15;
agility = 15;
intelligence = 3;
spirit = 8;
};
specialAbilities = {
[#4B03003A] = {
parameters = {
chance = 25;
duration = 15;
damage = 25;
tick = 2;
cooldown = 25;
};
}
};
};
};
};
}
-- On a per player/instance basis
local inventory = {
[#00278F223] = {
quality = enums.ItemQuality.Rare;
durability = 90
stats = {}; -- Overrides default stats
ability = {
[#4B03003A] = {
timestamp = 0; -- Unix timestamp (tick) of last activation time.
};
};
];
}
This is how I would do it. Stamina relates to how much HP the player has. So the player would have something like 5HP for each point of stamina. Strength is how hard a player hits in melee, how much a player blocks with a shield, and parry chance. Agility is how hard a player hits with ranged weapons (think bows and thrown weapons), and dodge chance. Intelligence dictates how hard a player hits with spells and how much mana a player has (depending on class). Spirit is how fast HP and mana regenerates. Mana is a resource for spell caster classes (mage, wizard, sorcerer, enchanter, warlock, etc…), but other classes can have other resources like rage (warrior), or focus (ranger/hunter). Of course, this comes from an insanely popular MMORPG known as World of Warcraft.
The way that this works is that you create an enumeration for the weapon quality. Then in the main item database, for each quality level of the item, you have various stats. I’ve included the possibility of unique item abilities in an ability database which contains the text of what the ability does and what the handler function for the ability is. This can allow for some pretty unique things. Parameters are unique for each ability.
You can make this as simple or as complicated as you want. But to answer your question, the basic idea is presented. If you plan to have a lot of different items, I would place them in the data store so you can access them by Id globally in your game. The unique part of the item would be stored on a per-player basis. It would still reference the item database to get other things, but your code would modify the stats based on weapon quality and any unique randomized stats. So in the example above, strength and stamina are random. So in the per-player data under stats, you would specify the strength and stamina values. Those would be used for the calculations and would also be displayed to the player.
Hope this helps.