Plugin authoring tutorials?

I know this is probably starting a bit off the deep end, but I'm a programmer that's interested in exploring plugin creation in RPG Maker MV, though I'm new to the software.  (I love coding, but strongly dislike creating graphics from scratch... something the program looks to provide quite nicely.)  I've already taken a look at the code for some existing plugins, but it's a slow start when you don't have any guidance.

Is there any existing documentation on how to write plugins and connect to various game subsystems?

What would be some good plugins to examine and learn from?  It'd be great to start with some simpler ones and then up the complexity, since I know what I'm interested in doing will likely end up complex.  I know how to build things up progressively, and I'm fine with programming independently... but I have little knowledge of how that connects with the RPG Maker MV engine.

-----

If anyone's curious...

My first idea of interest:  I tend to like character customization in various forms - one I'd like to author would be AP-based skill/stat unlocking for character customization.  (Which would eventually involve tracking extra data, extra stats, extra menus... yeah.  Complex.)   I figure the first large-scale component I should look at is probably enabling extra stats before moving onto the other details, and I've not even seen anything toward that yet.
I'm interresting too. I know, VB, VBS, Lua and a little C++.

In the futur, i would create the "Grandia" or "Child of Light" Battle.
I'd be interested in this documentation too,  I'm in the process of reverse engineering plugins to see how they're structured -- obviously taking more time than it should
You could check the files inside the js folder of every project:

  • rpg_core
  • rpg_managers
  • rpg_objects
  • rpg_scenes
  • rpg_sprites
  • rpg_windows

Those are the core files for every game.
I know this is probably starting a bit off the deep end, but I'm a programmer that's interested in exploring plugin creation in RPG Maker MV, though I'm new to the software.  (I love coding, but strongly dislike creating graphics from scratch... something the program looks to provide quite nicely.)  I've already taken a look at the code for some existing plugins, but it's a slow start when you don't have any guidance.

Is there any existing documentation on how to write plugins and connect to various game subsystems?

What would be some good plugins to examine and learn from?  It'd be great to start with some simpler ones and then up the complexity, since I know what I'm interested in doing will likely end up complex.  I know how to build things up progressively, and I'm fine with programming independently... but I have little knowledge of how that connects with the RPG Maker MV engine.

-----

If anyone's curious...

My first idea of interest:  I tend to like character customization in various forms - one I'd like to author would be AP-based skill/stat unlocking for character customization.  (Which would eventually involve tracking extra data, extra stats, extra menus... yeah.  Complex.)   I figure the first large-scale component I should look at is probably enabling extra stats before moving onto the other details, and I've not even seen anything toward that yet.
If you have Programming Experience, this will take you an hour tops to figure out, but here are my notes.

First,  you should reverse engineer an existing plugin.

it works in a way where you declare what function you want to edit

Once declared and have parameters set,  you then write your own version of this function.

when input in plugins and is enabled,  your plugins function is called and not the systems.
I started using RPG Maker XP back in 2006 and coming back to MV. I'm also a programmer but i'm good with spriting and art in general so i have it easier than you.

Anyway, I've delved into it quite a bit and here's my process:

1. Check the help file provided in your installation directory. It's quite helpful with getting started with the UI itself and at the end it gives u the API for the base classes (from Bitmap to windows, data structures, etc).

2. Check the script call master list provided by Archeia: http://forums.rpgmakerweb.com/index.php?/topic/46456-rpg-maker-mv-script-call-list/

This gives you a "complete" list of global variables used most commonly in RMMV. I've tried calling $gameMessage's ShowText() from an Event in the map, and it works great.

Right now i'm experimenting on different global variables in that master list in conjunction to creating test plugins.

3. Check the js folder in your project. The scripts are 2-10k lines which is daunting and i havent even read all off it in detail, but you will probably get the purpose of each pretty quick.

The main.js and rpg_managers.js are the main things that gives you the idea of how the engine runs.
 

4. For the plugins I started with the ENEMYBOOK.js script, for some reason. This is one of the simplest plugins I saw so far that introduces new methods to existing classes.

5. Create a test project and try to modify Window and Scene class.

My goal is to create my own battle and inventory system without using community-made plugins.

Good luck
Yeah it is pretty easy to do.  I have programming experience, but not with javascript.  If you worked with ruby before, you will probably like JS better.  Go into your game folders and open the java script files in notepad.  You can either edit the core scripts or make plugins.  

The only downside is the tediousness over the last version of RPG maker.  I used to love making a quick change to the core code, running the program, and test fixing,  Now you have to do a few more steps.  The same is with resources too.  

For the life of me, I don't understand why they didn't just add a simple text editor into MV.  It would be nice to be able to reference the javascript files without having to dig through projects, shrink screens, make edits, save, bring up rpg maker, run it, go back, etc etc etc.  Even when doing a slightly more custom event script, you end up leaving the JS files open at all times.  

MV is really moving in the direction to cater to kiddies who just want to make generic looking games and use all yanfly's plugins.  As great as they are, they make most games appear cookie cutter.  But I shouldn't complain cause we all do have the ability to change what we want.

*For those that are saying they know C++/VB, etc, then this will be a cake walk.  Like I said before, just open the java script files and edit.   
here is a template fo you to follow

https://www.dropbox.com/s/23qz6k2st0fnjb1/template.js?dl=0

Open it with your favorite text editor ( i prefer notepad ++ for these kinds of things) and give it a read over.

It will explain the basics of plugin building. 

It should give you enough of a foundation to explore on your own.
Is there any existing documentation on how to write plugins and connect to various game subsystems?

What would be some good plugins to examine and learn from?  It'd be great to start with some simpler ones and then up the complexity, since I know what I'm interested in doing will likely end up complex.  I know how to build things up progressively, and I'm fine with programming independently... but I have little knowledge of how that connects with the RPG Maker MV engine.
There's some stuff in the Help file. Look in the section titled "Plugin Specifications". Just something to note if you haven't read that - all RMMV plugins are meant to be encapsulated in functions. The core files outside the plugins folder, the ones labelled "rpg_" are not.

I can't tell you what Plugins you'd find easy to learn from - only you can know that - but I'm inclined to suggest staying away from anything massive like Yanfly's Engine plugins and Luna Engine if you're not confident. For me, I'd suggest taking a look at something like those "AltMenuScreen" plugins that come with the engine, but that's just because big visual changes make it easier for me to, well, see what they do.

The sad reality is that you'll need to know how the engine is structured before you can figure out how anything is linked to anything and if you're willing to follow the chain of code, the stuff in "main.js" is run first. Good luck.
How do we debug (show console messages, throw exceptions, etc)? I broke one of the scripts on purpose and got a black screen but I don't know how to check for errors.
How do we debug (show console messages, throw exceptions, etc)? I broke one of the scripts on purpose and got a black screen but I don't know how to check for errors.
F8 opens the console during playtest.
OK, I've definitely done some diving in and figured out a few things - I already got my feet wet with a minor plugin for customizing a few small battle features.  I based some of the coding patterns off of insights I cleaned from examining Yanfly's plugins.

//=============================================================================// JahwsUF - Battle Stat Manager// JAH_BattleStatManager.js// Version: 1.00//=============================================================================var JahwsUF = JahwsUF || {};//=============================================================================/*: * @plugindesc v1.00 Used for configuring otherwise-hardcoded battle stats. * @author JahwsUF * * @param Critical Multiplier * @desc critical hit dmg = base damage * this multiplier * Default: 3 * @default 3 * * @param Min Initial TP * @desc Minimum amount of TP a character may have at the start of battle. * Default: 0 * @default 0 * * @param Max Initial TP * @desc Maximum amount of TP a character may have at the start of battle. * Default: 25 * @default 25 */JahwsUF.Parameters = PluginManager.parameters('JAH_BattleStatManager');JahwsUF.Param = JahwsUF.Param || {};JahwsUF.Param.CriticalMultiplier = Number(JahwsUF.Parameters['Critical Multiplier']);JahwsUF.Param.MaxInitialTP = Number(JahwsUF.Parameters['Max Initial TP']);JahwsUF.Param.MinInitialTP = Number(JahwsUF.Parameters['Min Initial TP']);// Replaces the original function implementation from rpg_objects.js.Game_Action.prototype.applyCritical = function(damage) { return damage * JahwsUF.Param.CriticalMultiplier;};// Replaces the initial TP assignment function from rpg.objects.js.Game_Battler.prototype.initTp = function() { range = JahwsUF.Param.MaxInitialTP - JahwsUF.Param.MinInitialTP; this.setTp(Math.randomInt(range) + JahwsUF.Param.MinInitialTP);};Info for those versed in other languages:

  • Javascript is very clearly not a strongly-typed language - no type declarations.  You can custom build your own objects on the fly, without previously declaring all the fields and methods.
     
  • Plugins are loaded with the default *.js files first, then from top to bottom in the plugin manager.  This is very important to note due to its implications.

    * If you have one plugin that relies upon another, that "another" needs to be higher up so that the relevant objects and variables will exist.

    * You can completely overwrite old functions with new ones by assigning a newly defined function to the same location as an old one, as done in the small plugin example above.  (Apparently every function is actually represented via function pointer internally -  I haven't done it yet, but I'm confident that you could "store" the old function in a variable within your plugin and call it from the new one to override + extend the old version!)
     
  • You can pretty clearly see how to define plugin parameters in the code/comments above, which uses pretty standard annotation syntax. 

    Important - make sure all three pieces are there - @param, @desc, and @default.  If you put in description text without the @desc tag, it will break the plugin manager when you run the game, but not before, render the parameters unreadable to your plugin and likely crashing your game.
     
  • In order to read those parameters, you call "PluginManager.parameters('MyPlugin');" when "MyPlugin.js" is the filename of your plugin.  It returns a loosely typed directory/map structure (hash map, for those with CS knowledge) of pairs of strings.
     
  • There also exists syntax for the help / documentation part of your plugin.  I was just a lazy programmer and left it out - you use @help to denote the start of that area in your master comment, which seems to end once your master multi-line comment containing the annotations ends.
F8 opens the console during playtest.
Thanks! Very useful!

@JahwsUF, where does range come from? this won't cause errors but range will be declared in the global scope. is this intended?

Also, i wonder if when writing plugins to be shared in public, if we need to do data validation (like if damage passed isNaN). validation can impact performance but i dont know, i think we need to reduce as many errors as possible.
Thanks! Very useful!

@JahwsUF, where does range come from? this won't cause errors but range will be declared in the global scope. is this intended?

Also, i wonder if when writing plugins to be shared in public, if we need to do data validation (like if damage passed isNaN). validation can impact performance but i dont know, i think we need to reduce as many errors as possible.
Range is intended as a local variable, and according to this link, range is not global but local as originally written.

As for data validation, I will say the methods provided here have exactly the same validation as the original methods from the RPG Maker's core libraries.  It might not hurt to manually implement exception handling, assuming that's a thing in Javascript.  The code above was first intended as a minor exploration in coding a plugin - short, simple, and sweet; an easy-ish to read intro into plugin design.  Complexities can always be added later, and it has the bonus of being a great starting point for a useful plugin, and even functions as such in this form.
OK, I've definitely filtered through a lot of stuff and found out some pretty interesting things.

Example:  all stats are pre-calculated for every class in the database.  They're static values in the system, which are then offset by equipment - they're never stored locally on each Actor!  (See Game_Actor.prototype.paramBase in rpg_objects.js, line 3829 or so.)

It's easily possible to implement your own functions in a *.js plugin and reference those in damage formulas - if there's a complex formula you want to use frequently, it's very worth considering.

There's one major thing I've left to figure out/discern - how do save files work with this thing?  What data gets stored in a save file vs not?  I'm assuming it's possible to store things on game objects, since Yanfly's done a customized-items script, but how that works is not yet clear to me.  I'd like to make some class values that can be stored as part of the actors... but I've noticed that the core Game_Actor objects seem to be reconstructed each time the game is reloaded.
here is a template fo you to follow

https://www.dropbox.com/s/23qz6k2st0fnjb1/template.js?dl=0

Open it with your favorite text editor ( i prefer notepad ++ for these kinds of things) and give it a read over.

It will explain the basics of plugin building. 

It should give you enough of a foundation to explore on your own.
Good stuff man! Thanks for the template.
I've moved this thread to Learning Javascript. Please be sure to post your threads in the correct forum next time. Thank you.
You should always write your entire plugin code (except for the parts you want to make public) inside a self-executing function, like this:

var IAVRA = IAVRA || {};(function() { "use strict"; // IAVRA.MyPlugin = ...})();This way you can define local variables without having them globally available (which can be REALLY nasty).I only have 1 line outside the function, which is my namespace object. The notation

var IAVRA = IAVRA || {};initializes the object if it doesn't already exists and leaves it alone, otherwise. I use this namespace for all of my plugins to not mess with other plugin's variables.Also note that i put "use strict"; in my function. This enables strict mode, which, among other things, prohibits the declaration of global variables (global variables don't have a "var" in front of them and are globally available. Local variables with a leading "var" are scoped to the surrounding function).
Assume I want to extend a 3rd party plugin (YED_MessageCore.js).  I want to add one additional regex to Window_Base.prototype.convertExtraEscapeCharacters, where the plugin replaces escape codes in the message boxes.  Now it's probably a bad idea to modify the plugin directly because if they update it, I will lose my modification. For the record, I have already made the modification to test it, to ensure it does what I want, which it does.  I can leave it, but as I said, updates would be a problem... I'd like to do it correctly if I can.

So how do I create my own plugin that extends someone else's plugin?
Assume I want to extend a 3rd party plugin (YED_MessageCore.js).  I want to add one additional regex to Window_Base.prototype.convertExtraEscapeCharacters, where the plugin replaces escape codes in the message boxes.  Now it's probably a bad idea to modify the plugin directly because if they update it, I will lose my modification. For the record, I have already made the modification to test it, to ensure it does what I want, which it does.  I can leave it, but as I said, updates would be a problem... I'd like to do it correctly if I can.

So how do I create my own plugin that extends someone else's plugin?
It's past midnight here, so I just took a little peek at how Yanfly extends some core plugins like Battle Engine Core with the Action Sequence Packs.

At the beginning of the scripts there is always something like

var Imported = Imported || {};

Imported.YEP_X_ActSeqPack1 = true;

 

var Yanfly = Yanfly || {};Yanfly.ASP1 = Yanfly.ASP1 || {};



 

Enclosing the actual script is this here

 

if (Imported.YEP_BattleEngineCore) {...}


to ensure that the core script is loaded, so you should make sure to have that check, too.

I don't have much knowledge about javascript as I'm in the middle of learning it, so I might be totally wrong.

But I think, in Yanfly's case,  you can override the function you want as you can with any function from RMMV itself, as they don't seem to be private.

Just make sure that you have the line with

var Yanfly = Yanfly || {};

so you can use Yanfly.Message.Window_Base_convertEscapeCharacters

Original thread: https://forums.rpgmakerweb.com/threads/plugin-authoring-tutorials.47036/