Help with event encounters system

So, I thought I had this all figured out, but having trouble with something...

Currently, I have each event set to erase / exit event processing if you win the battle and just stay on the map if you escape.   This works great because I wanted the dungeon to reset after the player left, to prevent Inn Abuse, to allow players to go back to re-do low-level dungeons later on in the game for the fun of it, etc..   So far, so good.

Here's my problem though.  I noticed that even if a player walks to the 2nd floor of the dungeon, when he goes back up the stairs to the 1st floor, all of the enemies have respawned.  Part of why I went with evented encounters instead of random encounters was to avoid this very issue:  my game has only a very limited touch of surrealism, so I don't want to use the "give the player a magic portal to take the party back to town" after every dungeon; I want players to have to walk back out of the dungeon the good old fashioned way, I just don't want them to have to re-clear all of the low-level monsters on the way out. 

Obviously, one way I could deal with this problem would be to give a switch for every single encounter in the game...but that seems way too much work and a poor way to do it.  Any other ideas?  I feel there's some super obvious way to handle this, but I'm unable to see it.

Thanks in advance.
Instead of using "erase event" use self-switches. this will erase them forever, and you don't have to make a switch for every encounter in the game

If you have multiples, just copy and paste

erase event's purpose is so events will respawn when the map is reentered
Thanks - I thought of that, but I want the player to be able to go back to this dungeon after they leave and have the events respawn.

Is there a way to make the encounters not respawn until after the player has exited the dungeon?
The simplest way is to set each of them to self switch A after they've been defeated, then reset the self switches once the player exits the dungeon. Since they're walking, just have the exit event reset the self switches for the whole dungeon.

Just use the following script call to reset the self switches to false. replace map_id with the ID of the map, and event_id with the ID of the event.

$game_self_switches[[map_id, event_id, 'A']] = false

You'll have to set the self switch and the new page for each event, but at least for the resetting portion it's all in the exit event.
Oh, that works perfectly! THANK YOU!
Alternatively, have the battle throw a general switch e.g. Dungeon #3 fights to ON.  That switch conditions the second page with nothing on it.  The exit event turns that switch OFF.  Then you don't have to mess around finding all the map ids and each individjual event id, which is a lengthy process.  30 seconds does it.
Yeah I just realized it's still a lot of work to set every event's self-switch off.

With that general battle switch, I still have to make a switch for every event right?  Meh, there has to be an easier way...

Is there a way to say in a single line, "set the self-switch on map X, of any event GREATER THAN Y, to off" ?

-EDIT- ok wait, just thought of something...Isn't there a way on the 2nd page of all the events, to put some conditional that will set the self-switch to OFF when the player has exited the dungeon?   going to experiment with this...
Again, the hardest part is just to put in the self switch and the second page. You can always copy and paste the pages between events, so it should be that much easier.

As for looking up each ID, a very easy way is to go into any event and open up the "Set Move Route" command. The dropdown lists all of the events with their IDs. Now, if you haven't been naming any of your events, this will be useless. If you have been naming them, then you've got a full list of all the events in the map and you can just jot them down in notepad and paste those script calls into the exit dungeon event.

There are faster ways, such as making sure all the monster events are in order event-ID wise and using a loop to go through them and setting their self switches off, but that would mean you had this planned from the beginning.

It's nice to find a perfect system, but oftentimes optimizing a system takes longer than doing it the simple way. I suggest just biting the bullet and doing it this way (unless someone has a much faster way).
You could use script that can reset all map event selfswitch. But I forgot where I've seen that script. And since I'm not in my laptop with ace I cannot script it my own.
Ah, I'll search for it.  Until then, I've found the easiest way is to just make a regular switch for each encounter, and then set these switches to off when leaving the dungeon (since it's easy to select a 'batch' or range of regular switches).  I don't really follow how to make the self-switches script easy...I don't normally name my events, but even if I did, it's tedious and discouraging to think i'd have to add a line of code for every encounter. 
Yeah I just realized it's still a lot of work to set every event's self-switch off.

...

Is there a way to say in a single line, "set the self-switch on map X, of any event GREATER THAN Y, to off" ?
Yeah.  Just run a loop.

for i in 28..56$game_self_switches[[7, i, 'A']] = falseendThat will set Self Switch A OFF for every event between (and including) 28 and 56 on Map #7.

And if you don't have them neatly organized you can use:

for i in [28, 32, 36, 51, 55, 56]$game_self_switches[[7, i, 'A']] = falseendThat will set Self Switch A OFF for those six events on Map #7.
beautiful stuff...thank you!
I've moved this thread to VX Ace Support. Please be sure to post your threads in the correct forum next time. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-event-encounters-system.37871/