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.
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>
ugh! It's mhp, not maxhp.
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.
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.