Which is better 1 script in every weapon, or 1 main script?

Hello, I would like to know if it’s better to have 1 script in every weapon, or a modular system to do that in one script. (I am making a game with bunch of weapons.) If you have an idea of how this system could be made well please leave a reply that would help a lot!!

It’s almost always better to use one main script for your system and split things up into modules.

4 Likes

Ok, thanks for the reply I didn’t know if I should’ve done that or not. But what would the system look like?

1 Like

It’s entirely up to you how you organize your code, but here are some tips:

  • You’ll need some sort of system to detect what type of tools are entering the player’s backpack and set them up accordingly. Attributes are a good way to do this.
  • I personally find that an object-oriented approach is good for tool systems because it makes organization a lot easier
1 Like

What do you mean by object oriented? Do you mean that each item would have like some module for it’s stats?

1 Like

Use a module for the weapon system then a script will assign each weapon in a folder that code, or clone a script into the weapons so you don’t have to do it manually

1 Like

Ooh. That would be smart cloning a script.

1 Like

Depends on your preferred type of organization.

One type of organising is by having multiple modules for different big parts of each gun, like for one module, it will have the actions for the guns, like, :Fire() with multiple parameters/presets; such as the bullet type, bullet speed, bullet range, etc, etc.

Then, just have one script go into the modules folder, and get the folder of all the guns, and just have a script go through all of them linking them.
Also, tables will help alot.

Depends if each of your guns require their own features/code.

1 Like

I am aiming for a system that is easily expandable incase I want to add a new weapon or something.

1 Like

You could have the main script connect to the module, and the folder of all the guns, and whenever you add another gun, you can just go in and add a new dictionary/table/array of the gun, with it’s preferred presets/parameters, such as bullet type, bullet speed, animation for reload, etc.

The script will handle the rest.

1 Like
  • Without having to clone a script, put that script into the gun, and edit the entire code.
1 Like

That would be really cool having a system that would put presets on automatic weapons, melee, semi auto and more. Or maybe something very far-fetched would be an artificial intelligence that learns what damage or something.

1 Like

1 script in every weapon is extremely inefficient. Because if u have alot of weapon its just gonna be duplicate scripts. What I do is that i make a module that has functions for the weapon and in every weapon u just require that module and send parameters using a constructor function.

1 Like

I don’t know which is a more correct solution.

1 Like

It is possible to do presets, you can use tables with pre sets in there, which you can load like; :Fire(module.preset.Rocket), etc.

Although it’s possible to create your own AI to detect which damage to set, like if a bullet hit a certain spot, a certain part, etc.

1 Like

If someone here made a detailed response with the best approach, I would consider that the solution.

1 Like

Don’t bribe people for a solution tick

1 Like

you could do both

(char limit)

1 Like

Sorry, I was just trying to be funny lol. I would never ask someone for a full solution maybe just a suggestion.

1 Like

TL;DR:

^ is the best approach here.

1 Like