More practical way to group on-map enemies?

I'm using on-map encounters in my game project, but instead of each enemy event sending the player into a battle with multiple enemies I would prefer a system in which the number of enemy events on the map is the same as the number of enemies (not troops) the player actually fights. I have found a way that works, but I can see it becoming rather impractical for a larger project.


For example:


There are two bats on the map. If the player touches a bat, they are sent into a battle against two bats. After the battle, both bats are gone from the map.


Of course, this can easily be accomplished by using a switch to turn the bat events "off" like this, with an empty second page and the condition: Switch #0021 Bats defeated:


On-map_encounters.png


(Sorry about the German interface, haven't had time to ty and switch it to English yet.)


But with this system I would need a switch for every single battle in my game. Not a problem in a smaller project, but I'd rather avoid having to set aside 100 or so switches just for regular battles in my hypothetical 40 hour epic 😉  


Is there another way of doing this? Something like Shared Self Switches would be great, but I doubt that exists. Or I'm simply blind.


Anyway, I've been thinking about this for a while without finding a solution, so I thought I ask for help here. Thanks in advance!
You can 'remote control' Self-Switches, and so have one Event turn off its own Self Switch, but also another (one, or two, three or more...). Using the Script call...


To set an event's Self Switch...
$gameSelfSwitches.setValue([mapId, eventId, switchLetter],value)
Ex: $gameSelfSwitches.setValue([1, 3, 'A'], false)



I've Script for turning off numerous Self Switches which can be useful; maybe too much for your needs here, though...


// The id's of all events you want to check


var eventsToCheck = [55,71,72,73,74,75,76,77,78,79,80,81,82,83,84,105,107];


// The map Id the events are located


var mapId = 58;


// Just storing the length of the array in a variable


var eventsLength = eventsToCheck.length;


// Iterate through the eventId's and turn off self switch A


for(var i = 0; i < eventsLength; i++){


$gameSelfSwitches.setValue([mapId, eventsToCheck, 'A'], false);


}


 


This would avoid having lots of Switches if there are lots of Events, but would need careful management just the same. It's possible; is it worth it..? What's wrong with having lots of Switches, if that's what the Game needs..?
This reminds me of Earthbound. When a battle start, it is against the enemy you touched, but there is a couple seconds a second enemy can join the battle.


Sadly, no idea how to do it...


Anyway, if you use switches, normal or self, don't forget to turn them back on when you enter the map again, else you'll have a limited number of enemies...
@Dad3353 Thanks a lot, that's what I was looking for! I'm not sure either whether I'll use this method or not, but it's good to have a different option. As for why I don't want a lot of switches ... I don't really know, guess I'm just afraid I don't plan enough space for battle switches and end up with loads of unorganized stuff (like in all the projects I've started so far ... really need to pay more attention to things like that)


@Waterguy Funny that you mention it, Earthbound is where I got the idea from! (Without the "enemy runs up to the player"-part, although I guess that could rather easily be done via move routes?) And yes, I currently have a system in place where the player can choose whether the enemies should respawn upon re-entering the map. Actually, I'm wondering if I should do a tutorial on that. It's really simple, but I haven't seen that in the "how to on-map encounters" tutorials so far.

Original thread: https://forums.rpgmakerweb.com/threads/more-practical-way-to-group-on-map-enemies.68826/