Execute common event when any event is triggered.

So, what I want to do is execute a common event from the game, so whenever the player interacts with an event, it will run the common event and then run the event.


The reason for this is because I have a lot of events in my game and don't want to have to add the run common event to the beginning of every event in the game.


Is there any simple way to do this, like a plugin?
There is literally a reserve common event command in the event commands pages.

Spoiler
8idYbNu.png
There is literally a reserve common event command in the event commands pages.

Spoiler
[IMG]http://i.imgur.com/8idYbNu.png[/IMG]

I know, but I don't want to have to add that manually for every event in the game.
If you want it to run before any event in the game, you'll either need to put that in every event, or use a plugin. Of course I don't know about every plugin made so far, but I don't know of any that does what you're looking for.
If you want it to run before any event in the game, you'll either need to put that in every event, or use a plugin. Of course I don't know about every plugin made so far, but I don't know of any that does what you're looking for.

Okay.


Guess I might have to make my own, but I'm new to programming for RPG Maker MV.
Theoretically it shouldn't be that hard, since you want this to be done to every event, the easiest solution would probably be to alias the Game_Event's list function to get the list of event commands, and just pop the common event call in the beginning.


It looks roughly like this:

Spoiler
QxPjbAH.png



Just be sure to actually alias it, not just put things in the default scripts. That's bad practice, it'd be better to make it a plugin, with a parameter for which common event to call.


EDIT: Also I forgot to change the return statement to "return list;"
Theoretically it shouldn't be that hard, since you want this to be done to every event, the easiest solution would probably be to alias the Game_Event's list function to get the list of event commands, and just pop the common event call in the beginning.


It looks roughly like this:

Spoiler
[IMG]http://i.imgur.com/QxPjbAH.png[/IMG]



Just be sure to actually alias it, not just put things in the default scripts. That's bad practice, it'd be better to make it a plugin, with a parameter for which common event to call.

ok
You can use this plugin:

Code:
/*:
 * @plugindesc Call a Common Event before any event <CommonEventBeforeAnyEvent>
 * @author Hudell
 *
 * @param commonEventId
 * @desc The Id of the common event
 * @default 0
 *
 * @help
 * ============================================================================
 * Hudell's Plugins
 * ============================================================================
 * 
 * Check out my website:
 * http://hudell.com
 * 
 *=============================================================================*/
var Imported = Imported || {};
var CommonEventBeforeAnyEvent = {};

(function($) {
  "use strict";

  var parameters = $plugins.filter(function(plugin) { return plugin.description.contains('<CommonEventBeforeAnyEvent>'); });
  if (parameters.length === 0) {
    throw new Error("Couldn't find parameters of CommonEventBeforeAnyEvent.");
  }
  $.Parameters = parameters[0].parameters;
  $.Param = {};

  $.Param.commonEventId = Number($.Parameters.commonEventId || 0);

  var oldGameInterpreter_setup = Game_Interpreter.prototype.setup;

  Game_Interpreter.prototype.setup = function(list, eventId) {
    oldGameInterpreter_setup.call(this, list, eventId);

    if (this._depth === 0) {
      var commonEvent = $dataCommonEvents[$.Param.commonEventId];
      if (!!commonEvent) {
        this.setupChild(commonEvent.list, eventId);
      }
    }
  };
})(CommonEventBeforeAnyEvent);
You can use this plugin:



/*:
* @plugindesc Call a Common Event before any event <CommonEventBeforeAnyEvent>
* @author Hudell
*
* @param commonEventId
* @desc The Id of the common event
* @default 0
*
* @help
* ============================================================================
* Hudell's Plugins
* ============================================================================
*
* Check out my website:
* http://hudell.com
*
*=============================================================================*/
var Imported = Imported || {};
var CommonEventBeforeAnyEvent = {};

(function($) {
"use strict";

var parameters = $plugins.filter(function(plugin) { return plugin.description.contains('<CommonEventBeforeAnyEvent>'); });
if (parameters.length === 0) {
throw new Error("Couldn't find parameters of CommonEventBeforeAnyEvent.");
}
$.Parameters = parameters[0].parameters;
$.Param = {};

$.Param.commonEventId = Number($.Parameters.commonEventId || 0);

var oldGameInterpreter_setup = Game_Interpreter.prototype.setup;

Game_Interpreter.prototype.setup = function(list, eventId) {
oldGameInterpreter_setup.call(this, list, eventId);

if (this._depth === 0) {
var commonEvent = $dataCommonEvents[$.Param.commonEventId];
if (!!commonEvent) {
this.setupChild(commonEvent.list, eventId);
}
}
};
})(CommonEventBeforeAnyEvent);

Thanks

Original thread: https://forums.rpgmakerweb.com/threads/execute-common-event-when-any-event-is-triggered.61212/