Change Hp with %?

So one of the mechanics I want to add to my game is summons. These summons are handled through common events. However, while one of the summons are out, I have a "Stress" state applied to the summoner that reduces either their max HP or their max MP by 15-25%, depending on how powerful the summon is. When the summon dies, the state is removed from the summoner until they resummons the monster.
My question is how would I make it so that, when the summon does die, the summoner regains the HP/MP they lost from the state? What I mean is:


Character A has 20 max HP.


Character A summons Monster A with 25% HP Stress, reducing Character A's max HP to 15.


Character A suffers 5 damage from enemies, reducing Character A to 10/15 HP. (2/3rds of current max HP)


Monster A dies. A common event then removes the state from Character A.


Character A now has 10/20 HP.


I want Character A to have 16/20 (2/3rds of max) HP when Monster A dies rather than 10/20, or at the least 15/20 (enough to pay back what Character A lost from the Stress state).


EDIT: I do know of the "Actor: Change HP..." event. That is not quite what I want as it cannot deal with percentages like I want. I can add 5 HP to the Summoner when the monster summoned dies, but when the Summoner gains more HP (through either leveling or gear), that 5 HP will no longer be 25% of the Summoner's HP
After Actor returned his max hp


use $gameActors.actor(actorId).gainHp($gameActors.actor(actorId).mhp/100*25);
Even though percentages are not supported by default, you can calculate the actors new HP value using variables:



New HP / New MHP  =  Stressed HP / Stressed MHP  =>


New HP  =  Stressed HP * New MHP / Stressed MHP


can be calculated either by using javascript code or event commands:

Spoiler
@>Control Variables: [0001: Stressed MHP] = [Actor]'s MHP


@>Change State: [Actor], - [Stress]  <- Remove Stress State after memorizing the MHP


@>Control Variables: [0002: New HP] = [Actor]'s HP


@>Control Variables: [0002: New HP] *= Variable [0001: Stressed MHP]


@>Control Variables: [0002: New HP] /= [Actor]'s MHP


@>Control Variables: [0002: New HP] -= [Actor]'s HP  <- Since you cannot set HP directly, add the difference instead


@>Change HP: [Actor], + Variable [0002: New HP]



mrcopra already provided a working javascript solution, however, I think you also have to round the value manually to prevent decimal HP values:


$gameActors.actor(actorId).gainHp(Math.floor($gameActors.actor(actorId).mhp/100*25));
Yay! That works. Thanks for the quick response, you two 🙂

Original thread: https://forums.rpgmakerweb.com/threads/change-hp-with.63408/