YEP_EquipCore Returning NaN in Equipment Formula

Hey all. Another YEP problem for you.

I'm creating a sword that gives its own Base Attack approximately +1% Attack for every 1% HP the player is missing.

I'm using the following note tag on the sword in question:

<Custom Parameters>
atk = 10 * (2 - (hp / maxhp))
</Custom Parameters>

As far as I can tell, this is valid JavaScript. In theory, if the player was at 2 out of 10 HP this should return 10 * 1.8, or 18 Attack. Instead, it returns NaN leading me to believe that there's something wrong with my use of "atk", "hp", or "maxhp".

I know that RPG Maker MV addresses max HP as "mhp" internally, while the Yanfly mod addresses it as "maxhp", and I've tried both and received the same result.
It actually seems that the plugin uses "HP", "MAXHP", and "MAX HP" all as acceptable forms for the player's maximum HP... but I can't find a way to find the player's current HP for use the in the formula.

Still experiencing problems with this. Does anyone know a way to reword the formula?

Weapon Attack Power = 10 * (2 - (Current HP / Max HP))
It's not possible to use the equipped character's own stats in the formula for equipment notetags for Equip Core, unfortunately, without editing the plugin to allow that.
It's not possible to use the equipped character's own stats in the formula for equipment notetags for Equip Core, unfortunately, without editing the plugin to allow that.

Strange, I'm able to use ATK, DEF, and Max Hp in the formulas just fine on the weapons and armor I've tested, and it works. Like if I type "ATK = HP", it sets it up properly. I'm just having trouble finding out what the "Current HP" stat is. I guess from the sounds of it it doesn't exist.
You're able to use atk, def and max hp because those are stats the weapons and armour are able to raise, but "current HP" isn't something a piece of equipment has a concept of because the parameter formula doesn't link to an actor.

Like it can handle "Raise the max HP of whoever equips this by 100" just fine, but if you try to tell it to involve the current HP of the person who has it equipped it'll fall over trying to calculate what that is *before someone equips it*.

Try doing user.hp / user.mhp and you'll see what I mean. It ends up recursively trying to figure out what user.hp is and exceeds the max call stack, causing the game to crash or slow down massively.

There is however one way you can accomplish this, and that's if the piece of equipment can only be equipped by one character. Then you can do $gameActors.actor(id of actor).hp / $gameActors.actor(id of actor).mhp and it should work fine because then it knows which actor it's meant to be getting the stats of (be careful with this though; I think the stat bonuses from equipment are only evaluated when equipped, meaning this wouldn't update as the equipped character was taking damage).

I'm sure there's a way you could do this with a passive state on the weapon, but I haven't figured it out yet.
Is there any way through a script call to pull current HP into a var and then plug that into the formula instead?
<in an event>
var[x] == user.hp
<on the item>
ATK = 10 * (2 - (var[x] / MaxHP))
The problem is, how would you know which actor you were getting the HP of?
Not a problem, my game doesn't have multiple actors. Single character.
Try this:

<Custom Parameters>
atk = 10 * (2 - ($gameParty.leader().hp / $gameParty.leader().maxhp))
</Custom Parameters>
Try this:

<Custom Parameters>
atk = 10 * (2 - ($gameParty.leader().hp / $gameParty.leader().maxhp))
</Custom Parameters>

Thanks for the reply. Tried this, returned NaN for my attack stat.
ugh! It's mhp, not maxhp.
ugh! It's mhp, not maxhp.

Works flawlessly now, but the game experiences incredible slowdown... 3-5 seconds to load every single menu. Lag stops as soon as I unequip the sword!
I can't imagine that particular tag would be the cause. If you remove the tag altogether, then equip the sword, does it still happen?
Game performance is normal with the tag removed. As soon as I add it back, it begins to lag again. The drop in performance starts as far back as the New Game / Load / Exit screen.

Upon further testing, I've also found a new strange bug... the accuracy for both enemies and myself have dropped to 0%. I tested this through about 30 rounds of combat and not a single hit landed. Everything was a miss.
I wonder if there's some incompatibility there ... so to go back to the start, are you certain all your Yanfly plugins are in the correct order? If you disable other plugins that this one doesn't need, does the problem still happen? Please show screenshots of your plugin manager.
I think this may be related to the issue where using user.hp slows it to a screeching halt. I can only assume it's constantly trying to check the value because parameters are being updated frame by frame? That's the only thing I can think of but I haven't delved into the code too much.
@Trihan is that an issue with the plugin, or the core scripts?
@Trihan is that an issue with the plugin, or the core scripts?

Seems to be an issue with using that particular eval for the plugin notetag.

Just confirmed with a console.log that custom parameters notetags are evaluated every frame while on the equipment screen, so yeah. Trying to use any stat of the equipped character causes the call stack to be exceeded.

After some playing around, I realised some of the slowdown was being caused by a per-frame console.log I was running as a debug elsewhere; removing that did make an improvement, but it's still reaaaaaaaaaally slow. Takes about 20 seconds to show the stat change.

@Sketchward I've found a way to implement this; the only thing is that you don't see the increase when equipping it.

Give the weapon 10 base ATK, then create a passive state for the weapon with the following notetag:

Code:
<Custom Initiate Effect>
a._hpMod = Math.floor(10 * (1 - a.hp / a.mhp));
a.addParam(2, a._hpMod);
</Custom Initiate Effect>
<Custom Conclude Effect>
a.addParam(2, -a._hpMod);
delete a._hpMod;
</Custom Conclude Effect>

This will add atk based on lost HP when the actor starts an action, and remove the added atk afterwards.
Interesting - surely that can't be intentional ... would only want to redo it if they changed equip?
That's actually the default behaviour; even without the plugin paramPlus gets called a bunch of times when equipping items.

Original thread: https://forums.rpgmakerweb.com/threads/yep_equipcore-returning-nan-in-equipment-formula.124251/