MZ Help in creating a Skill Stat-Based Function to turn into a plug-in

Hi, so I've recently picked up RPGMZ since it was on sale and thought it would be fun to put some stored game concepts into practice. Then, I found out that it's run on JS, a language I utilize the most (or as much as a non-professional student hobbyist would). So, I had fun with this particular concept I liked:

Class "Contractor" playstyle is based on their Skill "Create Contract" which the Caster will average its stats between the Ally Target and itself. It will also be able to learn all of the abilities that the Ally Target has.

For something like this, I'm quite sure that there is no pure vanilla "use the dropdowns" way of making this work, so I decided to code something. So far, I've only done the main concept and it technically works in test battles, but it feels messy (plus the fact I'll have to make sure the Contract---maybe turn into a state as Contractor and Contractee--ends and the Caster loses the stat boost and learned abilities). Although I feel like I can certainly do that as a Common Event that ends, it seems like it should be simpler if I learn to create a plug-in.

I haven't created a plug-in, but from what I see from messing around with function codes in the test battles and viewing a few lines of plugins, would something like this just require creating a function in form with MZ's style?

And the code for reference:

JavaScript:
let gtCs = $dataSystem.variables[98]; // Caster -->
let gtTg = $dataSystem.variables[99]; // Target --> kept in a variable through the formula (yes, I know it's bad, but it's quick and doesn't target an enemy instead)

if (JSON.stringify(gtCs) === JSON.stringify(gtTg)){
$gameMessage.add("A contract cannot be formed with this target.");
} // to make sure the user can't target themselves (haven't tested it on auto)
else {
// HP,MP,ATK,DEF,MAT,MDF,AGI,LUK
gtCs.addParam(0, Math.floor((gtCs.mhp + gtTg.mhp*1.2)/2 - gtCs.mhp));
   gtCs.gainHp(Math.floor((gtCs.mhp + gtTg.mhp*1.2)/2 - gtCs.mhp)); // to supplement the boosted HP that doesn't regen
gtCs.addParam(1, Math.floor((gtCs.mmp + gtTg.mmp*1.2)/2 - gtCs.mmp));
   gtCs.gainMp(Math.floor((gtCs.mmp + gtTg.mmp*1.2)/2 - gtCs.mmp)); // same as above (only kept the archaic code since I originally thought something was wrong with this code)
gtCs.addParam(2, (gtCs.atk + gtTg.atk*1.2)/2 - gtCs.atk);
gtCs.addParam(3, (gtCs.def + gtTg.def*1.2)/2 - gtCs.def);
gtCs.addParam(4, (gtCs.mat + gtTg.mat*1.2)/2 - gtCs.mat);
gtCs.addParam(5, (gtCs.mdf + gtTg.mdf*1.2)/2 - gtCs.mdf);
gtCs.addParam(6, (gtCs.agi + gtTg.agi*1.2)/2 - gtCs.agi);
gtCs.addParam(7, (gtCs.luk + gtTg.luk*1.2)/2 - gtCs.luk);

// ADD SKILLS
    // Basically just looked at actor objects and just messed around and saw this worked
for (var i=0; i<gtTg.skills().length; i++){gtCs.learnSkill(gtTg.skills()[i].id);}
    // If there was a simpler way to just make this a state, that would be actually great
    // Maybe a plugin that makes a custom state and adds skills as traits with each use of the skill-- of course rewriting previous state (is this a good idea?)

    // State -> Add Skill Type
let gtClassNM = $dataClasses.find(x => x !== null && gtTg._classId).name
// Since I couldn't find a particular way to fix this, I ended up finding that making this a state was much more efficient
    // And the [] of just the Class to Skill Types matching because I forgot they all have IDs
    if (["Soldier","Mercenary"].includes(gtClassNM)) {gtCs.addNewState(45);} // Sword
    if (["Merchant"].includes(gtClassNM)) {gtCs.addNewState(46);} // Spear
    if (["Archer","Hunter"].includes(gtClassNM)) {gtCs.addNewState(47);} // Bow
    if (["Soldier","Mercenary","Merchant","Nomad"].includes(gtClassNM)) {gtCs.addNewState(48);} // Shield
    if (["Nomad"].includes(gtClassNM)) {gtCs.addNewState(49);} // Fist
    if (["Priest","Nomad"].includes(gtClassNM)) {gtCs.addNewState(50);} // Healing

$gameMessage.add(gtCs.nickname() + " formed a contract with " + gtTg.nickname()); // For text purposes


}
Welcome!

I think you should mess around a little bit more with making stuff in RPG Maker to be comfortable with how its systems work, then take some time to read through some existing plugins and see how they work.

The way you're doing this going through all of the $data objects is going to both make things harder for you and possibly lead to problems when the actual game objects you're interacting with don't match up with their database entries.

For example, actors can be renamed.

Plus, you can't do any of your actual modifications to those $data objects, you have to use the in-game objects and datatypes.

I'm not sure what you have around/leading up to this, but dealing with $dataSystem.variables seems completely wrong. That only stores the names of the variables as the user has entered them in the editor - it doesn't have anything to do with their value. Then why would you run it through JSON.stringify()? They're already strings, why would you want them in JSON format just to see if they're the same? You can perform equality comparisons on regular strings.

Then you try to add parameters to them which will just fail, because gtCs isn't any kind of object with parameters, it's a string.

I think you're just confused/not yet knowledgeable of what the data types are and how they're used. You may find this useful - it's written for MV, but the majority of the structures are the same.

But I think you just want to spend some time reading the code. Decide you want to figure out how something works (such as the resolution of an attack) and follow it through the functions in the files in your js folder. Say you want to see how someone else made a modification to something - download the plugin and read through it.

Good luck!
Welcome!

I think you should mess around a little bit more with making stuff in RPG Maker to be comfortable with how its systems work, then take some time to read through some existing plugins and see how they work.

The way you're doing this going through all of the $data objects is going to both make things harder for you and possibly lead to problems when the actual game objects you're interacting with don't match up with their database entries.

For example, actors can be renamed.

Plus, you can't do any of your actual modifications to those $data objects, you have to use the in-game objects and datatypes.

I'm not sure what you have around/leading up to this, but dealing with $dataSystem.variables seems completely wrong. That only stores the names of the variables as the user has entered them in the editor - it doesn't have anything to do with their value. Then why would you run it through JSON.stringify()? They're already strings, why would you want them in JSON format just to see if they're the same? You can perform equality comparisons on regular strings.

Then you try to add parameters to them which will just fail, because gtCs isn't any kind of object with parameters, it's a string.

I think you're just confused/not yet knowledgeable of what the data types are and how they're used. You may find this useful - it's written for MV, but the majority of the structures are the same.

But I think you just want to spend some time reading the code. Decide you want to figure out how something works (such as the resolution of an attack) and follow it through the functions in the files in your js folder. Say you want to see how someone else made a modification to something - download the plugin and read through it.

Good luck!
Thanks!

My main issue (which why I was being lazy and storing actor objects through variables by using skill formulas, then calling the script) was that I couldn't find the right function to get the target of the skill and the caster of it when I looked through the possible calls. I'll be staring at the doc and look for the particular call I'm looking for. I'll probably be looking instead at creating custom states and see how I can do that since they're not permanent. Once I get the hang of it, I'll probably just stare at lots of the more simpler plugins and try to make it more flexible for possibly other use cases.
My main issue...was that I couldn't find the right function to get the target of the skill and the caster of it
So...I don't know how you're trying to do your research. But if I Google "RPG Maker MZ script call current target," the fourth result
shows that BattleManager._targets is an array of the targets of the current action.

Similarly, if I Google "RPG Maker MZ script call current battler," the first result
gives you BattleManager._subject

If I didn't want to Google it for some reason, I might grep the js directory for "damage" because I know the damage formula has to be able to reference both battlers. It's safe to assume this has nothing to do with sprites or windows. The 13 results in rmmz_managers are clearly not relevant.

So then we scroll through the results in rmmz_objects, and the 12th one is obviously pay dirt - Game_Action.makeDamageValue() is what we want by the name, and takes the target as an argument.

Once you've found that, you should be able to search forward and backward to find the actual code of makeDamageValue() to see how the current battler is referenced, and you can also backtrack the functions it's called from to see how target is come up with in the first place.

Or you could go to the pinned MV/MZ script call list

Clicking the link to the "Battle" section has, right near the top,
1689982396099.png


Good luck!
So...I don't know how you're trying to do your research. But if I Google "RPG Maker MZ script call current target," the fourth result
shows that BattleManager._targets is an array of the targets of the current action.

Similarly, if I Google "RPG Maker MZ script call current battler," the first result
gives you BattleManager._subject

If I didn't want to Google it for some reason, I might grep the js directory for "damage" because I know the damage formula has to be able to reference both battlers. It's safe to assume this has nothing to do with sprites or windows. The 13 results in rmmz_managers are clearly not relevant.

So then we scroll through the results in rmmz_objects, and the 12th one is obviously pay dirt - Game_Action.makeDamageValue() is what we want by the name, and takes the target as an argument.

Once you've found that, you should be able to search forward and backward to find the actual code of makeDamageValue() to see how the current battler is referenced, and you can also backtrack the functions it's called from to see how target is come up with in the first place.

Or you could go to the pinned MV/MZ script call list

Clicking the link to the "Battle" section has, right near the top,
View attachment 270219

Good luck!
Yeah, I originally wanted to do this (searched a few keywords to find things that could suit this) but when I tried to log it (BattleManager), it returned an empty array (targets) and null (the user) when I tested it with both skills that targeted one actor, or multiple enemies. I'll probably have to find a real fix since I've seen others reference this and have no issue, but I also saw on the first link when I originally had this idea to use the Formula and Variable list (in which the two variables are not held in a String, but rather as Game_Actor--which I could actually add in stuff and have the rest work). Which, was extremely useful, but there had to be a less BS way of doing that even though there's nothing game-breaking about it. ---At this point, I'm trying to make a Skill in which their main happenings need to occur in a script (so, I was making a Common Event to test it out). Originally needed some planning ideas on how to interpret that into a Plugin, but recently realized that out of all things I needed to do, this was probably the least "Plugin" I have to do. (Since I started this project with an idea and the mentality to script things myself to improve on coding and thought of this as a perfect idea to start)

So, I ended up lessening the annoyance by just rewriting a blank state meant specifically for the skill since directly pushing a state seemed extremely off (even though actor states aren't by IDs but rather the actual object). Though the above methods didn't work for some reason (as well as adjacent methods as I tried looking at the "parent") and looking through the code to see how the function is called doesn't exactly seem helpful (and backtracking didn't lead me to a particular call to the target, as well as adjacent calls related to them) unless I want to mess with it all the time for battles (but this is just one skill I need to call). I have looked through the rmmz_objects and manager, Crtl+F "target" without much results earlier when I was trying to do this myself, and even now, jumping to "targetsForEveryone" and the related functions didn't lead me to a clear answer.

BattleManager._action's "_targetIndex" was also not the correct index (even though the skill was correct), so I couldn't use that either. So, when I looked at another adjacent issue when searching this issue, $GameTemp seemed perfect for what I was looking for and replaced the dumber previous method. Well, I'll find it eventually, so I'll just close this for now since I no longer need to make a plugin at the moment and will search for more options and look at the JS files again. Thanks for your help, though!
This thread is being closed at OP’s request. If you would like it reopened, report it to us to let us know why. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/help-in-creating-a-skill-stat-based-function-to-turn-into-a-plug-in.159544/