RPG Maker Forums

New to RPG Maker MV and a rather out of practice with JavaScript (as well as coding in general), so I thought I would try something easy. Could anyone glance over the following plugin and let me know if there is a way to improve the code? I am attempting to port one of my favorite scripts from RPG Maker VXA which allowed to user to run a specified common event when entering or exiting a map. The plugin functions just fine, but some sections are a bit ugly ... 


Map Note Tags

  • Enter : <mtcvEn:cevId>
  • Exit : <mtcvEx:cevId>


Code:
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// █▐▐  [MV] Map Transfer Common Event
// ╞══════════════════════════════════════════════════════════════════════════════════╡
/*:
 *  @plugindesc Instantly run a specified common event when entering or exiting a map.
 *
 *  @author Exhydra
 *
 *  @param 
 *
 *  @desc 
 *
 *  @default 
 *
 *  @help 
 */
// ╘══════════════════════════════════════════════════════════════════════════════════╛
 
// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Plugin
// ╘══════════════════════════════════════════════════════════════════════════════════╛

var Exhydra  = Exhydra      || {};
Exhydra.MTCV = Exhydra.MTCV || {};


// ╒══════════════════════════════════════════════════════════════════════════════════╕
// ■ [Object] Game_Map
// ╘══════════════════════════════════════════════════════════════════════════════════╛

// ┌──────────────────────────────────────────────────────────────────────────────────┐
// □ [Function] setup
// └──────────────────────────────────────────────────────────────────────────────────┘

Exhydra.MTCV.Game_Map_setup = Game_Map.prototype.setup;

Game_Map.prototype.setup = function(mapId) {

	// Run exit common event
	if ($dataMap && $gamePlayer.newMapId() != $gameMap.mapId()) {
		$gameMap.instantCommonEvent(this._metaExitEvent);
	}

    Exhydra.MTCV.Game_Map_setup.call(this, mapId);

	// The new map is already loaded before the setup function is called, thus 
	// overwriting the meta data for the previous map. So I save the exit common
	// event id in a variable which is then used in the above code.
	this._metaExitEvent = $dataMap['meta'].mtcvEx || 0;

	// Run enter common event
	if ($dataMap && $gamePlayer.newMapId() == $gameMap.mapId()) {
		$gameMap.instantCommonEvent($dataMap['meta'].mtcvEn);
	}

}; // Game_Map ‹‹ setup

// ┌──────────────────────────────────────────────────────────────────────────────────┐
// □ [Function] instantCommonEvent
// └──────────────────────────────────────────────────────────────────────────────────┘
 
Game_Map.prototype.instantCommonEvent = function(cevId) {
	
	if (cevId > 0) {
		$gameTemp.reserveCommonEvent(cevId);
		this._interpreter.setupReservedCommonEvent();
		
		// The enter common event runs fine without the following code, however the
		// exit common event will not execute at all without force-running 
		// executeCommand() for each entry in the common event. The code works, but
		// it is rather ugly.
		this._interpreter._list.forEach(function(tempCommon) {
			$gameMap._interpreter.executeCommand();
		});
	}
	
}; // Game_Map ‹‹ instantCommonEvent

// ▌▌██████████████████████████████████████ EOF █████████████████████████████████████▐▐

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,034
Messages
1,018,446
Members
137,820
Latest member
georg09byron
Top