[SOVLED] Turn off (reset) ALL Self Switches??

I know this question probably hasn't been asked this specifically, but similar topics exist. I was PMd this thread topic to help solve my issue; however, it was someone else's work and I don't know what all they have in their plugin. ((Great idea though, but it would imply I would have to keep updating it with MapIDs everytime I add a new one, and I was hoping someone could tell me in how to set all Self Switches "A, B, C, D" off for all events on ALL maps.
Thread that was PM'd: 





===================================================


I was inspired by Yoji Ojima's OuterSelfSwitch plugin, and since I'm still new at scripting I decided to try to reverse engineer it for my needs. The problem I think I'm having ((Unless someone can point out an better way to do this)): is getting the array of all the map IDs :\  I will of course include the whole plugin here for anyone to glance over and point out my errors. And to those who can help me, you have my pre-emptive appreciation <3 ^_^ 

 

Spoiler
Code:
//=============================================================================
// Reset All Self Switches by LordValinar (aka the DarkSorcerer)
// darkResetSelfSwitches.js
// Version: 1.0
// Free for all commercial and non-commercial games
//=============================================================================
/*:
 * @plugindesc Resets all self switches on all maps good for games 
 * that use maps for title screens.
 * @author LordValinar (aka the DarkSorcerer)
 *
 * @help
 * On the Title Screen (map) onLoad event (when you first come to
 * the map, you usually have an event that clears all other data
 * ... or well you should. You'll want to place a plugin command: 
 *
 * darkReset all
 *
 * This resets all event's Self Switches on all maps so when you go
 * back to the Title Screen (map), it'll reset all those map events
 * that you had self switches for (maybe for cutscenes you want to
 * reset, or other area load in effects (weather/tint/etc)
 *
 * INSTRUCTIONS:
 *
 * 1.) If using a map for a title screen, ensure you have an event
 *     that does all your setup (pictures, variables, switches,
 *     clearing of any other unneeded data, etc).
 * 
 * 2.) on your "New Game" select (however you have it.. like mine
 *     I have an event where the player is placed or transferred
 *     to. Since they can't move anywhere they can either touch
 *     player height events (which changes options), or press
 *     ENTER/OK for whatever option they selected) -
 *     -- On your New Game option run the plugin: "darkReset all"
 *
 * 3.) And that's it. Now when a player starts a new game, either
 *     for the first time, or from returning to the title screen
 *     to a new game, all self switches will be reset.
 *
 * This plugin was created with the help of reverse engineering of
 * Yoji Ojima's "OuterSelfSwitch.js" plugin. So I want to thank
 * him of course :) Even if it seems simple to other people, I'm
 * still learning
 *
 * Alternatively you can still use much of Ojima's original
 * functionality:
 * 
 * darkReset on 1 A      #turns on A self switch for event 1
 * darkReset off 5 B     #turns off B self switch for event 5
 * darkReset off all B   #turns off B self switch for all events
 *                       for the current map only
 *
 * (Coming Soon!)
 * -------------WIP---------------
 * You may want to turn on/off multple self switches for 
 * multiple events!
 *
 * darkReset on 1,2 B    #turns on B self switch for events 1 & 2
 * darkReset off 1,2 B,C #turns off B and C selfSwitch for events 
 *                       1 and 2!
 * -------------WIP---------------
 * 
 * NOTE: if the 1st parameter is "all" it doesn't matter what you
 * have after it. It will function as the primary command of this
 * plugin intended to do - turn off all events in all maps!
*/
//=============================================================================
Imported = Imported || {};
var LordValinar = LordValinar || {};

(function () {  
	
	var lordV_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        lordV_pluginCommand.call(this, command, args);
        if (command === 'darkReset') {
            var operand = args[0];
            if (operand === 'on' || operand === 'off') {
                var eventId = args[1];
                var switches = String(args[2]).split(',');
                var trueFalse = (operand === 'on');	
				for (var i=0; i < switches.length; i++;) {
					var selfSwitch = switches[i];
					setSelfSwitch(this._mapId, eventId, selfSwitch, trueFalse);
				}
			}
			if (operand === 'all') {				
				for (var i=1; i <= $gameMap.mapId.length; i++) { // What is proper call for all MapIDs?
					resetAllSelfSwitches(i, switches);
				}
			}
        }
    };
	
	function setSelfSwitch(mapId, eventId, selfSwitch, trueFalse) {        
		if (selfSwitch.match(/^[A-D]$/)) {
            if (eventId === 'all') {
                for (var i=1; i <= $dataMap.events.length; i++) {
                    setSelfSwitch(mapId, i, selfSwitch, trueFalse);
                }
            } else {
                var eID = Number(eventId);
                if (eID > 0) {
                    var key = [mapId, eID, selfSwitch];
                    $gameSelfSwitches.setValue(key, trueFalse);
                }
            }
        }
    }

	function resetAllSelfSwitches(mapId, switches) {		
        for (var i=1; i <= $dataMap.events.length; i++) {  
			for (var j=0; j < switches.length; j++) {
				var selfSwitch = switches[j];
				var key = [mapId, i, selfSwitch];
				$gameSelfSwitches.setValue(key, false);
			}
        }
    }
	
})(LordValinar);
Imported["ResetAllSelfSwitches"] = 1.0;
Code:
$gameSelfSwitches.clear();
$gameSelfSwitches.clear();



Oh well now I feel like an idiot for something so simple LMAO ... Thanks 🙂
Thank you very much for this code. Does it also work on MZ?

Original thread: https://forums.rpgmakerweb.com/threads/sovled-turn-off-reset-all-self-switches.57773/