Setting Actor HP?

I'm trying to adjust Actor's HP so that it scales with various buffs/debuffs. Here's the general gist:
Actor1 has an MHP of 100
They have 70 HP

If they have a debuff that makes MHP 75%, their HP should scale down to 35. If it's a buff that makes it 200%, then it should be 140 HP.

What I'd like to do is:
Take current HP, divide by max HP. This gives a percentage. We save this as a variable. Then, set their HP to be equal to MHP * variable. This is what it looks like thus far:

Code:
$gameActors.actor(1).gainHp($gameActors.actor(1).mhp*$gameVariables.value(39))

The problem is, this is gainHP. So, they'll actually be GIVEN that much HP, rather than adjusting their HP to that number. Any thoughts?
1.) I don't think I understand your math well:
Actor1 has an MHP of 100
They have 70 HP

If they have a debuff that makes MHP 75%, their HP should scale down to 35.

"If they have a debuff that makes MHP 75%, their HP should scale down to 35." --> why would the HP go down by half if the MHP goes down by a quarter?

Using your example:

"Take current HP, divide by max HP"
70 / 100 = 0.70 (or 70%)
"debuff that makes MHP 75%"
MHP = 100 * 0.75 = 75
"Then, set their HP to be equal to MHP * variable."
HP = 75 * 0.70 = 52.5

Am I missing something?

2.) If you want to set the HP rather than gain HP, use setHp() rather than gainHp()
To clarify what you want to do. In case the MHP goes up or down, you want the actors to keep the same HP rate they had? So if actor has 70% health left, and their MHP changes, you still want them to have 70% left?

There is, by the way, command for .hprate() which returns the HP/MHP . Other than that, yes, go with .setHp(hp)
1.) I don't think I understand your math well:


"If they have a debuff that makes MHP 75%, their HP should scale down to 35." --> why would the HP go down by half if the MHP goes down by a quarter?

Using your example:

"Take current HP, divide by max HP"
70 / 100 = 0.70 (or 70%)
"debuff that makes MHP 75%"
MHP = 100 * 0.75 = 75
"Then, set their HP to be equal to MHP * variable."
HP = 75 * 0.70 = 52.5

Am I missing something?

2.) If you want to set the HP rather than gain HP, use setHp() rather than gainHp()

To clarify what you want to do. In case the MHP goes up or down, you want the actors to keep the same HP rate they had? So if actor has 70% health left, and their MHP changes, you still want them to have 70% left?

There is, by the way, command for .hprate() which returns the HP/MHP . Other than that, yes, go with .setHp(hp)

I'm awful at math. Whoops! Oh well, you guys knew what I was looking for with .setHp. Thank you, a bunch <3

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/setting-actor-hp.94503/