A Start to Plugins

This is going to be a pretty pitiful lesson on MV's Plugins. This is just from a day one glimpse of RMMV. I'm sure someone else will make a better guide in the future.
Unlike the ruby script editor, Javascript plug-ins have to be written outside the program. Notepad is all you really need, however it won't colorize your code.

[Creating a New Plugin]
Saving from Notepad into your project's plugin folder, change the file type to All files (*.*) and end the filename with .js
Rpg Maker's Help file says it uses UTF-8 for character code, so that's what we'll change the encoding to.
ImageImage

[Setting Parameters]
First things first, add your documentation.
Any line starting with // will be a comment and not executed code.
The documentation that appears in the plugin editor begins and ends with /*: and closes with */ like so
Image
You can read more about the plugin parameters in the help file.

[Redefining Methods & Functions]
I think most people will want to make changes to what's already there. So what you can to do is search for the existing methods and functions like window and display items. There's no convenient script editor; being familiar with the RGSS in previous makers will clue you in to which .js you should look in, otherwise you may need to find what you're looking for.

I know I'm glossing over a lot. But I believe you'll pick up the proper syntax and structure as you play around.

For this example I'm going to change the Party Command List which is found in the rpg_windows.js
We don't want to edit it directly so we're going to copy it over to our plug-in file. Whatever changes we make in our plug-in will overwrite the original because we're using the same method name: Window_PartyCommand.prototype.makeCommandList
Image
With this function I can renamed the Fight and Escape commands. But that's dumb since we can edit the terms in the database. Instead we'll add a new command "Dance" between the Fight and Escape lines.

this.addCommand("Dance");
Image

All this does is add a new command to the list. Keeping this a simple demonstration, it won't actually do anything. Baby steps.
With the plugin enabled, and saved the changes to the project, when we test battle we should see this:
Image


[Aliasing]
some practical advice/ further explanations that might be hard to follow Show
It's called Aliasing in Ruby. I think in Javascript it's called an Anonymous Function. I'm not an expert.
Imagine if this command list was a lot longer than "Fight" and "Escape". It wouldn't be very efficient or clean to copy a long piece of code if we're just adding 1 new line and nothing else. So what we can do is store the function (object, prototype, method, I'm not clear on the proper terminology) into a variable which I'm calling "original".

var original = Window_PartyCommand.prototype.makeCommandList;

With the old method stored inside this variable it's safe to use the method name in our plugin. Like so.

Window_PartyCommand.prototype.makeCommandList = function() {
this.addCommand("Dance", 'fight');
};

It'll look like this since using the same name "...makeCommandList" in our plugin rewrote the method in rpg_windows.js
We don't have Fight and Escape in the command list anymore
Image


But we stored the original in a variable, so all we have to do is call the original list first using variable name and .call(this) before the "Dance" command

Window_PartyCommand.prototype.makeCommandList = function() {
original.call(this);
this.addCommand("Dance", 'fight');
};

But this of course places Dance below Fight and Escape because that's the order it's written in. Realistically, a longer list of commands would be placed inside an array [fight, escape, dance, ect...] that you can rearrange with methods like .push() or .splice()
Image


[More to come?]
Where was I going with this
Image
Cheers for this. I worked out most of it but this has cleared up a few things.

There's a lot of new keywords that will probably look scary to a newcomer, but once you're used to them and where they go (for example prototype: http://www.w3schools.com/js/js_object_prototypes.asp) it's pretty much Ruby with semicolons.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78821