MV Fixes to WAY_SRD_EquipmentCompareUpgrade

Hey all, thanks for checking this.

I'm looking for a fix for Waynee95's mod for SRD's Equipment Compare Upgrade. <- Links here

The former adds a feature to the latter that allows it to show the effects of the currently equipped item (rather than nothing at all) on the equip summary (whereas SRD takes over for the actual swap). It has exactly what I'm looking for, but has two issues that rather need addressing:

1. Kind of a big one: It doesn't actually get the right parameters at all (lol). I guess the TP didn't actually use it in the end. But it seems to add +1 to the parameter index or something wild. For example, this Cudgel:
1780501410799.png

Shouldn't show this at all, it should be +ATK/+MAT (or Physical/Ether Power), not MP/DEF:
1780501486148.png


2. As it mentions in the request, this does not extend to the extra parameters added by SRD's plugin. I'm using those extras to enable the Equip menu to show Elemental and State Resistances in the Equip Menu, so I'd like them to show up, as that's really the main point of using the SRD plugin in the first place, so we can see this:
1780501730253.png

Thank you all kindly in advance. 🙂
You can edit the Waynee plugin, an example below. Here I edited the plugin file directly.

To make it show the correct parameter, I added +1 to where it says _this.drawParamName(y, paramId + 1);

Then after the loop I added a conditional to check to make it show trait values. In the example I added hit rate. You can change it and copy-paste to add more below. Since you only have three, you can just write the stuff for them all. You might need to change x positions if you have long names. You could probably loop them, but I don't have motivation to check the plugin properly to see how it stores all the data. So I just wrote it one at a time. You need to check in console what is the trait code for the stuff you want to show.

Window_StatCompare.prototype.drawItemParams = function (item) {
var _this = this;

var line = 0;
item.params.forEach(function (param, paramId) {
if (param !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.drawParamName(y, paramId + 1);
_this.changeTextColor(_this.paramchangeTextColor(param));
var text = param > 0 ? '(+' + param + ')' : '(' + param + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
});
if (item && item.traits.find(trait => trait.code === 22)) {
const value = item.traits.find(trait => trait.code === 22).value * 100;
if (value !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.changeTextColor(this.systemColor());
_this.drawText("Hit Rate", x, y, _this.contents.width / 2 - _this.textPadding(), 'left');
_this.changeTextColor(value > 0 ? "#80ff80" : "#c08080");
var text = value > 0 ? '(+' + value + '%' + ')' : '(-' + value + '%' + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
}
};

EDIT: Oh I realized that you wanted to show all element and state resistances, so you'd have much more than three. So you want to make loop out of it. But yeah anyway you can use what I wrote as basis.
You can edit the Waynee plugin, an example below. Here I edited the plugin file directly.

To make it show the correct parameter, I added +1 to where it says _this.drawParamName(y, paramId + 1);

Then after the loop I added a conditional to check to make it show trait values. In the example I added hit rate. You can change it and copy-paste to add more below. Since you only have three, you can just write the stuff for them all. You might need to change x positions if you have long names. You could probably loop them, but I don't have motivation to check the plugin properly to see how it stores all the data. So I just wrote it one at a time. You need to check in console what is the trait code for the stuff you want to show.

Window_StatCompare.prototype.drawItemParams = function (item) {
var _this = this;

var line = 0;
item.params.forEach(function (param, paramId) {
if (param !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.drawParamName(y, paramId + 1);
_this.changeTextColor(_this.paramchangeTextColor(param));
var text = param > 0 ? '(+' + param + ')' : '(' + param + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
});
if (item && item.traits.find(trait => trait.code === 22)) {
const value = item.traits.find(trait => trait.code === 22).value * 100;
if (value !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.changeTextColor(this.systemColor());
_this.drawText("Hit Rate", x, y, _this.contents.width / 2 - _this.textPadding(), 'left');
_this.changeTextColor(value > 0 ? "#80ff80" : "#c08080");
var text = value > 0 ? '(+' + value + '%' + ')' : '(-' + value + '%' + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
}
};

EDIT: Oh I realized that you wanted to show all element and state resistances, so you'd have much more than three. So you want to make loop out of it. But yeah anyway you can use what I wrote as basis.

Yes, I need it for all elements (9 of them) and all the "regular" status effects (15), as well as the sparams and xparams.

I'm pretty sure I don't want to loop through ALL my states (there's like 350 already, many of which are not relevant for the player and don't appear on equipment in any case). And, due to silliness with my database, the regular status effects are not in a nice row, part of why it's nice to define where they are with the settings of SRD, as can be seen here (states 2,5,7,8,9,14-19,22-24, and 28):
1780559313740.png


So is there a simple way to hook into/steal what SRD's plugin is already doing to iterate through the definitions there? That's basically what I was hoping. It's a short actual plugin (1700 lines are just the setup, it's only like 200 itself).
I'm assuming it's stealing the loop under the tempactor comparison, so if I were to kind of stitch together what the two are doing, I guess a loop would be something like this?
Code:
        let place = 0;
        var _this = this;
        for(var i = 1; i < _.names.length; i++) {
            if(_.names[i]) {
                var y = line * _this.lineHeight();
                _this.drawDarkRect(place, y, _this.contents.width, _this.lineHeight());
                this.drawItem(0, place * this.lineHeight(), i);
                place++;
                }
            }
        }
I meant loop through the traits, not all your states.

The code above fixed the showing of correct param name. And shows an example how to draw the other stuff.

I can check the code sometime later unless someone else does it. It's probably not hard, I just don't like it when they're inside the iife not accessible and stuff is named like _
Yep, sorry if I didn't sound appreciative, it's given me a basis to work on.

I've handled quite a lot of code by myself lately, but there are still a few things that, whilst I can probably eventually get there, it's just more economical to ask.

Incidentally, that snippet retrieves ALL the XParams, but calls them all "Hit Rate" which is pretty funny. Guess I've got to make it find the name of the XParam its representing rather than being a constant.

EDIT: Hm, it's rather tougher than first expected, can't just hack a loop based on the normal params method. Looks like it needs some new methods as noted on this topic here.
If you meant that code I posted above, I made it draw text "Hit Rate" since at that time I thought you only needed to show a couple of stuff that you could add individually and change what it says.

I checked the code again and yeah, that SRD plugin scans the plugin data, but since it's inside iife, as far as I understand, you can't use that data anywhere else. So you'd have to do that same thing in the WAY patch or put the patch functionality inside the SRD plugin.
But anyway, the bigger problem is that the SRD plugin gets the values by checking what your total value is and comparing it to what total value is if you change the equipment. But for that WAY patch stuff you don't need total values or comparison values, but the trait value of the current equipment.

Don't think there's any other way to do that than to check the _slotWindow item and then check the traits. Code for state resists seems to be 13 and code for element resist seems to be 11. Then they have the dataId value which is state id or element id and then the value. Then when drawing the names you can get the names with the ids from $dataStates and $dataSystem.elements

So loop through the weapon/armor traits and check all of those codes and draw the info, something like change the WAY patch draw method in the patch plugin:

Window_StatCompare.prototype.drawItemParams = function (item) {
var _this = this;
var line = 0;
item.params.forEach(function (param, paramId) {
if (param !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.drawParamName(y, paramId + 1);
_this.changeTextColor(_this.paramchangeTextColor(param));
var text = param > 0 ? '(+' + param + ')' : '(-' + param + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
});
item.traits.forEach(trait => {
let value = 0;
let dataId = 0;
let name = "";
if (trait.code === 13) {
dataId = trait.dataId;
name = $dataStates[dataId].name;
value = (trait.value * 100);
}
if (trait.code === 11) {
dataId = trait.dataId;
name = $dataSystem.elements[dataId];
value = (trait.value * 100);
}
if (value !== 0) {
var x = 0;
var y = line * _this.lineHeight();
_this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
_this.changeTextColor(this.systemColor());
_this.drawText(name, x, y, _this.contents.width / 2 - _this.textPadding(), 'left');
_this.changeTextColor(value > 0 ? "#80ff80" : "#c08080");
var text = value > 0 ? '(+' + value + '%' + ')' : '(-' + value + '%' + ')';
_this.drawText(text, x, y, _this.contents.width / 2 - _this.textPadding(), 'right');
line++;
}
})
};

That one seemed to work for me, though you might want to position stuff a bit if you have long names.
Yep, that works fine for showing the elements and states. I tweaked it slightly to add a string after/before. Now just need to figure out the xparams and sparams names. I did try the obvious, copying the states one, retrieving the code from RPG_Objects, to tack this in:
Code:
    if (trait.code === 22) {
        dataId = trait.dataId;
        name = $dataSystem.xparam[dataId].name;
        var name2 = ' ' + name;
        value = (trait.value * 100);
        }
    if (trait.code === 23) {
        dataId = trait.dataId;
        name = $dataSystem.sparam[dataId].name;
        var name2 = ' ' + name;
        value = (trait.value * 100);
        }
But clearly that's not how I'm supposed to access that data and it returns a null. I was thinking that it's probably not in dataSystem in this case. Possibly trait.dataId needs to also be param.dataId or similar, though these are stored as traits as well.

EDIT Hm, so just replacing name with 'foo' as a string does correctly retrieve the numerical values, it's just getting it correctly retrieve the name of the xparam. Tried a few Game_Actor things as well, and Game_BattlerBase. Mayhap I have to set up all the names first.
Code:
    if (trait.code === 22) {
        dataId = trait.dataId;
        name = 'fooo'; //Game_Actor.xparam[dataId].name;
        var name2 = ' ' + name;
        value = (trait.value * 100);
        }
Looking at Eli's Dynamic Parameters for inspiration, and yeah, it seems like he defines all the xparam and sparam names into an array. Yanfly's Extra Param Formulae also scans for param names and changes them to numbers. Guess that is required, ugh.
Cool.

And if you also want to show those x-params and s-params, didn't you already write those in the SRD plugin? You can imitate how it gets the names. Though if I remember correctly it declared and used something like plain _ for stuff. You might need to change that.
Anyways, the result of the matter was me defining the sparams and xparams:
Code:
    Window_StatCompare.prototype.drawItemParams = function (item) {
    var _this = this;
    var line = 0;
    function getBattlerParamNameX(xparamId) {
    const paramMap = {
        0: 'Accuracy',
        1: 'Evasion',
        2: 'Critical Hit Chance',
        3: 'Critical Avoid',
        4: 'Magic Evasion',
        5: 'Reflection',
        6: 'Counter Rate',
        7: 'Vitality Regeneration',
        8: 'Ether Rejuvenation',
        9: 'Conviction Restoration'
    };

    return paramMap[xparamId] || 'unknown';
}
    function getBattlerParamNameS(sparamId) {
    const paramMap = {
        0: 'Target Rate',
        1: 'Guard Damage Reduction',
        2: 'Healing Bonus',
        3: 'Medical Expertise',
        4: 'Ether Multiplier',
        5: 'Conviction Multiplier',
        6: 'Physical Damage Reduction',
        7: 'Magical Damage Reduction',
        8: 'Environmental Damage',
        9: 'Experience Gain'
    };

    return paramMap[sparamId] || 'unknown';
}
    item.params.forEach(function (param, paramId) {
        if (param !== 0) {
            var x = 0;
            var y = line * _this.lineHeight();
            _this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
            _this.drawParamName(y, paramId + 1);
            _this.changeTextColor(_this.paramchangeTextColor(param));
            var text = param > 0 ? '[' + param + ']' : '[-' + param + ']';
            _this.drawText(text, x, y, _this.contents.width / 1.65 - _this.textPadding(), 'right');
            line++;
        }
    });
    item.traits.forEach(trait => {
    let value = 0;
    let dataId = 0;
    let name = "";
    if (trait.code === 11) {
        dataId = trait.dataId;
        name = $dataSystem.elements[dataId];
        var name2 = ' ' + name + ' Damage Reduction';
        value = ((trait.value + 0.1) * 10);
        }
    if (trait.code === 13) {
        dataId = trait.dataId;
        name = $dataStates[dataId].name;
        var name2 = ' ' + name + ' Resistance';
        value = ((trait.value + 0.1) * 10);
        }
    if (trait.code === 22) {
        dataId = trait.dataId;
        var name2 = ' ' + getBattlerParamNameX(dataId);
        value = (trait.value * 100);
        }
    if (trait.code === 23) {
        dataId = trait.dataId;
        var name2 = ' ' + getBattlerParamNameS(dataId);
        value = (trait.value * 100);
        }
    if (value !== 0) {
        var x = 0;
        var y = line * _this.lineHeight();
        _this.drawDarkRect(x, y, _this.contents.width, _this.lineHeight());
        _this.changeTextColor(this.systemColor());
        _this.drawText(name2, x, y, _this.contents.width / 2 - _this.textPadding(), 'left');
        _this.changeTextColor(value > 0 ? "#80ff80" : "#c08080");
        var text = value > 0 ? '[' + value + '%' + ']' : '[-' + value + '%' + ']';
        _this.drawText(text, x, y, _this.contents.width / 1.65 - _this.textPadding(), 'right');
        line++;       
    }
    })
};
Which works fine:
1780694634583.png

Albeit there's a slight misalignment in normal params vs. everything else, because it seems this.drawParamNamedoesn't accept an X value without disappearing, so it differs to the this.drawtext.
Also slight weirdness with the elements apparently always changing 10% to 9%, but apparently I can't add a math.ceil to the value without causing a crash, so I just add 0.1 to the value.
I then slightly shuffled SRD's X-Coordinates so that when you click between the item stats and item comparison more seamlessly without the text jumping about. Looks smooth.

Just one final problem. I cannot, for the life of me, get this bloody right-arrow to move in SRD's code.
1780694512054.png
You would think it was the this.drawRightArrow(x + this.width - (312 - 188), y); but apparently, even commenting that out does nothing to the arrow. Any ideas for this?
The misaligment is because you're using:
drawText with var x = 0;
drawParamName uses const x = this.textPadding(); (which is 6)
So you can just put var x = this.textPadding(); instead of 0
(At least for me the normal param name was more to the right than for example element resistance)

Don't know what's causing you having to add to the trait percentage, seemed to work for me. Quickly checking your code it seems you're only multiplying the value by 10 instead of 100 though. How does that work?

For the arrow thing, if you're using Yanfly Equip Core, doesn't the drawItem method for the Window_StatCompare come from that? So you'd have to edit that Yanfly method, I think.
EDIT: meaning that SRD doesn't even define a drawItem for that window
The misaligment is because you're using:
drawText with var x = 0;
drawParamName uses const x = this.textPadding(); (which is 6)
So you can just put var x = this.textPadding(); instead of 0
(At least for me the normal param name was more to the right than for example element resistance)

Don't know what's causing you having to add to the trait percentage, seemed to work for me. Quickly checking your code it seems you're only multiplying the value by 10 instead of 100 though. How does that work?

For the arrow thing, if you're using Yanfly Equip Core, doesn't the drawItem method for the Window_StatCompare come from that? So you'd have to edit that Yanfly method, I think.
EDIT: meaning that SRD doesn't even define a drawItem for that window
Thankyou, that fixes the misalignment.

I'm multiplying by 10 because I want to show the actual bonus given on the page, not the rate. i.e. This item is giving +10% Resist to Burning Damage, not 100%. So we see:
1780733884518.png

And on the database it's:
1780733979567.png

The Rate is 90%, so it should be a 10% reduction in damage, yeah?
In fact, I fixed this after that post, apparently I was just doing something dumb before. It's now:
value = (Math.ceil(1 - trait.value) * 10);
And that works fine.

I'll have to look into that Yanfly method for the arrow then, thanks, that gives me a place to look.

EDIT: Yay, fixed!
1780735572893.png
Actually the value = (Math.ceil(1 - trait.value) * 10); was in fact broke, it just so happened my test items were 10% (le sigh). Good job I had one character with 5% on one thing which made me double take it was still showing 10%. The correct version is value = Math.ceil((1 - trait.value) * 100);

Anyways, all resolved now I think, I'll ask it to be closed.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/fixes-to-way_srd_equipmentcompareupgrade.183898/