Make multiple types of guns with different stats

Hello guys, I want to have multiple guns in my game with different stats. my question is how should I set it up? do I make a new class derived from gun that hosts all of the guns stats for each gun, or is there some better way to do this?

Well, that’s OOP concept really.

What you should do is, create a MasterWeapon class. Put all your weapon configuration variables in it (or what I did: created a WeaponConfig UStruct and set it as a single variable in the MasterWeapon). Then when you want to make a new gun, just inherit MasterWeapon, set it’s stats and you are pretty much done.

Though what I did was extend it even more.

MasterItem -> MasterWeapon-> Pistol || AR || SG || MG || SMG etc -> MyFirstWeapon || MySecondWeapon etc etc etc

That way, I have all the functionality for item pickup in MasterItem, all the functionality for shooting and weapon config (dmg, recoil, reload time, handling, ammo etc) in MasterWeapon, then I filter them to add Single Fire or automatic or etc and then finally just have instances of them in separate objects. That way you will comply the SR (Single Responsibility) principle.

Best regards,

Another option is to look in to something like -

Most guns, certainly within a particular category (pistol, rifle etc) can be defined/differentiated purely by their stats (magazine size, rate of fire, damage etc). So rather than creating a child class for each specific gun, you can just load the data for each one from Excel (or JSON file etc) and set all the stats within an instance of your main “Gun” class. Even things like the mesh to display and sound FX can be defined this way.

Yes, tho that will be quite harder to maintain at runtime. For example if you wanted to limit someone to use only pistols, you would have to predefine a lot of parameters. Otherwise, you can just make a pointer to Pistol class. And cast it to Pistol.

The above method will surely work. It all depends on what you are trying to implement.

The quesiton is: Does your weapon system look more like Borderlands, or more like DOOM?

If like DOOM, then a single actor class per weapon type is fine. You can subclass from a Weapon that subclasses from Actor, or you can just create direct Actor subclasses for each (perhaps with an interface if you want to treat “weapons” specially)

If like Borderlands, you absolutely need the Excel-like approach.

is there some way I can read the file off of a dedicated server instead of the clients machine?