How Can I Recove Party HP and MP Through an Event?

Howdy guys, I'm new to RPG Maker. I already tried searching through old posts, but I've not been able to find a solution that works. I'm trying to figure out how to restore my party's HP and MP through meals in a restaurant. I've tried using the Change HP and Change MP commands. I've misunderstood how variables work and this is part of the issue. For example when I go to Change HP and set the actor to the entire party and for the operand variable I tried using "b.mhp * 0.20" to try and restore 20% of the parties HP. That didn't work. The only other thing I can think to try at this point are custom scripts, but I have no knowledge on coding. Does anyone have any recommendations or advice? At this point I'll take an introductory course for Java.
1701549437938.png


The script call versions are
JavaScript:
$gameParty.members().forEach(function(m){
 m.recoverAll();
});
or
JavaScript:
$gameParty.members().forEach(function(m){
 m.gainHp(Math.round(1*(m.mhp)));
 m.gainMp(Math.round(1*(m.mmp)));
});
If you only want to recover a percentage of their HP or MP you would change the 1 to .25 for 25 percent or whatever
Can you explain how I need to change that code to make it work for each occasion?
Hey, @Mikeits, I've got a non-script solution for you. You will have to recover each party member's HP one at a time instead of using Recover All, but it accomplishes the same purpose as you wanted.

To recover 20% of each party member's HP, I get their Max HP, divide it by 5, then use Change HP, repeating for each actor in the party.
HPScreenshot.png
Can you explain how I need to change that code to make it work for each occasion?
You put in a script call
$gameParty.members().forEach(function(m){ m.gainHp(Math.round(1*(m.mhp))); m.gainMp(Math.round(1*(m.mmp))); });

And change the 1 to the decimal of the percentage you want to recover (.25 for 25 percent). Delete the m.gainHP or m.gainMP line if you only want to recover one or the other.
You put in a script call
$gameParty.members().forEach(function(m){ m.gainHp(Math.round(1*(m.mhp))); m.gainMp(Math.round(1*(m.mmp))); });

And change the 1 to the decimal of the percentage you want to recover (.25 for 25 percent). Delete the m.gainHP or m.gainMP line if you only want to recover one or the other.
You're an angel. That worked. Do you know of any good tutorials for Java Script so I can start writing my own code?
Hey, @Mikeits, I've got a non-script solution for you. You will have to recover each party member's HP one at a time instead of using Recover All, but it accomplishes the same purpose as you wanted.

To recover 20% of each party member's HP, I get their Max HP, divide it by 5, then use Change HP, repeating for each actor in the party.
View attachment 286149
I'll also add this to me repertoire. Thank you.
You're an angel. That worked. Do you know of any good tutorials for Java Script so I can start writing my own code?
I just got the code version of the event command from

As far as Javascript tutorials go, I used FreeCodeCamp and W3 Schools
I just got the code version of the event command from

As far as Javascript tutorials go, I used FreeCodeCamp and W3 Schools
Thank you for the script call list, Echo (and Mikeits for the good question). I thought doing the reverse (for a BOMB trap popping-up from a chest) would be "m.loseHp" (which doesnt work). ... I didnt think it was simply the same line except with a minus sign added instead... clever!


EDIT: Where would I need to add "false" to prevent a GameOver? Tried various placements and none seemed to have worked. Ill try some more for a leader-only version too.
EDIT: Where would I need to add "false" to prevent a GameOver? Tried various placements and none seemed to have worked. Ill try some more for a leader-only version too.

I think you can use the ready made function that has the check to change the damage value if you've set allow death to false (change -100 to your damage value):

const actor = $gameParty.leader();
Game_Interpreter.prototype.changeHp.call(actor, actor, -100, false);

@Nirriti, please refrain from necro-posting in a thread. Necro-posting is posting in a thread that has not had posting activity in over 30 days. You can review our forum rules here. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-recove-party-hp-and-mp-through-an-event.163528/