Enemy HP/MP change script call

Hello folks,

I'm trying to create a scene where a battle gets interrupted, but the resumes a bit later. The problem I'm having is I'm trying to have the enemy's HP and MP be back to what it was before the battle gets interrupted. I can store their HP/MP in variables (I think, since I've never gotten it to pop back, I'm not positive lol) but how can I get it to actually be their HP/MP when the battle resumes (basically just restarting the encounter and they have full health). I'm pretty sure there's a script call I can use but I'm not exactly sure what it is...anyone know, or have another way I can implement this? Thanks in advance!
You don't need a script
EnemyHP.png


Edit: You just need a variable for each enemies Hp, and each enemies MP
To elaborate: enemies start battles at max HP by default, so with eventing you could store the difference between max HP and current HP, then use that value to decrease their HP at the start of the next battle (same idea for MP). E.g.
  • End of battle 1 (Control Variables > Game Data > Enemy > HP | Max HP):
    Code:
    ◆Comment:Get max HP minus current HP
    ◆Control Variables:#0050 Enemy1-HP = Max HP of #1
    ◆Control Variables:#0050 Enemy1-HP -= HP of #1
  • Start of battle 2 (Change Enemy HP > Decrease > Variable):
    Code:
    ◆Change Enemy HP:#1, - {Enemy1-HP} (Allow Knockout)
To elaborate: enemies start battles at max HP by default, so with eventing you could store the difference between max HP and current HP, then use that value to decrease their HP at the start of the next battle (same idea for MP). E.g.
  • End of battle 1 (Control Variables > Game Data > Enemy > HP | Max HP):
    Code:
    ◆Comment:Get max HP minus current HP
    ◆Control Variables:#0050 Enemy1-HP = Max HP of #1
    ◆Control Variables:#0050 Enemy1-HP -= HP of #1
  • Start of battle 2 (Change Enemy HP > Decrease > Variable):
    Code:
    ◆Change Enemy HP:#1, - {Enemy1-HP} (Allow Knockout)

I tried to do something like this but I couldn't get it to work, like, at all. Did you happen to test this at all?

EDIT: Maybe I'm not storing the variables right. It seems to me though that this should store them every turn, right?

hpvar.jpg
Store them in the event page that interupts the battle, just before the battle is interupted
Store them in the event page that interupts the battle, just before the battle is interupted


Well, the problem is, this isn't a one time thing. It happens, or has the potential to happen, during every boss fight. It's a...weird mechanic I'm trying to implement. And I have a common event spawned by a plugin that happens when the party is defeated during a fight. It does one thing during a regular battle, but another thing during any boss battle. So, in order for it to work, to store the variables with the event, I'd have to put conditional branches for every boss, and turn on a DIFFERENT switch for every boss fight so that the event would know what enemy's HP to store. Also, I'm not really sure how to store an enemy's HP in a variable in a non-battle event, since what am I telling the game to look at for the enemy's HP? The enemy doesn't really exist outside of combat and neither does his HP.
Can you please show the event which does the "abort battle"? This is where @Oddball suggested to store the boss HP into a variable.
It's a Common Event and not a Troop Event?

So, in order for it to work, to store the variables with the event, I'd have to put conditional branches for every boss, and turn on a DIFFERENT switch for every boss fight so that the event would know what enemy's HP to store.
Yes, this is a valid concern but let's just get it working for one scenario first. After that we can come back to this concern and think of an efficient way to do it for all your scenarios without so much manual work for you.
Common events don't run during battle
Can you please show the event which does the "abort battle"? This is where @Oddball suggested to store the boss HP into a variable.
It's a Common Event and not a Troop Event?

It is a Common Event, but it's controlled by a plugin. Basically the plugin replaces the Game Over event. So...I guess technically the battle isn't "interrupted" per se, so there is no Abort Battle command. The switch occurs if the party is defeated.
Can you please just show us the event. Since it's a plugin, you need to tell us which one it is - if the plugin provides a way to get the information that you need we need to look at the documentation.

Edit: for future questions, if you're using plugins that change the standard behavior of how MV works, you should include links to the plugins in the first post
Can you please just show us the event. Since it's a plugin, you need to tell us which one it is - if the plugin provides a way to get the information that you need we need to look at the documentation.

Edit: for future questions, if you're using plugins that change the standard behavior of how MV works, you should include links to the plugins in the first post

Sure, sorry. The plugin is here: https://forums.rpgmakerweb.com/index.php?threads/custom-game-over-behavior.55072/

The event is this:
Spoiler
dcevent.jpg

and then I have another event controlling the actual battle I'm testing this with:

Spoiler
bossevent.jpg

and I was attempting to control the variables and new boss HP level through the battle event pages but the one with the variable control is posted above and I deleted what I had for the other battle event to reduce the boss's HP because it wasn't working
From the description of that plugin:

Your Party Death Common Event will run in the same scene that the party dies, in place of a standard Game Over. If the party dies in battle, then this common event will play out in battle

Since the Common Event is playing inside the battle (the plugin changes the default behavior to allow this), you should be able to access the HP of the enemies at that time.
Either from @caethyril solution above, or via the Script section in Control Variables.

Code:
$gameTroop.members()[X].hp
Where X is the index of the troop member (index starts at zero)
If that doesn't work someone might have to look at the code of the plugin, but during the battle you should be able to get the enemy hp
From the description of that plugin:



Since the Common Event is playing inside the battle (the plugin changes the default behavior to allow this), you should be able to access the HP of the enemies at that time.
Either from @caethyril solution above, or via the Script section in Control Variables.

Code:
$gameTroop.members()[X].hp
Where X is the index of the troop member (index starts at zero)
If that doesn't work someone might have to look at the code of the plugin, but during the battle you should be able to get the enemy hp

Okay, so here's the weird thing. It works...sort of. I actually tried this before and I thought that it wasn't working. But that's because I closed the battle before it could go into effect. I installed a plugin to show enemy HP just so I could test it, but when the battle first loads, it either doesn't drop the enemy's HP right away, or the plugin doesn't register it right away. It's not until the enemy has his first turn that it goes into effect, but I have it set to go into effect on turn 0. Which effectively means it works, I guess, unless I want to have something set up to display enemy HP. Any insight into this?

Edit: Here's the battle event, in case it matters:

Spoiler
battleevent.jpg

Edit edit: and the link to the plugin that shows the HP: https://forums.rpgmakerweb.com/index.php?threads/show-enemy-hp-updated.82985/

Edit edit edit: aaaaaand now that I've installed Yanfly's battle core and HP gauges, it doesn't work at all. *sigh*
I think I understand what you're saying, but just to be clear --

Does the strategy actually work, you're able to set the enemy HP to a variable which contains their HP from the previous battle?

And now the issue is that you need the guage to be refreshed after "turn 0".

If so, that is progress! Your problem went from "it's not working" to "it only appears that it's not working".
I think I understand what you're saying, but just to be clear --

Does the strategy actually work, you're able to set the enemy HP to a variable which contains their HP from the previous battle?

And now the issue is that you need the guage to be refreshed after "turn 0".

If so, that is progress! Your problem went from "it's not working" to "it only appears that it's not working".

That SEEMS to be the case, except, the change doesn't appear at all after I installed Yanfly's Battle Core and HP Gauges. I'm gonna test it with the other HP gauge just to see what happens, but I have trouble believing Yanfly's plugins would misinterpret the HP that way, so I have a feeling the Battle Core messes it up completely somehow. Which is a shame, because I really want to use the Battle Core.

Edit: Actually, it seems to be working totally fine now. Maybe the plugin didn't work in the first time, I dunno, for some reason plugins don't always work exactly right the first time you test them.

Original thread: https://forums.rpgmakerweb.com/threads/enemy-hp-mp-change-script-call.114222/