Selfswitches from ON to OFF on selected maps

Hello, can anyone help me, please, with script code that provides to check every event on map (would be cool if restricted to map number, not every map in game) and if selfswitch B is ON, then it turns it OFF? I'm so bad at scripting ;_;
Why checking if it is on? just set every self-switch B to off without any check - if the self-switch is already off that doesn't change them.

And there is already a plugin provided in your extra resources that gives a plugin command to handle self-switches from other events (called outerselfswitch or something similiar)
The script call is this:

for (var i = 1; i < x; ++i) {
$gameSelfSwitches.setValue([y, i, "B"], false);
}

Replace y with the id of the map.
Replace x with the highest event id on the map +1 (so if the highest event id is 24, replace x with 25).

Original thread: https://forums.rpgmakerweb.com/threads/selfswitches-from-on-to-off-on-selected-maps.78940/