Running code on each map load ?

Hi, I am working on a custom lighting/parallax plugin, currently the parallax is done via a simple PluginCommand in an autorun event. Now trying to trigger my plugin everytime a map is loaded instead of using a plugin command.

I tried with Game_map.prototype.setup()

Code:
Game_Map.prototype.setupOld = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId){
    console.log("mapId");
   var r = this.setupOld.apply(this, arguments);
   Game_Interpreter.prototype.pluginCommand('BlackLights');
   return r
}

But my plugin doesnt work here because SceneManager._scene._spriteset is not defined at that moment 🙁
I am looking to something like Game_Map.onLoaded( not existing ) to inject my call when i am sure the map
is loaded.
Hi, I am working on a custom lighting/parallax plugin, currently the parallax is done via a simple PluginCommand in an autorun event. Now trying to trigger my plugin everytime a map is loaded instead of using a plugin command.

I tried with Game_map.prototype.setup()

Code:
Game_Map.prototype.setupOld = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId){
    console.log("mapId");
   var r = this.setupOld.apply(this, arguments);
   Game_Interpreter.prototype.pluginCommand('BlackLights');
   return r
}

But my plugin doesnt work here because SceneManager._scene._spriteset is not defined at that moment 🙁
I am looking to something like Game_Map.onLoaded( not existing ) to inject my call when i am sure the map
is loaded.
This help?
https://forums.rpgmakerweb.com/index.php?threads/orange-map-change-event.46728/
Partially solved.


Thanks, after looking on orange-map-change-event, modified my code to:

Code:
var oldGamePlayer_performTransfer = Game_Player.prototype.performTransfer;
Game_Player.prototype.performTransfer = function() {
    console.log("TRANSFER");
    $gameTemp.reserveCommonEvent(10);
    oldGamePlayer_performTransfer.call(this);
};

And put the pluginCommand on that common event (10).
That works and solves the problem, but... makes my plugin a little bit more complicated to install.
Trying to do it without requiring to reserve a commont event just for a plugin command.

Using a 200 miliseconds timeout also solves the problem:

Code:
var oldGamePlayer_performTransfer = Game_Player.prototype.performTransfer;
Game_Player.prototype.performTransfer = function() {
    console.log("TRANSFER");
    setTimeout(function(){
       Game_Interpreter.prototype.pluginCommand('BlackLights');
   },200)
    
 
    oldGamePlayer_performTransfer.call(this);
};

But using a time-out it's not a solid solution.

Original thread: https://forums.rpgmakerweb.com/threads/running-code-on-each-map-load.116310/