Best way to code a class-based MOBA weapon system?

Hi, and thanks for reading in advance.

I’m making a little class-based MOBA where the main draw is that players are able to rapidly upgrade their equipment over the course of a round. Each weapon has a unique passive and set of abilities that offer an alternative playstyle to the class - sort of like TF2.

I’m trying to think of the most efficient way to structure and program this so as to save time when I begin making the other classes. Currently, my plan is dense and simple: I use folders for individual weapons that contain the weapon’s client and server code and any relevant dynamic information like cooldowns or stamina costs, and simply delete the player’s current weapon folder and exchange it for a new one when they need to swap.

I know temporary scripts should be avoided and this is likely bad practice, but I’m not sure what I should be doing. I thought of creating a central, main client and server code and simply executing the weapon’s unique code from modules instead - perhaps that would serve better? Does it even matter?

I personally would go for a modular approach, registering each module with a slug (identifier), such that WeaponModules[ 'sword' ] would probably hold a reference to my sword module for example.

When a player selects a new weapon, I would let the server know so the server can make any required changes, such as swapping the physical parts, and then I’d have common methods in each weapon. For example Weapon:Attack could be a function that you call upon left mouse click,

-- Left mouse click handler
WeaponModules[ currentWeapon ]:Attack( currentTarget )

That’s the kind of route I’d go down, but I tend to think in OOP modules and see everything as an object. There’s no definitive right or wrong in programming as long as it’s secure and works properly.

1 Like

In the game I’m working on, I’ve taken an approach similar to BanTech’s. To create a weapon, there is a class that I instantiate, and one of its fields is the weapon (in my case, I’m using Model instances, but I suppose Tool instances work just as well), and this is done on the server.

To support client functionality, there is a module script in the weapon model called Instance.

You might want to look into using Aero Game Framework. It’s a framework I would recommend to any developer on Roblox.