YEP_EquipCore Returning NaN in Equipment Formula

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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.
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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))
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
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.
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
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.
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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))
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
The problem is, how would you know which actor you were getting the HP of?
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
Not a problem, my game doesn't have multiple actors. Single character.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Try this:

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

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
ugh! It's mhp, not maxhp.
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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?
 

Sketchward

Veteran
Veteran
Joined
Jul 26, 2016
Messages
111
Reaction score
8
First Language
English
Primarily Uses
RMMV
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
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.
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
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.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
@Trihan is that an issue with the plugin, or the core scripts?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
@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.
 
Last edited:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,108
Reaction score
13,713
First Language
English
Primarily Uses
RMMV
Interesting - surely that can't be intentional ... would only want to redo it if they changed equip?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
That's actually the default behaviour; even without the plugin paramPlus gets called a bunch of times when equipping items.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,455
Members
137,821
Latest member
Capterson
Top