MZ Just trying to figure out how to implement supposedly simple plugin properly

Hi all, I am fairly new to making plugins for RPG Maker MZ, yet I am not new to coding in general. (I normally use Java, Javascript, HTML, CSS, basically some basic coding programs)

Basic Concept for Plugin

The basic function I am trying to have my plugin do is for it to detect if an Armor ID in Equipment Type [ID: 10] matches the Actor ID in the battle party.
---If yes, then check if any party member has it equipped
------If yes, Unequip that party member with that Armor item (I would like to disable the armor from being allowed to be equipped while the matching ID party member is in the battle party, but baby steps)
------If Armor is not equipped then just don't allow that armor to be equipped (again can be found out later)

-Else when the Armor ID in Equipment Type 10 slot does not match any battle party member's Actor ID then just do nothing allow that item to be equipped basically.

The basic idea is that this "Armor" is one of the inactive party members teamed up with one of the main battle party members giving them a boost in power in some way like Attack boost, counter attack, minor auto healing, etc.

Where I'm struggling

I think I have a bit of a handle on how the code except for how to call the plugin. I am unsure of how the game acts to call this plugin. I tried looking up tutorials and feel like a Note tag like system would be good, but I don't fully grasp how that function is being reached.

Would there be a better way to handle this that isn't a notetag? If not then how would I get the notetag that I typed in the Armor notes get called by the plugin itself?

Any help would be appreciated.

Thank you.
Probably the easiest place to implement that is to find the function that is called when equipment is equipped, and stick a call to your function that's doing the heavy lifting there. This way the check is done every time an actor equips gear. Probably include an if statement so it only uses your function when the proper armor type is being equipped.

I won't try to go into detail on how to basically hijack a base function, there's a good tutorial for that hanging around. Just make sure you declare the copy as const, not var, or it won't work. Found that out the hard way. lol

Honestly I feel like most plugins are mostly just hijacking a base function, either to completely rewrite it or simply just add a little to it, so I feel like learning that part is essential.
So one part of your question (how notetags work) I think is most easily grasped by just downloading another plugin that uses them and read how they're parsed.

However, if you are only using this with one specific piece of armor, there's no point in using a notetag - notetags are to supply information to your plugin from a variety of sources.

You would want your plugin to add the check to the changeEquip function and return out of it as necessary.
Probably the easiest place to implement that is to find the function that is called when equipment is equipped, and stick a call to your function that's doing the heavy lifting there. This way the check is done every time an actor equips gear. Probably include an if statement so it only uses your function when the proper armor type is being equipped.

I won't try to go into detail on how to basically hijack a base function, there's a good tutorial for that hanging around. Just make sure you declare the copy as const, not var, or it won't work. Found that out the hard way. lol

Honestly I feel like most plugins are mostly just hijacking a base function, either to completely rewrite it or simply just add a little to it, so I feel like learning that part is essential.

So one part of your question (how notetags work) I think is most easily grasped by just downloading another plugin that uses them and read how they're parsed.

However, if you are only using this with one specific piece of armor, there's no point in using a notetag - notetags are to supply information to your plugin from a variety of sources.

You would want your plugin to add the check to the changeEquip function and return out of it as necessary.


This has been a great help. Thank you Drakkonis and ATT_Turan! I got things in the code to read properly and am happy. I even managed to figure out how the notetag system works, even If I might not need it for this project.

Now when I am implementing the code I have realized one major issue and I have tried looking into this with little success in results. Since I can call when equipment is changed is it also possible to check when Party Positions are changed / moving actors around in the formation?

This check for party formation swapping would help me in finishing this plugin for the game I'm working on.

All help is much appreciated and I will let you know the status of the code when I am done.

Thank you have and have a great night.
Your biggest friend as you try to get into coding for RPG Maker will be Google. With how long it's been out, it's pretty well-documented, and just about everything you could want to know has been asked already.

So while I don't know exactly how you want to "check for" formation changes, I Googled "RPG Maker MV script change party," and the function used to exchange party members is $gameParty.swapOrder()
This has been a great help. Thank you Drakkonis and ATT_Turan! I got things in the code to read properly and am happy. I even managed to figure out how the notetag system works, even If I might not need it for this project.

Now when I am implementing the code I have realized one major issue and I have tried looking into this with little success in results. Since I can call when equipment is changed is it also possible to check when Party Positions are changed / moving actors around in the formation?

This check for party formation swapping would help me in finishing this plugin for the game I'm working on.

All help is much appreciated and I will let you know the status of the code when I am done.

Thank you have and have a great night.
you might want to see this functions
Code:
Scene_Menu.prototype.onFormationOk = function() {
    const index = this._statusWindow.index();
    const pendingIndex = this._statusWindow.pendingIndex();
    if (pendingIndex >= 0) {
        $gameParty.swapOrder(index, pendingIndex);
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.redrawItem(index);
    } else {
        this._statusWindow.setPendingIndex(index);
    }
    this._statusWindow.activate();
};
this execute when you click ok on the formation (run on BOTH first one to choose actor to move AND second one to finalize the new position)

basically if pendingIndex >= 0 and index != pendingIndex
then that means position swapping happen...

if pendingIndex < 0 then the swapping did not happen (case: swapping already happened before or this is the first time you enter the formation)
if index == pending index then the swapping did not happen (case: choosing the same actor to place at the same position as before)

above code is base RPG Maker function btw... if you use other plugin then it's better to alias the Scene_Menu.prototype.onFormationOk
then use this._statusWindow.index() and this._statusWindow.pendingIndex() BEFORE calling the alias (because if after the pending index already changed by the alias function).

something like this:
Code:
var myAliasSceneMenuOnFormationOk = Scene_Menu.prototype.onFormationOk;
Scene_Menu.prototype.onFormationOk = function() {
    var storedIndex = this._statusWindow.index();
    var storedPendingIndex =this._statusWindow.pendingIndex();
    if(storedPendingIndex >= 0 && storedIndex != storedPendingIndex)
    {
    // you can put your code here
    }
//calling the alias here
    myAliasSceneMenuOnFormationOk.call(this);
    if(storedPendingIndex >= 0 && storedIndex != storedPendingIndex)
    {
    // or here
    }
};

hope this help.
you might want to see this functions
Code:
Scene_Menu.prototype.onFormationOk = function() {
    const index = this._statusWindow.index();
    const pendingIndex = this._statusWindow.pendingIndex();
    if (pendingIndex >= 0) {
        $gameParty.swapOrder(index, pendingIndex);
        this._statusWindow.setPendingIndex(-1);
        this._statusWindow.redrawItem(index);
    } else {
        this._statusWindow.setPendingIndex(index);
    }
    this._statusWindow.activate();
};
this execute when you click ok on the formation (run on BOTH first one to choose actor to move AND second one to finalize the new position)

basically if pendingIndex >= 0 and index != pendingIndex
then that means position swapping happen...

Thank you estriole, This has helped tremendously. I have tested out the code and It works the way I wanted. You have also explained how it works wonderfully, that a newbie to plugin creation like me could understand it. Thank you.

I did notice that when I was using the visustella Party System Plugin is causing the Scene_Menu.prototype.onFormationOk to not be called when switching party members, so this is a bit of a wrinkle.

Though with this new information I have narrowed things down and I can use the help that everyone has given me here to finally get this small plugin finally done.

I'm one step closer thanks to everyone here. If I have further questions I will make sure to post them in the future. When I figure this code out I'll make sure to let everyone know I have succeeded!

Thank you once again.



Edit: I managed to get this working with the Visustella Party System plugin by targeting the Formation window Close button. At that point is when I run the rest of my code to make sure all the armor is properly set-up for my party as to who is equipable and who isn't "Equipable".

I have run into the final aspect of my plugin how to activate and deactivate specific armor, but I will start that in a new thread.

Thank you everyone for your help and getting me to this point.

Original thread: https://forums.rpgmakerweb.com/threads/just-trying-to-figure-out-how-to-implement-supposedly-simple-plugin-properly.134462/