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,606
Reaction score
1,965
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,606
Reaction score
1,965
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,606
Reaction score
1,965
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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,606
Reaction score
1,965
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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,606
Reaction score
1,965
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

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,692
Reaction score
13,980
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,606
Reaction score
1,965
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

Well that was three hours of work down the drain, because GIMP froze and I forgot to save anything.
for who interested in a example boilerplate pixijs with snowpack , i made a branch with pixijs .
Web and Desktop, nwjs is not required.
https://github.com/nwutils/SnowPack-nw/tree/PixiJs
I definitely give up Parcel bundler !
I wonder how many amazing games from the Completed Game/Games In Development forums that I just passed only because of an uninteresting title.


Doing more paralaxing. It isn't much, but it looks a lot less blocky now :)
aww these times when you feel alone, abandonned and lack the self awareness you don't even read anymore your favorite of all forum. Sorry all!

Forum statistics

Threads
107,383
Messages
1,029,249
Members
139,477
Latest member
segit
Top