Commont event on load script custumization

I want to update this code for add a parameter in the pluggin option.


Curently this script run commonevent on map load based on a parameter inside map tag.


I want to add option in pluggin parameter for set a by default commonevent id.


This will be optional and map tag got priority if exist.


I try some stuff but did't seem to work, so I ask you help, that will help me to learn in same time.


The current working code:

Spoiler
var DEX = DEX || {};
DEX.MSCE = DEX.MSCE || {};
DEX.MSCE.Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function () {
    DEX.MSCE.Scene_Map_start.call(this);
    var commonEventId = $dataMap.meta.load_event_id;
    if (commonEventId) {
        $gameTemp.reserveCommonEvent(commonEventId);
    }
};



Thanks for your help.
var DEX = DEX || {};
DEX.MSCE = DEX.MSCE || {};
DEX.MSCE.Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function () {
DEX.MSCE.Scene_Map_start.call(this);
var defaultCommonEvent = 1; //Change this to the ID of the default common event
var commonEventId = $dataMap.meta.load_event_id;
if (commonEventId) {
$gameTemp.reserveCommonEvent(commonEventId);
}
else {
$gameTemp.reserveCommonEvent(defaultCommonEvent);
}
};


Not really in the form of plugin parameter (coz I might write it wrong as I don't have MV with me right now), but this should work, just change the value of defaultCommonEvent to the ID of the common event that you want to be default
Note, my problem is solved now -:0)


My current code, but if I put 460 in my map tag and 455 and default, that trigger 455 for unknow reason.

Spoiler
/*:
 * @plugindesc v1.00 Allows a common event to run on start of a Scene_Map, without creating an autorun.
 * @author Procraftynation - https://www.youtube.com/c/procraftynation
 *                         - https://github.com/procraftynation
 * @help
 * =====================================================================
 * Usage Syntax to be placed on a Map's Note:
 * <load_event_id:COMMON_EVENT_ID>
 * Example:
 * <load_event_id:1>
 *   - Calls the Common Event 1 when the map is just started.
 * NOTE: Only 1 common event can run on map start
 * =====================================================================
 * Terms of Use
 * =====================================================================
 * Free for use in non-commercial and commercial games just give credit
 * and link back to https://www.youtube.com/c/procraftynation.
 * If commercial, a free copy of the game is awesome but optional.
 * =====================================================================
 * @param DefaultEvent
 * @desc Enter the Commont evnt id to load by default
 * @default 0
 */


var DEXp = PluginManager.parameters('DEX_MapStartCommonEvent');
var DEX = DEX || {};
DEX.MSCE = DEX.MSCE || {};
DEX.MSCE.Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function () {
    DEX.MSCE.Scene_Map_start.call(this);
    var defaultCommonEvent = Number(DEXp['DefaultEvent']);
    var commonEventId = $dataMap.meta.load_event_id;



if (commonEventId !== undefined) {
   if (commonEventId > 0) {
      $gameTemp.reserveCommonEvent(commonEventId);
   }
}
else {
   if (defaultCommonEvent > 0) {
      $gameTemp.reserveCommonEvent(defaultCommonEvent);
   }
}
};
can you try to change this


if (commonEventId !== undefined) {
if (commonEventId > 0) {
$gameTemp.reserveCommonEvent(commonEventId);
}
}


into just this


if (commonEventId > 0) {
$gameTemp.reserveCommonEvent(commonEventId);
}


and see if it fixes your problem
if I set nothing as value, undefined is equivalent to 0?
IDK, I haven't tested it and I can't.. Actually, that might even error since undefined is a different type than 0


You could also just really do this like the original code which is simply "if (commonEventId)", this one will surely work seeing as how the original script uses just this and it works.

Code:
if (commonEventId) {
     $gameTemp.reserveCommonEvent(commonEventId);
}
else {
   if (defaultCommonEvent > 0) {
      $gameTemp.reserveCommonEvent(defaultCommonEvent);
   }

Original thread: https://forums.rpgmakerweb.com/threads/commont-event-on-load-script-custumization.74094/