Toggle many different events with a single switch

There are many apples scattered on the map (100). Each lying apple represents a separate event and can be eaten when the player touches it. When it is eaten, it visually disappears.
There is a tree with apples on the map. The player can hit it and then all 100 apples will fall from the tree and appear in the same places. There is only one switch inside the tree event.

Is this possible? To change the condition of many similar events separately, but then put them back in their original position all together using just one switch?

What I mean is that I don't want to use 100 separate switches for each apple, but I'm willing to use plugins/scripts. I've tried doing it through YEP self switches, but unfortunately those switches you make self switches become them completely and you can't switch them remotely anymore.
If the tree sets of one universal switch that isn't a self switch, and every apple has the same switch conditions, it would work.
not directly, but it can be done with a combination.

each apple event needs to have three pages.
first page is apple on the ground, no condition, switch self-switch A if eaten/action button
second page is conditioned on self-switch A, does nothing
third page is conditioned on one reset-switch (same for every event), parallel process with three commands: control self-switch A off, wait 2 frames, control reset-switch off.

the wait(2) is very important here, don't mess with it unless you know what you're doing

With those events every apple should get back the moment the reset-switch is triggered at the tree, and that can be repeated as two frames later the reset-switch would be off again.
Oh, that's nice, I didn't think of it, thank you. But I'm not sure about waiting.

1650039187778.png


I tested it with 20 events and it works fine, all of them are back in place when I'm activating the switch. If they are all parallel, then there is no point in waiting, or are there some pitfalls? My point of view is that if you have 100 parallel events that start working when you flip a switch, it's better to make them work shorter so they don't waste even 2 extra frames.

Edit: it's for you, @Andar , I forgot to quote the message.
You should be able to do this with a script call within the event (provided your 100 apple events are all sequential IDs):

var firstEventID = 1; var lastEventID = 100; for (var i = firstEventID; i <= lastEventID; i++) { var key = [this._mapId, i, "A"]; $gameSelfSwitches.setValue(key, true); }

I don't think a wait will be necessary with this approach but I included it in case in the screenshot below:

1650039389720.png
then there is no point in waiting, or are there some pitfalls
the pitfall is in the timing: if the second command switches off the reset before all apples are reset, then it can happen that some apples do not reset at all, simply because the switch is off again before their third page can be processed.

unfortunately all timing problems are random because no one can really know the order in which a hundred events are processed. And that is why I usually go the guaranteed way by forcing the event to wait before disabling the reset. 2 frames are only 1/30 of a second after all, too fast for any human to detect.

EDIT: and no, @Villhelm 's scripted mehtod does not need the wait because no other events are processed in that time
Just to mention it, it is possible to Change the Self Switch of an Event from another Event.
Code:
 $gameSelfSwitches.setValue([$gameMap.mapId(), 1, 'A'], true)

To change all 100 Self Switches A to Off:
Code:
for (var a = 1; a < 100; a++) {
if (!!$gameMap.event(a)) {   // check that event exists
$gameSelfSwitches.setValue([$gameMap.mapId(), a, 'A'], false);
 }}
Edit:
This Solution was allready mentioned and i somehow overlooked it.

Original thread: https://forums.rpgmakerweb.com/threads/toggle-many-different-events-with-a-single-switch.146787/