So I am trying to make a plugin and came up with the script for it. Though every time I go to enter a command, it brings up that it isn't defined. So how would I make a plugin command in the script so that it would work? Is there a specific thing I must do?
MV How to plugin command?
Learning JavascriptThe specifications for plugin commands are in the help file under Contents -> Documentation -> Plugin Specifications
But you can also just call any function you put in the plugin using the Script box instead of the Plugin Command box.
But you can also just call any function you put in the plugin using the Script box instead of the Plugin Command box.
First I just need to ask if you're trying to do a plugin command and have the plugin command include a space. If so that could be the underlying problem.
Either way perhaps this example will help:
Let's say we want to make a plugin command be "Example Command"
& then get the passed arguments after that..
A plugin command with a space would be done something like this:
JavaScript:
/*=============================================================================*\
* CTB Plugin Command Example
* By CT_Bolt
* CTB_PluginCommandExample.js
* Version: 1.00
* Terms of Use:
* Free for commercial or non-commercial use
*
/*=============================================================================*/
var CTB = CTB || {}; CTB.PluginCommandExample = CTB.PluginCommandExample || {};
var Imported = Imported || {}; Imported["CT_Bolt PluginCommandExample"] = 1.00;
//=============================================================================//
/*:
* @plugindesc [RPG Maker MV] [Tier 0] [Version 1.00] [CT_Bolt - Plugin Command Example]
* @author CT_Bolt
*
* @help
* CT_Bolt's Plugin Command Example
* Version 1.00
* CT_Bolt
*
* This plugin is a to show an example of a plugin command
*/
//=============================================================================
//=============================================================================
"use strict";
(function ($_$) {
function getPluginParameters() {var a = document.currentScript || (function() { var b = document.getElementsByTagName('script'); return b[b.length - 1]; })(); return PluginManager.parameters(a.src.substring((a.src.lastIndexOf('/') + 1), a.src.indexOf('.js')));} $_$.params = getPluginParameters();
// Alias the pluginCommand function from the Game_Interpreter
$_$['Game_Interpreter.prototype.pluginCommand'] = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
$_$['Game_Interpreter.prototype.pluginCommand'].apply(this, arguments);
console.log('Real Plugin Command is "Example Command"');
console.log('but.. what the interpreter gets for a command is...');
console.log('Plugin Command: "' + command + '"');
var fullCommand = (command + args[0]).toLowerCase();
if (fullCommand.includes('example') && fullCommand.includes('command')){
this.exampleCommand(args);
};
};
// New Game_Interpreter function called "exampleCommand"
Game_Interpreter.prototype.exampleCommand = function(args) {
if (!args) return;
console.log('Args: ');
console.log(args);
console.log('List of wanted plugin parameters:');
args = args.filter(function(arg){arg = arg.trim().toLowerCase(); return arg !== 'command' && arg !== ':'});
args = args.map(function(arg){return removeCommas(arg)});
console.log(args);
};
// Function to remove unwanted commas
function removeCommas(str) {
if (str.startsWith(',') && str.endsWith(',')) {
return str.slice(1, -1);
}
if (str.startsWith(',')) {
return str.slice(1);
}
if (str.endsWith(',')) {
return str.slice(0, -1);
}
return str;
}
})(CTB.PluginCommandExample);
So that would be used something like this:
Then from that example what is printed to the console would be this:
Also the way that I set up that example doesn't require specific capitalization of the command or require the ":" and also strips commas from the ends of the parameters.
Meaning the plugin command could also be called like this:
& then the printed console log would be like this:
Hope all this makes sense to ya
I've also attached the plugin for an example of how to use the example plugin command I shown above to do what I printed to the console.
Hope that's helpful?
Original thread: https://forums.rpgmakerweb.com/threads/how-to-plugin-command.147596/