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.
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.
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...
RPG Maker separate into 4 layer
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.
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.
If you want manipulate content in game such actors, map, variable, switches and so on.
This the right place:
| Object | Type | Purpose |
|---|---|---|
$gameActors | Game_Actors | All actor instances by ID |
$gameParty | Game_Party | Active party, gold, items, steps |
$gameTroop | Game_Troop | Enemy group in current battle |
$gameMap | Game_Map | Current map, events, tiles, scroll |
$gamePlayer | Game_Player | Player character on map |
$gameVariables | Game_Variables | Game variables accessed by ID |
$gameSwitches | Game_Switches | Game switches accessed by ID |
$gameTemp | Game_Temp | Temporary runtime data (not saved in save files) |
$gameSelfSwitches | Game_SelfSwitches | Per-event local switches |
$gameScreen | Game_Screen | Controls screen effects (shake, tone, flash) |
$gameMessage | Game_Message | Message window state and dialogue data |
$dataActors | RPG.Actor[] | Database actors (read-only) |
$dataItems / $dataWeapons / $dataArmors | RPG.Item[] | Database items, weapons, and armors |
$dataSkills | RPG.Skill[] | Database skills |
$dataStates | RPG.State[] | Database states |
$dataEnemies | RPG.Enemy[] | Database enemies |
$dataMapInfos | RPG.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);