Overwriten events are getting reset when opening the menu

Greetings Friends.

I am overriding the event details based on when specific meta values are found during the event initialization. Everything works as expected except for the case of going into the game menu, and then exiting out. The events are restored to their previous setting. When I leave the map, and return, the initialize is called again and the events are once again restored.

Can anyone help me in the right direction or prototype/function that I need to consider?

This is for RPGMaker MV

Thanks in advance
The event that controls the opening sequence should end with turning self-switch A ON.
Have a second page which is completely blank except for being conditioned by that self switch. This will ensure that the event only runs once. Without it, the event will run again every time you enter that map.
I am sorry if I am not being clear enough in my request but do appreciate your attempt in helping me.

This is for plug in development specifically. So this is in JavaScript and not using the built in event editor.

My script will look for meta tagging, and then overwrite the event logic. It works perfectly. I can leave the map and come back and still get the new logic. The issue happens when I go into the menu and then exit the menu. The custom logic that my plugin writes is reverted to whatever the original event logic was.

I assumed this was enough detail but if wanted I could share the script I have.

Thanks in advance

-- also, I guess after reading paying closer attention to the board it is on it on the wrong place. It looks like I cannot delete / or move thread. Can a moderator help me move it to this board? https://forums.rpgmakerweb.com/index.php?forums/learning-javascript.127/
Moderator note: Moving to Learning Javascript
Solved it myself. It turns out that in rpg_managers.js DataManager.loadDataFile() is being called whenever your on a map and enter then exit the menu which was overwriting my events after I overwrote them in initilize. Originally I was overwriting my event logic like such:
Spoiler: Original Failure
Code:
thisEvent.pages[0].list = [];
                var oListItem = {};
                oListItem.code = 355;
                oListItem.indent = 0;
                oListItem.parameters = [];
                oListItem.parameters.push("HarvestResource(" + this._mapId + "," + this._eventId + ");");
                //oListItem.parameters.push("alert(" + this._mapId + "," + this._eventId + ");");
                thisEvent.pages[0].list.push(oListItem);
                
                var oListItem2 = {};
                oListItem2.code = 0;
                oListItem2.indent = 0;
                oListItem2.parameters = [];
                thisEvent.pages[0].list.push(oListItem2);

To solve, I ended up overwriting the Game_Event.prototype.start function to look for the case of my custom logic, act, then perform anything in the database:


Spoiler: Code
Code:
var alias_GameEventstart = Game_Event.prototype.start;
Game_Event.prototype.start = function() {
    alias_GameEventstart.call(this);
    if (this.IsResource())
    {
        this.HarvestResource();
    }
};

Original thread: https://forums.rpgmakerweb.com/threads/overwriten-events-are-getting-reset-when-opening-the-menu.85742/