Custom state effect problem (Yanfly Engine Plugins)

Hi everyone! 🙂

I'm kinda new in in RMMV and i'm trying to make a passive for one of my classes but i can't make it work.
The passive would be this: if your hp is lower than 100% your attack power is increased by 2% for each 1% hp missing.
The formula what i've tried: Math.floor(((user.hp/user.mhp)*100))*(user.atk*0.02).
So if the character has 100 atk on 100% hp, after damaged down to 80% hp he's missing 20% hp, his atk is increased by 20(100*0.02) = 40, so on 80% hp he would have 140 atk.

I'm using Yanfly's plugins, and i've tried a few thing but I can't make it happen. I tried to do this with the AutoPassiveStates and BuffsStatesCore plugins.

I hope you can help me with this.

Have a good day everyone! 🙂
I can't test this as Dropbox isn't accessible at work, but from what I can tell of the documentation for the plugins, you may be able to achieve this using <Custom Turn Start Effect> in your passive state so that every turn it sets the actor's attack to their standard atk value plus 2% for each 1% they're missing from their HP. The only thing is you'd have to find some way to separate the bonus from the base so that you don't end up overwriting changes from other effects.
I tried to do it with this piece of code:

Spoiler: Code
<Custom Turn Start Effect>
var batk = user.atk;
if(user.hp != user.mhp)
{
user.atk += ((user.hp/user.mhp)*100)*(user.atk*0.02);
}
else
{
user.atk = batk;
}
</Custom Turn Start Effect>

Unfortunately something is still wrong, maybe i wrote something in a bad way?
The correct term is user._paramPlus[2], not user.atk

To make it more detailed, It won't up the atk stat if you say user.atk but if you're referring to the param atk then yes it is user.atk.


I answered how to do this already on https://forums.rpgmakerweb.com/inde...sives-with-2-of-yanflys-states-plugins.73920/ l dont feel like explaining again as it's very complicated and players don't care about minor stats boost so it's just a waste of time overall.
Thanks for your answer, I'll read it now and try to do this passive. Later I'll let you know if I could do it or not.
I must be missing something but I still can't make it work. Now I'm watching Yanfly Engine videos, and code explanations and googling things. I'm so new to this but I'll learn it with time, unfortunately now I'm just suffering.
What you're trying to do is basically one of the most complicated passives. I'm not even doing those myself.
I see. Then I'll do other easier passives and skills and with time as I learn and understand things maybe I'll be good enought to do this.

Thanks for all help and informatin!
if your hp is lower than 100% your attack power is increased by 2% for each 1% hp missing.
The formula what i've tried: Math.floor(((user.hp/user.mhp)*100))*(user.atk*0.02).
I can't tell you about the rest, but I can tell you that your mathematics are wrong.

hp/mhp*100 is NOT "missing HP", it is "Remaining HP".
The correct formula for increasing atk by 2% for each missing HP% would be

(100-(user.hp/user.mhp*100))*user.atk*0.02

Or 100% minus "remaining HP%", then multiply by 2% ATK
Oh, yes you're right. Thanks. 🙂 Now i'm doing other thing while tryig to learn how to do this one.

Original thread: https://forums.rpgmakerweb.com/threads/custom-state-effect-problem-yanfly-engine-plugins.75160/