RMMZ Javascript code to run plugin command?

poorrabbit

Veteran
Veteran
Joined
Mar 15, 2014
Messages
84
Reaction score
55
First Language
english
Primarily Uses
RMMZ
I apologize if this is already covered somewhere, but I've googled and binged my way across half the internet and can't find the answer...and least, not one that I understand....

I have a couple of plugins that do exactly what I want, but plugin commands are only available via events (common or otherwise), and I would very very much like to use their functionality through scripting.

Is there a standard way in MZ, using javascript, to run a plugin command?
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,789
Reaction score
7,876
First Language
German
Primarily Uses
RMMV
no, because that would be doing it backwards.

the plugin commands are already a complex interface to allow events to call on javascript functions without programming knowledge. If you are already in javascript, you should call those functions directly instead of making a wrapper to call a wrapper that does nothing but call functions you can already call directly.

what you need to do is go to those parts of a plugin that handles plugin commands, check which internal function those plugins call after analysing the plugin commands, and then call those functions directly.
 

Featherbrain

Prehistoric Gamer
Veteran
Joined
Jan 12, 2020
Messages
106
Reaction score
190
First Language
English
Primarily Uses
RMMV
I don't know a "standard" way necessarily, but if you understand a little javascript, it's usually fairly straightforward to track down the functions and arguments that the plugin commands are actually calling, and just call those functions directly with script calls.

Easiest way is to do a "find" on the exact, case-sensitive plugin command. Look for where that command is taken as a string argument by a function that looks like it's handling plugin commands, e.g. in MZ I believe it would look like "PluginManager.registerCommand(x, y, z)"--the command you're looking for should be one of the x, y, or z string arguments being passed to that function. When you find the function that's taking that plugin command as an argument, you've most likely found the code that is run when you use that plugin command. You can then grab that code, manually setting any necessary arguments that would have been passed in the plugin command, and use it as a script call.
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,226
Reaction score
1,634
First Language
EN
Primarily Uses
RMMZ
JavaScript:
PluginManager.callCommand(self, pluginName, commandName, args);
  • self is a Game_Interpreter reference;
  • pluginName is the name of the plugin (string) without the ".js" extension;
  • commandName is the name of the command (string);
  • args is an object in the form {paramName1: value, paramName2: value, ...}.
Example: ButtonPicture is a plugin present by default in new RMMZ projects. To call its plugin command, set, try this in a Script command:
JavaScript:
PluginManager.callCommand(this, 'ButtonPicture', 'set', {
  pictureId: 1,
  commonEventId: 5
});
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,548
Reaction score
3,297
First Language
Binary
Primarily Uses
RMMZ
1607106165362.png
That is a function from the rmmz_managers.js file. it shows how to trigger a plugin command.

you should be able to then do something like this as a script call:
Code:
const event = this;
const plug_name = "AwesomePlugin";
const comm_name = "BestCommandEv";
const comm_args = "somearg1 somearg2";
PluginManager.callCommand(event, plug_name, comm_name, comm_args);

You MUST actually pass the correct event if you are using some command that would manipulate the event in some way. (if running the script from the desired event, using 'this' as shown above is suitable).

You should replace plug and comm name strings with the relevant strings for your commands. Also, I've never used a plugin command myself, so I'm not entirely sure of the format that 'comm_args' would be in. its either going to be a string with each 'argument' seperated by a space, or an array of strings:
Code:
const comm_args = "somearg1 somearg2"; // spaced string
const comm_args = ["somearg1", "somearg2"];// array


Anyway, hope that helps! :*

edit: damn ninjas. I knew I took too long :D
Oh, seems the comm_args is supposed to be an object as shown by @caethyril ! Nice! Learned something new :D
 
Last edited:

poorrabbit

Veteran
Veteran
Joined
Mar 15, 2014
Messages
84
Reaction score
55
First Language
english
Primarily Uses
RMMZ
no, because that would be doing it backwards.
.......
what you need to do is go to those parts of a plugin that handles plugin commands, check which internal function those plugins call after analysing the plugin commands, and then call those functions directly.
I would love to do that - unfortunately, they're pretty well obfuscated.
The parameters and whatnot are there for me to look at (per the other instruction),
but the actual code....not so much.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,548
Reaction score
3,297
First Language
Binary
Primarily Uses
RMMZ
...unfortunately, they're pretty well obfuscated...
Just in case your not aware - obfuscated code has many additional downsides. Performance impact being a main one. I'm not going to derail your thread, but I recommend looking into it further. :)
 

poorrabbit

Veteran
Veteran
Joined
Mar 15, 2014
Messages
84
Reaction score
55
First Language
english
Primarily Uses
RMMZ
Just in case your not aware - obfuscated code has many additional downsides. Performance impact being a main one. I'm not going to derail your thread, but I recommend looking into it further. :)
I'll keep that in mind. Thanks.
 

Latest Threads

Latest Posts

Latest Profile Posts

Making Houses and Outside on the same map with RPG Maker MV!
Do people actually use buff/debuff function?
Ami


Imagine you (as Miner) Sleep in the Cave,the other side is a Bunch of Golds,how d'you feel?
finally got footage of my main character running around his corrupted street...

Forum statistics

Threads
107,708
Messages
1,031,569
Members
139,844
Latest member
nibas0001
Top