Starting a plug-in

(I realized after this probably should have been put into java support)


So I've been looking at the Java coding, and comparing it to ruby to figure out the calls.


So I feel about ready to make a quick plugin for many of the features I changed a lot in many of the Ace games for MV.


This probably sounds stupid, but is there a way to start it, or just write what functions I want to change.


Would I just put below in a .js file, for example, or are there special headers I need for the files?

Code:
Game_Actor.prototype.expForLevel = function(level) {
    return Math.round((100 * level) - 100);
};
I'm no expert on JavaScript but from my previous experience and just now looking at the plugins which come with MV there isn't anything needed at the start of script, of course it'll look much better with comments detailing what it does and what certain var's you've created do but that's more for making it look better and making easier to change later on then an actual necessity.
You do. The main parts are these:


The FILE_NAME.js is definitely necessary, as well as the plugin description and author. I'm not sure, but I don't think the help section is required.


//=============================================================================
// FILE_NAME.js
//=============================================================================

/*:
* @plugindesc description
* @author yourname
*
* @param optional
* @desc
* @default
*
* @help
*
* Optional
*
*/


Something that takes the bare minimum would look like this:


//=============================================================================
// AltSaveScreen.js
//=============================================================================

/*:
* @plugindesc Alternative save/load screen layout.
* @author Yoji Ojima
*
* @help This plugin does not provide plugin commands.
*/


(taken directly from the AltSaveScreen plugin included with MV ;P)
A plugin will work without any of the comments mentioned - the filename isn't required in the comments either.


The comments with @plugindesc, @author, @help etc. will be pulled into the plugin manager if they exist to help those who are using it but they seem to work fine without any of them  🙂
You can literally just dump code into a js file and it should work. But if you want to be more professional you can add a fancy header. Here is a template I use (borrowed mostly from Yanfly's formatting)

Spoiler
Code:
/*=============================================================================
 * Gilgamar - Equip Common Event
 * By Gilgamar
 * G_EquipCE.js
 * Version: 1.02
 * Free for commercial and non commercial use.
 *=============================================================================*/

var Imported = Imported || {};
// You can check this flag in other scripts that depend on this one to make sure this one has been loaded
Imported.G_EquipCE = true;          

/*:
 * @plugindesc v1.02 Enable equipment common events.  <-- This stuff shows up in the plugin manager as a description
 * @author Gilgamar
 *
 * @help <-- this section shows up in plugin manager when you click the help button on your plugin
 * ============================================================================
 * Introduction
 * ============================================================================
 * Enables weapon and armor equip/remove common events via notetags. Ex:
 *
 * <EquipCE Event: 1 onequip>
 * <EquipCE Event: 2 onremove>
 *
 * The precedling lines will run common event ID 001 on equip and common event
 * ID 002 on remove for the weapon or armor tagged.
 *
 * The event does not run until menu is closed. If the item is equipped or
 * removed multiple times before closing the menu only the last event will run.
 *
 * ============================================================================
 * Changelog
 * ============================================================================
 * Version 1.02:
 * - Added SceneManager.goto(Scene_Map) after common event so the event will
 * run immediately on equip/remove
 *
 * Version 1.01:
 * - Moved event check into Game_Actor.changeEquip() so it works on optimize
 *
 * Version 1.00:
 * - Enables weapon and armor equip/remove common events via notetags
 */
@Galv Oh, seriously? xD But doesn't a plugin need to be turned on in the plugin manager to start properly? I've also noticed that if my file names mismatched, the plugin manager would reject the plugin/not run it.
Not sure where your mismatched filenames come from, but I can create a blank test.js file and can turn it on in the plugin manager.
Here is a simple template for setting up your plugin commands, probably the most useful thing you can do in a script to make it easy to use.

Code:
// Change 'aliasPluginCommand' to use your own alias
var aliasPluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
    aliasPluginCommand.call(this, command, args); // <-- change alias here also
    if (command == 'Chance') { // <-- this is first word in your plugin command
        switch (args[0]) {
            case 'shuffle':  // <--- second word in your plugin command, add more as needed
                var array = $gameVariables.value(Number(args[1]));  // <-- this is the third word (or number) (args[1])
                Chance.shuffle(array); // <--- run your code here
                break; // <--- don't forget to break on each case
        }
    }
}
@Galv Ah, then, I may be mistaken (I might've been thinking about the importing plugin parameters part). I learned MV's JS format nearly completely by looking at Yanfly's plugins xD


@deilin, pleas disregard my statements.
Ty.


I will try a few things mentioned. I'm so used to just changing core scripts directly, thought at least having a plug-in would save some time. Would definately be interesting to get the inputs working too for some of them.
@Galv Oh, seriously? xD But doesn't a plugin need to be turned on in the plugin manager to start properly? I've also noticed that if my file names mismatched, the plugin manager would reject the plugin/not run it.



That is correct. The name of the file matters when reading plugin parameters, but it is not required to load the plugin. It just means it won't find your plugin parameters.
Or, alternatively, you could use a different way to read plugin parameters (hint: It's linked in my signature). It has been adapted by dozens of plugins so far and i've yet to hear someone complain about it (unlike PluginManager.parameters, which tends to easily break some plugins) 😉
Or, alternatively, you could use a different way to read plugin parameters (hint: It's linked in my signature). It has been adapted by dozens of plugins so far and i've yet to hear someone complain about it (unlike PluginManager.parameters, which tends to easily break some plugins) 😉

hahaha I implemented your method in my Core Manager xD for my own plugins 


they also have MANIES way's to implement yours coding actually if I show you from my OWN way's to implement.


this from my Engine EmojiEngineV2

Spoiler
/*:
//==============================================================================
// ■ Emoji Engine MV - Origin "EmojiBase"
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// * @plugindesc Base for EMM. It's store params and permit to extract plugin
parrameters easily and faster then the default manner.
// * id: EEMV::Core
// * @author Nio Kasgami.
// * @Data : 2015/10/05
// * @Version : 2.0.0
// * @Require : NA
//==============================================================================

//==============================================================================
// ■ History
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// * 2015/10/29 - Begin and finish the plugin.
// * 2016/2/08 - Rewrite the plugin for being handles as Static class.
//==============================================================================

//==============================================================================
// ■ Plugin Parameter
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// this section handle the plugin parameter. Please do not edit unless you
// want to add extra plugin command.
//------------------------------------------------------------------------------
* it's a base so this not handle any param commands
//==============================================================================

//==============================================================================
// ■ Help File
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// This section serve for input the help file in the engine don't touch this
// unless you want to input more information
//------------------------------------------------------------------------------
* @help
* This plugin base serve for handles datas so it's not provide plugin command
* though it's serve for store my other plugin commands via the alias of
* the method "get_pluginname" and "get_params".
*
* be sure please to input this above all my EEMV plugin for avoid any issues.
*
* ====================================================================
* ■ Internal Method call
* ====================================================================
* /var/ = this.set_PluginName(plugin); : set the plugin name.
* /var/ = this.set_PluginID(plugin); : set the plugin ID.
* /var/ = this.setString(pluginVar,ParamName); : set the param as a string.
* /var/ = this.setBoolean(pluginVar,ParamName); : set the param as a boolean.
* /var/ = this.setNumber(PluginVar,ParamName,type,max_number); : set the
* params as number and permit to proceed maths conversion.
* /var/ = this.setArray(PluginVar,ParamName); : transform a list of number in
* array.
*/

//==============================================================================
// ■ Emoji
//------------------------------------------------------------------------------
// the class who handle all the base of my plugins. Can be access directly.
//==============================================================================

var $imported = $imported || {};
var $version = $version || {};

$imported.EmojiBase = true;
$version.EmojiBase = 2.00;



function Emoji(){ throw new Error('This a static class.'); }

Emoji.alias = Emoji.alias || {}; // Public variable : alias

//----------------------------------------------------------------------------
// ○ new public function: init
//----------------------------------------------------------------------------
// * this method serve for initialization. It's not necessary to touch this
// * method.
//
Emoji.init = function(){
this.getPlugins();
this.getParams();
this._initDebugger();
};

//----------------------------------------------------------------------------
// ○ new private function: _initDebugger
//----------------------------------------------------------------------------
// * will open the Debuging Box on startup if enabled.
//
Emoji._initDebugger = function(){
if (this._debugger === 'true'){
require('nw.gui').Window.get().showDevTools();
}
};

//----------------------------------------------------------------------------
// ○ new public function: getPlugins
//----------------------------------------------------------------------------
Emoji.getPlugins = function(){
this._emoji = this.setPluginID('EEMV::Core');
};

//----------------------------------------------------------------------------
// ○ new public function: getParams
//----------------------------------------------------------------------------
Emoji.getParams = function(){
this._debugger = this.setBoolean(this._emoji,'Enable Debugger');
this.fixTimer = this.setBoolean(this._emoji, 'Stop Timer');
};

//----------------------------------------------------------------------------
// ○ new public function: setPluginName
//----------------------------------------------------------------------------
Emoji.setPluginName = function(plugin){
return PluginManager.parameters(plugin);
};

//----------------------------------------------------------------------------
// ○ new public function: setPluginID
//----------------------------------------------------------------------------
Emoji.setPluginID = function(plugin){
return $plugins.filter(function(p){return p.description.contains('id: ' + plugin)})[0].parameters;
};

//----------------------------------------------------------------------------
// ○ new public function: init
//----------------------------------------------------------------------------
Emoji.setString = function(plugin, param){
return String(plugin[param]);
};

//----------------------------------------------------------------------------
// ○ new public function: setBoolean
//----------------------------------------------------------------------------
Emoji.setBoolean = function(plugin,param){
var n = plugin[param];
if(n === 'true' || n === 'false'){
if(n === 'true'){
return true;
} else {
return false
}
} else {
throw new Error(param + ' is a boolean please set it to true or false.');
}
};

//----------------------------------------------------------------------------
// ○ new public function: setNumber
//----------------------------------------------------------------------------
Emoji.setNumber = function(plugin,param,type,maxNumber){
var number = Number(plugin[param]);
switch(type.toLowerCase()){
// Get the regular number.
default :
return number;
break;
// Get the low round.
case 'floor' :
return Math.floor(number);
break;
// Get the uppest round.
case 'ceil' :
return Math.ceil(number);
break;
// Round to the nearest value.
case 'round' :
return Math.round(number);
break;
// Convert number to percent.
case 'topercent' :
return (number / maxNumber) * 100;
break
// Convert the percent in float number.
case 'todecimal' :
return (number / 100) * maxNumber;
break;
// Convert the number in PI value.
case 'topi' :
return alert('this functionnality is unavalable');
break;
// Return the absolute value of the number.
case 'abs' :
return Math.abs(number);
break;
// Convert the number in a Cossin maths.
case 'tocos' :
return Math.cos(number);
break;
// Convert the number in a Sin Maths.
case 'tosin' :
return Math.sin(number);
break;
// Convert the number in a Tangente Maths.
case 'totan' :
return Math.tan(number);
break;
}
};

//----------------------------------------------------------------------------
// ○ new public function: setArray
//----------------------------------------------------------------------------
Emoji.setArray = function(plugin, param){
return plugin[param].split(',').map( function (i) {return Number(i || 0);} );
};

//----------------------------------------------------------------------------
// ○ new public function: setStringArray
//----------------------------------------------------------------------------
Emoji.setStringArray = function(plugin, param){
return plugin[param].split(',').map( function (i) {return String(i || "");} );
};

Emoji.init(); // for get the pluginParam on startup.
//===============================================================================
// => END : Emoji
//===============================================================================

//==============================================================================
// ■ Sprite
//------------------------------------------------------------------------------
// The game object class for the timer.
//==============================================================================

Sprite.prototype.mirror = function(horizontal,vertical) {
if(horizontal){
this.scale.x = -1;
} else {
this.scale.x = 1;
}
if(vertical){
this.scale.y = -1;
} else {
this.scale.x = 1;
}
};
// Will set the Anchor in a one call. (lazy coding)
Sprite.prototype.setOrigin = function(ox,oy) {
this.anchor.x = ox;
this.anchor.y = oy;
};
// Allow Linear Movement for a sprite based on speed time and duration
Sprite.prototype.linear = function(t, b, c, d){
return c * t / d + b;
};

//==============================================================================
// ■ Game_Timer
//------------------------------------------------------------------------------
// The game object class for the timer.
//==============================================================================

//----------------------------------------------------------------------------
// ● overwrite function: update
//----------------------------------------------------------------------------
Game_Timer.prototype.update = function(sceneActive) {
if(sceneActive && this._working && this._frame > 0){
if(Emoji.fixTimer){
if($gameMessage.isBusy()){
this._frames = this._frames;
} else{
this._frames--;
}
} else {
this._frames--;
}
}
};

//===============================================================================
// => END : Game_Timer
//===============================================================================



I just love inputting comment in my stuff 


and I HATE the anonymous functions this a thing's who can complicate so much  our job :/


EDIT : also avoid to copy paste my code xD some of them are incomplete are would not work.
As a base, I got my plug-in running, but without the quick modifications options. Still working on getting that part working in a copy of what I have now.

Original thread: https://forums.rpgmakerweb.com/threads/starting-a-plug-in.57849/