How should I go about doing this?

I’m making different classes of weapons for my game, one of the ones I’ve already created are Bombs. All of these bombs have different qualities, qualities include:

  • Damage
  • Cooldowns
  • Bomb-Exclusives

An example of Bomb-Exclusives is the Cluster Bomb, as opposed to the Classic Bomb, after the cluster bomb explodes it leaves a volley of smaller bombs that explode.

The current system has all of the code for each bomb inside of each script, so even though the system for each bomb script follows mostly the same structure, they all vary in terms of what they do.

I’m wondering how to implement this into OOP form, because every time I fix an error in one bomb that has the same written structure as the other bombs, I have to go through every single bomb just to fix the code. Instead of this, I want to just have one module manage every bomb while keeping each bomb’s exclusive parts.

An example of this would be:

Classic Bomb: Player Activated Bomb → Server Event → OOP Bomb Module → Explodes → Deals Damage → Starts Cooldown →

Cluster Bomb: Player Activated Bomb → Server Event → OOP Bomb Module → Explodes → Deals Damage → ||(THE SECTION SPECIFIC TO THE CLUSTER BOMB) Starts Cooldown → Spawns Mini Bombs → Explodes → Deals Damage || →

So how should I go about doing this?

4 Likes
  • You can achieve this by creating inherited classes, you can create a base bomb class and other bomb types as different classes that inherit from the base class. That way the base class can handle the basic explosion and the other class types can have different customizations.

Note: I’m not that good at OOP so this might not be the best method to do this


You can check these links:

3 Likes

So do you think it would be optimal for me to structure it like this?

local bomb = {}
bomb.bombType = nil

function bombType2()

end

bomb.Explode = function(tickTime, damage)
     -- boom!!!

     if bomb.Type == "Type2" then bombType2()
end

return bomb
1 Like

still haven’t found a solution for this…

1 Like