MZ How to convert plugin command from MV to MZ

I am making a plugin, and want to release it for MV and MZ.

I did learn how to make plugin commands for MV, but in MZ this is a bit more complicated.

So this part I have and understand:


JavaScript:
@command ccWait
@text 'Skipping time by waiting'
@desc Run this command to skip hours/days.

However... How , to actually call the plugin command, I have this, which is for MV:
JavaScript:
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);

        if(command === 'ccWait') {
            My Code;
        }
    };

Everything IN the command works. I have tested everything in MV and MZ, and other than creating the plugin command, it is all compatible with both engines.

So how do I convert the last piece of code to trigger a pluggin command in MZ?
You need to add a @command annotation in your plugin's help section (with @arg annotations for any arguments you want it to provide) and then do PluginManager.registerCommand for the actual code. I'll show you the command from my skill select window plugin:

1710510031938.png

1710510042485.png

And then in the editor it looks like this:
1710510208510.png
JavaScript:
        PluginManager.registerCommand("YourPluginName", "ccWait", function(args) {
            // your code
        });
A couple more notes:
  1. If your code includes this (i.e. a reference to the current interpreter) then the registered function needs to be a "full" function(args) { ... } rather than just an arrow function args => { ... }.

  2. If you have already defined the function elsewhere, you can just reference that, e.g.
    JavaScript:
    JDN.ccWait = function(args) { alert("plugin command"); };
    PluginManager.registerCommand("JDN_ClockCore", "ccWait", JDN.ccWait);
You need to add a @command annotation in your plugin's help section (with @arg annotations for any arguments you want it to provide) and then do PluginManager.registerCommand for the actual code. I'll show you the command from my skill select window plugin:

View attachment 298539
View attachment 298540
And then in the editor it looks like this:
View attachment 298541
I kinda understand... 😛

JavaScript:
        PluginManager.registerCommand("YourPluginName", "ccWait", function(args) {
            // your code
        });
Okay, this I understand! And this works!

I had a few issues getting working, but that was my stupid mistake... I did rename a copy of the plugin to have MZ at the end, but I forgot to change the name of my function from JDN_ClockCore to JDN_ClockCore_MZ 😛

A couple more notes:
  1. If your code includes this (i.e. a reference to the current interpreter) then the registered function needs to be a "full" function(args) { ... } rather than just an arrow function args => { ... }.

  2. If you have already defined the function elsewhere, you can just reference that, e.g.
    JavaScript:
    JDN.ccWait = function(args) { alert("plugin command"); };
    PluginManager.registerCommand("JDN_ClockCore", "ccWait", JDN.ccWait);
Does this mean... uhm... Does this mean I can have both MV and MZ triggers in one plugin? That would be amazing, so I won't have to do things twice. 😛

On the other hand... Maybe making 2 plugins (one for MV and once of MZ) is the safe way? I am not overexaggerating when I say I know pretty much nothing about javascript.

----

Guys! The things I learned in the past few days, tripled my javascript knowledge at least. And even though you guys helped me a lot, there is way, way more I learned by using wwwschools, modzilla's library and of course the google docs sheets by... I think it was by Archeia?

Anyhow, long story short... With the help you guys provided me, and everything else I learned by days of working around the clock, I am able to release a real finished and polished product, instead of a half-baked first try! Thank you all for thinking along!
I kinda understand... 😛


Okay, this I understand! And this works!

I had a few issues getting working, but that was my stupid mistake... I did rename a copy of the plugin to have MZ at the end, but I forgot to change the name of my function from JDN_ClockCore to JDN_ClockCore_MZ 😛


Does this mean... uhm... Does this mean I can have both MV and MZ triggers in one plugin? That would be amazing, so I won't have to do things twice. 😛

On the other hand... Maybe making 2 plugins (one for MV and once of MZ) is the safe way? I am not overexaggerating when I say I know pretty much nothing about javascript.

----

Guys! The things I learned in the past few days, tripled my javascript knowledge at least. And even though you guys helped me a lot, there is way, way more I learned by using wwwschools, modzilla's library and of course the google docs sheets by... I think it was by Archeia?

Anyhow, long story short... With the help you guys provided me, and everything else I learned by days of working around the clock, I am able to release a real finished and polished product, instead of a half-baked first try! Thank you all for thinking along!
Yes, if you include both triggers, you can have them in one plugin. MV plugin commands do actually work in MZ too! If you copy/paste one from an MV project to an MZ one, assuming the plugin is compatible it'll still work.
you can make plugin commands like

if (UNTILS.RPGMAKER === "MV") {
// MV plugin commands here
} else {
// MZ command here
}
you can make plugin commands like

if (UNTILS.RPGMAKER === "MV") {
// MV plugin commands here
} else {
// MZ command here
}
UNTILS.RPGMAKER isn't a thing though. 😛

I'm guessing you're thinking of Utils.RPGMAKER_NAME, which would work that way.
you can make plugin commands like

if (UNTILS.RPGMAKER === "MV") {
// MV plugin commands here
} else {
// MZ command here
}
UNTILS.RPGMAKER isn't a thing though. 😛

I'm guessing you're thinking of Utils.RPGMAKER_NAME, which would work that way.

So then I would get this?

JavaScript:
if (Utils.RPGMAKER_NAME === "MV") {
    var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
    
        if(command === 'ccWait') {
            ALL MY CODE;
        }
    } else{
    PluginManager.registerCommand("JDN_ClockCore_MZ", "ccWait", function(args) {
        ALL MY CODE
    });
    }
So then I would get this?

JavaScript:
if (Utils.RPGMAKER_NAME === "MV") {
    var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
    Game_Interpreter.prototype.pluginCommand = function(command, args) {
        _Game_Interpreter_pluginCommand.call(this, command, args);
   
        if(command === 'ccWait') {
            ALL MY CODE;
        }
    } else{
    PluginManager.registerCommand("JDN_ClockCore_MZ", "ccWait", function(args) {
        ALL MY CODE
    });
    }
That would work, yeah.
That would work, yeah.
Thanks. here is what I am going to do, though...

Just to be safe, I am going to finish the last steps of my MV plugin, and then convert it to a MZ plugin. Doing it this way, I have enough time to finish everything before noon tomorrow.

Once I have done all that, I will try to merch them into 1 plugin. For now, just having the plugins ready in time for my stream, has the priority.

Now I know how to convert the plugin commands, and with that I am at least sure to have them ready for both engines in time, which was my main concern.

Thank you all for your help. I really appreciate it. I wouldn't have been able to finish in time without your help. (I already lost hours trying to figure this one out by myself.)
Thanks. here is what I am going to do, though...

Just to be safe, I am going to finish the last steps of my MV plugin, and then convert it to a MZ plugin. Doing it this way, I have enough time to finish everything before noon tomorrow.

Once I have done all that, I will try to merch them into 1 plugin. For now, just having the plugins ready in time for my stream, has the priority.

Now I know how to convert the plugin commands, and with that I am at least sure to have them ready for both engines in time, which was my main concern.

Thank you all for your help. I really appreciate it. I wouldn't have been able to finish in time without your help. (I already lost hours trying to figure this one out by myself.)
One thing to keep in mind is that if your plugin involves the creation of new windows, you'll need separate MV and MZ versions anyway, because MV uses x, y, width and height arguments in the constructor, and MZ ones require a Rectangle object (which is why most MV plugins that involve custom windows crash MZ out of the box)
One thing to keep in mind is that if your plugin involves the creation of new windows, you'll need separate MV and MZ versions anyway, because MV uses x, y, width and height arguments in the constructor, and MZ ones require a Rectangle object (which is why most MV plugins that involve custom windows crash MZ out of the box)
Thanks, but the plugin controls 4 things:
1. Variables (all the time)
2. Actor States (on call and or on transfer)
3. Weather (on transfer)
4 . Tint screen (always whenever day turns night and on transfer when the player move from outdoors to indoors, and visa versa)

Those seem tobwork exactly the same in both engines, so other than the plugin command, I should have no problem.

Ill try to remember than for future plugins, though. Thank you!

Yes, if you include both triggers, you can have them in one plugin. MV plugin commands do actually work in MZ too! If you copy/paste one from an MV project to an MZ one, assuming the plugin is compatible it'll still work.

I have noticed that too!! However, there is no way for the MZ user to create a plugin command in the editor, because it will only allow the MZ way of creating a plugin command.

I did run my MV project in MZ, just to test everything out, and at first I didn't think I'd have a problem, until I actually wanted to use a plugin command. 😛
Thanks, but the plugin controls 4 things:
1. Variables (all the time)
2. Actor States (on call and or on transfer)
3. Weather (on transfer)
4 . Tint screen (always whenever day turns night and on transfer when the player move from outdoors to indoors, and visa versa)

Those seem tobwork exactly the same in both engines, so other than the plugin command, I should have no problem.

Ill try to remember than for future plugins, though. Thank you!



I have noticed that too!! However, there is no way for the MZ user to create a plugin command in the editor, because it will only allow the MZ way of creating a plugin command.

I did run my MV project in MZ, just to test everything out, and at first I didn't think I'd have a problem, until I actually wanted to use a plugin command. 😛
Yeah, it only applies if you created the command in MV and then pasted it in MZ.
Yeah, it only applies if you created the command in MV and then pasted it in MZ.
Yeah. That is actually super cool, for my own use, but I can't sell a plugin working like that. 😛 hahaha.

---

Funfact! So... I was trying to have a script call add states to the party for hunger, thirst and fatique. And I tried 2 methods which both work for state 1 (resulting in game-over) but not for any other state. And I could figure out why...

I couldn't find why, because I assume the mistake was in the code... It wasn't...

1710522861688.png


Can you see why no state was seen after I triggered the sleeping state? 😛 hahaha. (Not a real question. I found the problem.)

Original thread: https://forums.rpgmakerweb.com/threads/how-to-convert-plugin-command-from-mv-to-mz.166821/