RPGMaker plugin introduction

Quick introduction into RPG Maker plugin

Ta-da, my first blog post. Okay, moving on.

RPGMaker especially MV/MZ use pixijs in their corescript - a script for the engine. The engine utilize NW.js as distribution platform to be able running javascript in browser-like embedded environment. You could do inspect element in game engine.

Understanding javascript would be sufficient for create a plugins. To prevent misunderstanding, let agree on definition of plugin: a script that extend the corescript functionalities whether to modify behaviour or adding new feature on top of it.

So the key is : to extent what the engine already have. Even RPG Maker has to utilitize that allow us create game, without touch it with modification feel sadning, we could create unique even bizare behaivour for our game, to escape felt generic.

The basics

In this writting, I will use RPGMaker MV that installed in machine.

The code in plugin use things called IIFE (Immediate Invocation Function Expression) -- this pattern to prevent code pollution as it contain plugins specific separate from corescript to extending it.

/*:
 * @plugindesc Your Plugin Name
 * @author YourName
 *
 * @param ExampleParam
 * @desc A sample parameter
 * @default 100
 *
 * @help
 * Plugin Commands:
 *   MYPLUGIN open    - Opens the custom scene
 */

(function() {
  "use strict";
  
  console.log("hey, this from plugins");
})();

Save this code in js/plugins/ at your RPG Maker project with name TEST_PluginName.js.

Open "Plugin" menu at RPG Maker MV while you project open the project, right-click at empty list and select add, then choose you plugin name (filename, TEST_PluginName).

Do playtest and run inspect element inside your game! (press F12)

Now, you can create the plugins! Congrat!

B-but why it felt empty? I got you, be patient, we going to do something with it.

Alias Pattern

To extend, a function we will create an alias for it, which it run behaivour of it original function with our addition code in it. Look code below here:

var _Scene_Map_start = Scene_Map.prototype.start;
// store original function in temp variable

// shadowing the function
Scene_Map.prototype.start = function(){
  
  _Scene_Map_start.call(this);
  // call the original function
  
  console.log("Hey, I from plugin, invoked from Scene_Map start")
  // add some extra code, 
  // our injected behaivour
}

Familiarize youself with this type of code pattern, this will be our building block for plugin, and also this one...

The Engine Architecture

RPG Maker separate into 4 layer

  • Game Data : Game state, object dan data
  • Scene : Game screen (game map?)
  • Window : Menu UI, HUD and something
  • Sprite : Game sprites like character or something.

So if you want to create simple HUD, you could messing up in Window-* function and functio related with it, you can add sprite or what so ever.

But, if you dreamed to create your unique battle system or create mini-game puzzle, go with the scene. It literaly entire screen you see. When you playing game that is Scene_Map is rendered.

Interact with the Core

Now we done with appetizers, time to main dish.

There a lot important API function that we need to know, you could get reference script by Archeia.

But if you want to dive deep, let me summarize into couple section.

Game Data

If you want manipulate content in game such actors, map, variable, switches and so on.

This the right place:

ObjectTypePurpose
$gameActorsGame_ActorsAll actor instances by ID
$gamePartyGame_PartyActive party, gold, items, steps
$gameTroopGame_TroopEnemy group in current battle
$gameMapGame_MapCurrent map, events, tiles, scroll
$gamePlayerGame_PlayerPlayer character on map
$gameVariablesGame_VariablesGame variables accessed by ID
$gameSwitchesGame_SwitchesGame switches accessed by ID
$gameTempGame_TempTemporary runtime data (not saved in save files)
$gameSelfSwitchesGame_SelfSwitchesPer-event local switches
$gameScreenGame_ScreenControls screen effects (shake, tone, flash)
$gameMessageGame_MessageMessage window state and dialogue data
$dataActorsRPG.Actor[]Database actors (read-only)
$dataItems / $dataWeapons / $dataArmorsRPG.Item[]Database items, weapons, and armors
$dataSkillsRPG.Skill[]Database skills
$dataStatesRPG.State[]Database states
$dataEnemiesRPG.Enemy[]Database enemies
$dataMapInfosRPG.MapInfo[]Map list metadata

Example:

const actor   = $gameActors.actor(1);       // actor ID 1
const gold    = $gameParty.gold();
const hasItem = $gameParty.hasItem($dataItems[3]);
const varVal  = $gameVariables.value(5);    // variable #5
$gameVariables.setValue(5, varVal + 10);
const sw      = $gameSwitches.value(2);    // switch #2
$gameSwitches.setValue(2, true);

Scene

Window

Reference