I don’t know if this is the right category or not, but I’m currently making an NPC system, they can attack the player and all that good stuff. Now I have already made a fully functional combat system for the player, I’m wondering if I can re-use it for the NPC, since all of my code is modular and OOP based, I don’t think it should be too hard to implement. The real question is if it’s performant or not, I have like 5 modules regarding the combat system and it’s all OOP based, I don’t know how well it will handle if I have like 10-20 active NPCs at once. So, is it ideal for me to require all the modules and apply it in the NPCs, or am I better off creating a separate combat system for my NPC (so I don’t have to handle all the remote events and calling RunService to check if the script is client-based or not to fire them, horrendous process).
Any help is appreciated
In this scenario I recommend that you put them all in a file and use something like this.
(This script changes the parts colors)
Script:
for _ ,NPC in ipairs(workspace.NPCS:GetChildren()) do
local NPCconfig = require(game.ReplicatedStorage.ModuleScript)
NPCconfig.NPC(NPC)
end
Module Script:
local module = {
NPC = function(part)
part.BrickColor = BrickColor.new("Really red")
end
}
return module
This is just a color changing basic example of an easy version of implementing your NPCS! I hope this helped!
1 Like
I have experimented with re-using the modules of the player for the NPCs, did a bit of modification to the modules, turned out better than I thought.
That’s with 1 NPC and at its’ peak, not so bad. But when I tested it out with 10-15 NPCs, it started ramping up to 5%, until they all died obviously. Keep in mind this is only a simple punching implemented in, I haven’t applied the blocking / other states in yet.
Any thought on this ?