Modular stackable item system help

Hey! My first post on the devforums.
I am having some trouble understanding how to add stackable passive items. Basically items from ROR2(risk of rain 2) if you know that game. There are passive items that you can collect which give you stats or certain effects, and their effects stack if you pickup multiple of them.
EX:

Bloxy Cola - increase attack speed (by 15% for each stack)
(you have 5 colas, so it increases by 75%)
Explosion Catalyst - explode hit enemies for 10 damage with a radius of 50% (+50% radius for each stack)
(here only the radius increases with each stack)

My issue is just understanding how to implement this kind of system, i thought of using tables, but after experimenting for a bit its still kind of unclear. I want it to be as modular as i can make it to be.

Have a module that is responsible for the inventory, then have a method which ads any item that you pick up into your inventory

Have some sort of other table or use attributes for the item which dictates what buff the item gives so an example

local Table = {
  ['Bloxy Cola'] = {Buff = "Strength",  Amount = 3}; -- 3 is our 30% in short
}

On pickup then search through the table if they find the item and then apply the appropriate perk like the following:

local FoundItem = table.find(ItemTable, ToolYouPickedUp.Name)
if FoundItem then
      if FoundItem["Buff"] == "Strength" then
            --Run code that would apply extra strength to the player like following
            local Strength = Player.Stats.Strength.Value
            local NewStrength = Strength  +  ((Strength / 10)  * FoundItem['Amount'])
            Player.Stats.Strength.Value = NewStrength
      end
end
1 Like

Thanks for the quick answer! I’ll try that out!