MV Current HP Percentage tracking between states

Hi, good people of the RPG Maker Forum! I've been advised I'll need a plugin for the effect I desire.

I have a State Super that alters Param MHP 150% and a State Weakened that alters Param MHP 75%. When both states are removed, the Actor's current HP stays the same numeric value. I need the Actor's current HP after the state is removed to maintain the same percentage of their new (normal) MHP as the State-affected MHP.

Example Super:

Normal MHP: 20
Super is applied. MHP: 30
Actor takes 15 damage. Current HP 15/30 (50%)
Super is removed. MHP: 20
Current HP shows 15/20
I need Current HP to be 10/20 (50%).

Example Weakened:

Normal MHP: 20
Weakened is applied. MHP: 15
Actor takes 10 damage. Current HP 5/15 (~33%)
Weakened is removed. MHP: 20
Current HP shows 5/20
I need Current HP to be 7/20 (~33%, rounded up).

I would like the plugin to automatically round up or down. If possible, I'd like 0.5 to be rounded up, and anything lower rounded down. If that isn't possible, then I'd rather have everything rounded down.

I would love to add more states like these, but I want to test things out with these two first. If the plugin could holistically include the ability to do the same things with MP and TP, that would be fantastic.

I know this is probably a big ask, but any help would be appreciated.
Bump
Thinking about this, I think it can be done​
with Yanfly's Buff and States Core, and some math. If for instance, the HP increase increases HP by 50%, then it would just need a <Custom Remove Effect> that decreases current HP by 33%. Ironically, an HP decrease of 75% would need a <Custom Remove Effect> that increases HP by 33%.
Thank you for the reply.
Hmm. Okay, I'm not very good at math. Is it because that 50% increase is 1/3rd of the current HP when the Super state is applied that you reduce current HP by 33% when removing the state?
If I understand correctly, if the Super state made MHP 125% instead, when removing the state, you'd reduce current HP by 20%. Is that correct?
And with the Weakened state: 33% of 75 is 25, so adding 33% would make it 100 (100%). So, again if I understand, if the Weakened state altered MHP to 67% instead of 75%, you'd increase current HP by 49% when the state is removed. Is that right?
If I'm completely wrong, could you please elaborate more?
You are exactly right in your reasoning.​
​
My friend and I had a fun time coming to this realization, but as long as your states have a static increase/decrease, then the inverse will always be static as well.

As for the actual code itself, I think it would be​
var a = Math.round(user.hp * 0.33) * -1;​
user.gainHp(a);​
​
To reduce the targets current HP by 33%. There's probably a more efficient way to do that but I haven't tested it yet.​
Hey guys. I just thought I'd add in here that I'm using Yanfly's scripts in my own game, and had Items that used Actor Max HP and Actor Current HP as variables. Referencing these variables in any way seems to cause the game to majorly slow down. It was taking 5-6 seconds to open or navigate between menus, and in-battle the game would freeze almost completely, taking upwards of 15 seconds to process turns.

I *think* it's because referencing these Actor Stats in a State or in an Item causes a full Actor Refresh any time those items or states are referenced... this constant refreshing of the entire Actor state takes a long time.
You are exactly right in your reasoning.​
​
My friend and I had a fun time coming to this realization, but as long as your states have a static increase/decrease, then the inverse will always be static as well.​
​
As for the actual code itself, I think it would be​
var a = Math.round(user.hp * 0.33) * -1;​
user.gainHp(a);​
​
To reduce the targets current HP by 33%. There's probably a more efficient way to do that but I haven't tested it yet.​

Sorry about the delayed response. Real life seriously got in the way.

Thanks for clarifying and for your help!
Hey guys. I just thought I'd add in here that I'm using Yanfly's scripts in my own game, and had Items that used Actor Max HP and Actor Current HP as variables. Referencing these variables in any way seems to cause the game to majorly slow down. It was taking 5-6 seconds to open or navigate between menus, and in-battle the game would freeze almost completely, taking upwards of 15 seconds to process turns.

I *think* it's because referencing these Actor Stats in a State or in an Item causes a full Actor Refresh any time those items or states are referenced... this constant refreshing of the entire Actor state takes a long time.

I appreciate you letting me know. I'm still going to give it a shot, but if I have similar issues, I'll post back and let you know. I'm not going to be using items that reference Current or MHP, just states.
You are exactly right in your reasoning.​
​
My friend and I had a fun time coming to this realization, but as long as your states have a static increase/decrease, then the inverse will always be static as well.​
​
As for the actual code itself, I think it would be​
var a = Math.round(user.hp * 0.33) * -1;​
user.gainHp(a);​
​
To reduce the targets current HP by 33%. There's probably a more efficient way to do that but I haven't tested it yet.​

I'm working on this today, and I've run into an issue. I'm pretty sure I've done all the math right (I've done it a lot), and I've just copied and pasted your code with Yanfly's notetags, yet it still doesn't work right.

Weakened makes MHP 75%. So to start, the Actor has 18 MHP. Weakened makes MHP 14 (rounded). She takes 10 damage (71%). When Weakened is removed, her HP shoots back up to 18 (normal MHP). Her HP should only go up to 13. Any idea what's going on? I understand this on paper, but I don't know how the code works.
I'm not sure about the math here, as I did a test myself just now. A character started with 18 MHP, then received the weaken state downing them to 14 MHP. I then dealt 10 Damage to them, dropping them to 4 HP. The state then expired, and their MHP went back up to 18, while their current HP went from 4 to 5, as 33% of 4 is 1.32, which is rounded down to 1. For clarity, I used this in the state notebox:



<Custom Remove Effect>
var value = Math.round(user.hp * 0.33);
user.gainHp(value);
</Custom Remove Effect>




I can say there seems to be an error when I try to remove the state via events. However when the state expires naturally due to turn decay or when it's removed via a skill effect, it seems to function.


Spoiler: State in Action
weaken.gif


I tried it here using larger numbers to wrap my head around it. The character starts at 200 MPH, then is weakened by 75% to to 150 MHP. Then she takes 75 damage, reducing her HP % to 50%, 75/150. Then the Wait skill is used to remove the state, increasing her MHP back to 200, and her current HP is increased by 25, so she retains the 50% HP ratio.
I'm not sure about the math here, as I did a test myself just now. A character started with 18 MHP, then received the weaken state downing them to 14 MHP. I then dealt 10 Damage to them, dropping them to 4 HP. The state then expired, and their MHP went back up to 18, while their current HP went from 4 to 5, as 33% of 4 is 1.32, which is rounded down to 1. For clarity, I used this in the state notebox:



<Custom Remove Effect>
var value = Math.round(user.hp * 0.33);
user.gainHp(value);
</Custom Remove Effect>




I can say there seems to be an error when I try to remove the state via events. However when the state expires naturally due to turn decay or when it's removed via a skill effect, it seems to function.


Spoiler: State in Action
View attachment 160863

I tried it here using larger numbers to wrap my head around it. The character starts at 200 MPH, then is weakened by 75% to to 150 MHP. Then she takes 75 damage, reducing her HP % to 50%, 75/150. Then the Wait skill is used to remove the state, increasing her MHP back to 200, and her current HP is increased by 25, so she retains the 50% HP ratio.

Okay, I guess I'll just have to play around with it some more. I'll try larger numbers and various percentages as well. Thanks for your continued help with this!

Original thread: https://forums.rpgmakerweb.com/threads/current-hp-percentage-tracking-between-states.126599/