Running code on each map load ?

Joined
Jun 30, 2017
Messages
42
Reaction score
35
First Language
spanish
Primarily Uses
RMMV
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.
 

ct_bolt

Creator
Veteran
Joined
May 3, 2012
Messages
954
Reaction score
520
First Language
Javascript
Primarily Uses
RMMZ
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/
 
Joined
Jun 30, 2017
Messages
42
Reaction score
35
First Language
spanish
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Are we allowed to post about non-RPG Maker games?
I should realize that error was produced by a outdated version of MZ so that's why it pop up like that
Ami
i can't wait to drink some ice after struggling with my illness in 9 days. 9 days is really bad for me,i can't focus with my shop and even can't do something with my project
How many hours have you got in mz so far?

A bit of a "sparkle" update to the lower portion of the world map. :LZSexcite:

Forum statistics

Threads
105,883
Messages
1,017,234
Members
137,608
Latest member
Arm9
Top