MZ Additional Stats (Parameters) without Plugin

This seems to be a popular request, but I have yet to come across a thread that seems to fully answer this question. Most of time, people are pushing toward plugins, but I want to make the code adjustments myself without any plugin help.

I mean, at the end of the day, the plugin is just altering or adding code to existing scripts, no? So, I just need to know all the different places I need to make adjustments. I have been through each .js and jsom file and while I have had some success in getting my new parameters to show in both the Status and Equip windows, I am having trouble with value display. For my new parameter, it just shows "NaN":

param1.png


Here I've gone into the Terms tab in Database Manager and updated the existing 6 stock parameters to give them new names. I also went into the System.jsom and added the Willpower entry in the following code:

"params":["Max HP","Max MP","Strength","Vitality","Intelligence","Wisdom","Agility","Dexterity","Willpower","Hit","Evasion"]

To get this new entry to display in the Status and Equip windows, I had to make a couple of edits to the rmmz_windows.js file. For the Equip Status window, I updated the following:

Window_EquipStatus.prototype.drawAllParams = function() {
for (let i = 0; i < 7; i++) {
const x = this.itemPadding();
const y = this.paramY(i);
this.drawItem(x, y, 2 + i);
}
};

So that it said < 7 versus < 6. This trigged the game to add in my Willpower entry from the System.jsom file.

For the Status window, I made a similar update from 6 to 7 in the following:

Window_StatusParams.prototype.maxItems = function() {
return 7;
};

For the displayed values, these seem to populating based on the Classes.jsom file. Each of my Classes has an entry in this file and there is a "params": entry that lists out all the values for each of the levels for 8 items; the first item relates to the max HP, the second is max MP, and the other 6 relate to the 6 stock parameters.

I thought it would be as simple as adding in a 9 item, which would just sequence itself to my additional parameter, but that was not the case. Adding in the 9th row does nothing.

The question I have is that there is obviously some code somewhere that is linking those rows in the Classes file and similar to the Windows file, this is being limited to 8 and I need to adjust this to look for my new 9th.

Does anyone have any insight?

Thanks!
First of all, there's nothing wrong in not looking for a plugin and learning to modify the code yourself. That's how a lot of coders became coders. However, usual accepted practices dictates that you should do the modifications in a separate file and not modify the original core plugins.

As for your issue, it's probably because you create a new parameter without creating it in the code. Parameters aren't value stored in objects by default in RM, they are math functions determined by the database (see the Class tab). To get the current parameter of an actor the game just use the level as x in the function f(x). Of course, it then adds equip values on top.

My point is that you created a new parameter but you haven't modified all the necessary parts in the code to accommodate that new parameter.

It's more complicated then you think, but it's not that complicated. See the Game_BattlerBase.prototype.param function for instance, which is the base of how parameters are calculated in game. But then, Game_Actor is a subclass of that and changes part of that, see for example Game_Actor.prototype.paramBase.

TLDR: You haven't created how the parameter is calculated in the code, so when it tries to calculate the value of that parameter it gets nothing, hence the NaN.
Appreciate the feedback. I kind of understand that I haven't modified all the necessary parts, and so I am looking for specific guidance on where to make all those changes. The two functions you mention don't don't seem to get me there.

They just look like they return a value for a particular parameter that is passed. The question is where do I need to create this new parameter so the game knows to feed this new parameter ID into those functions to get the appropriate value?

In the rmmz_objects.js file, there is the following:

Object.defineProperties(Game_BattlerBase.prototype, {
// Hit Points
hp: {
get: function() {
return this._hp;
},
configurable: true
},
// Magic Points
mp: {
get: function() {
return this._mp;
},
configurable: true
},
// Tactical Points
tp: {
get: function() {
return this._tp;
},
configurable: true
},
// Maximum Hit Points
mhp: {
get: function() {
return this.param(0);
},
configurable: true
},
// Maximum Magic Points
mmp: {
get: function() {
return this.param(1);
},
configurable: true
},
// ATtacK power
atk: {
get: function() {
return this.param(2);
},
configurable: true
},
// DEFense power
def: {
get: function() {
return this.param(3);
},
configurable: true
},
// Magic ATtack power
mat: {
get: function() {
return this.param(4);
},
configurable: true
},
// Magic DeFense power
mdf: {
get: function() {
return this.param(5);
},
configurable: true
},
// AGIlity
agi: {
get: function() {
return this.param(6);
},
configurable: true
},
// LUcK
luk: {
get: function() {
return this.param(7);
},
configurable: true
},
// WILlpower
wil: {
get: function() {
return this.param(8);
},
configurable: true
}

And so, I added a new entry for Willpower just under Luck and set this.param(8). My thought was that this would get picked up by game engine, but I'm not really sure where to set the values for this.

Like I said, in the Classes.json, it looks like there are entries to assign the 0-100 level values for each of the parameters 0 through 7 in the list above, but adding in an additional row for 8, doesn't seem to work.

What's more is that in changing the window file to allow for 7 visible parameters versus the default 6 (where it starts +2 to avoid displaying max HP and MP), the display glosses right over the fact that I created this param(8) and displays Hit Rate instead, which is xparam(0).

Somewhere the game knows that this is only 8 total param (0-7) and what follows is the xparams. I don't know how to make it understand that there is now param(8).

Thoughts?
The functions I listed are where the parameters are called and calculated from in the game. What you listed is just the part of creating the setter and the getter to get the parameters, it doesn't create them. Just test to see if your modified json file works. Launch the game, open the console and type:
$dataClasses[x].params[y]
Replace x by the class ID of your character and y by the param id (8 for your project I assume?). If it doesn't return you an array of values then that means that there's no data for your parameter.
Thanks for the quick update. So, doing as you said, I actually do get any array when I plug in 8. I guess the question now is the reason I am getting NaN above is because that really isn't the Willpower parameter 8 that I created. I had actually renamed Hit Rate in the Terms tab to Willpower and what is being displayed there is that, so NaN makes sense.

But, any thoughts on how I get the Status and Equip screens to display Willpower the new parameter I created versus Willpower the renamed Hit Rate?
First of all, is your new parameter in your item objects? (by item I mean armors and weapons). If so, it's just an issue of displaying them in the window. If not, then that becomes a bit trickier.

Just a quick note on how parameters work for heroes and enemies. Basically this is the method that calculates a parameter in Game_BattlerBase, which is the mother class for Game_Actors and Game_Battlers:
Code:
Game_BattlerBase.prototype.param = function(paramId) {
    const value =
        this.paramBasePlus(paramId) *
        this.paramRate(paramId) *
        this.paramBuffRate(paramId);
    const maxValue = this.paramMax(paramId);
    const minValue = this.paramMin(paramId);
    return Math.round(value.clamp(minValue, maxValue));
};

Game_BattlerBase.prototype.paramBasePlus = function(paramId) {
    return Math.max(0, this.paramBase(paramId) + this.paramPlus(paramId));
};
So as you can see there are 4 components: paramBase is your battler or actor parameters, paramPlus is your equipment, the 2 others are traits and buffs. Now, for actors the paramBase method is different since it reads from $dataClasses, but you already fixed that part. Now onto the next part, equipment. If your parameter is not in the array data (cause the paramPlus data are kept in an array, search for this._paramPlus) it might return nothing, which might also explain your NaN.

As for displaying a new parameter in new scenes once they are worked into the objects, it's just an issue of finding windows and tweaking them. For instance for the equip scene, one of the window you need to modify is the Window_EquipStatus. Search for Window_EquipStatus.prototype.drawAllParams and you'll need to change it to i < 7 to have your additional parameter (it doesn't show HP and MP, that's why it's 6 and not 8).
I did just update both Weapons and Armors to account for a new parameter, so good call there. And, I have already modified the Window_EquipStatus.prototype.drawAllParams so that i < 7 rather than 6.

Problem is, the 7th item it chooses to display is Hit Rate and not Willpower. It glosses over my param(8) and chooses xparam(0) instead.

param3.png


If I could figure out how to get this choose param(8) instead, I think I'm golden.
So you want it to skip param 7 and display param 8 instead?
Ok, so I figured out why param 8 was being skipped, and it was because I had deleted the entry I made in the System.json at some point. Adding that back in, gets Willpower to show back up instead of Hit Rate.

But, I am also back to square one. The value is still displaying NaN. So, adding the array in Classes, updating my Weapons and Armors files to expand their param lists to 9 instead of 8, and updating the this._paramPlus to allow for 9 instead of 8, did not do the trick.

There's still a NULL value being introduced somewhere to cause the display function to return the NaN.
Check what value each param method returns:
Code:
$gameParty.members()[0].paramBase(8);
$gameParty.members()[0].paramPlus(8);
$gameParty.members()[0].paramRate(8);
$gameParty.members()[0].paramBuffRate(8);
$gameParty.members()[0].paramMax(8);
$gameParty.members()[0].paramMin(8);
If one returns null or undefined, that would be the source of your problem.
My problem is definitely in the paramPlus space. If run any of those calls, I get data back for all but I do not get data back for paramPlus nor do I get anything back for paramBasePlus.

But, I'm scratching my head here. I've updated armors and weapons and I even updated items and enemies (which I don't even think matter here), but I'm not sure where it is getting the NULL value that is throwing the NaN.
ParamPlus definitely points to a problem with equipment. You should go to the function and work it backward to see where it goes wrong.

Original thread: https://forums.rpgmakerweb.com/threads/additional-stats-parameters-without-plugin.129552/