Hi all,
I’m developing a medieval-style fighting game that allocates some NPCs to both sides (think Mount & Blade). I’ve run into some performance issues that I’ve been trying to resolve (i.e., lots of lag with more than a few dozen NPCs fielded at once). One thing I’ve considered doing is condensing all of the scripts for the NPCs, of which there is one for each, into one master script, and from what I have read on here it seems that to do so would improve performance. My issue, though, is that I want these NPCs to behave somewhat dynamically. For example, if their target is about to attack them, instead of, say, following through with their own attack, they move to block instead. This is less critical with NPC vs. NPC combat but very important for NPC vs. player combat, as I want NPCs to be at least a bit of a threat to players, and if they don’t respond to player actions at all, they might as well not even be there in the first place.
For this reason, I feel like it would be quite difficult to govern all of that behavior from inside one single script. I don’t have much scripting experience as of yet, but my crude plan would be to constantly loop through each NPC in the game, check what their situation is, and give them some kind of an instruction based on that, but I am a) not sure that this would work properly and b) not entirely convinced that this would vastly improve performance.
I was just hoping for some general tips on the matter, since, as I have said, I don’t have much experience with scripting yet.