Looking for a way to lower overall enemy HP if one enemy in a group is dead

Hello everyone!

I am looking for a way to set it up that, in a group of at LEAST 2 enemies, defeating one of them (the main one) lowers the health of the remaining ones. This should only apply if a BOSS monster is present. Ideally I'd like it to be lowered by a percentage.

So, if there is a Boss and 2 minions, defeating the boss lowers the remaining health of the two minions. Defeating one of the minions does nothing to anyone's heath. If no boss is present in the battle, the functionality does not work or apply.

I also do not want it to be a speciel skill that is used to defeat the boss and triggers it, it needs to be seperate. I'd prefer it to be done via the regular encounter system, but a plugin is fine as well.



(The end goal of this is that the player needs to strategize about whether or not to defeat the boss first or the minions, which will deal less/no damage but can apply status effects to party members.)


Thanks for anyone willing to help!
1692467829686.png

So you *could* faff about with a bunch of variables for the calculations here, but you can also just do it with a script like this.

In this example, when the Minotaur is killed, each bat will have its HP lowered by 25%.
View attachment 273866
So you *could* faff about with a bunch of variables for the calculations here, but you can also just do it with a script like this.

In this example, when the Minotaur is killed, each bat will have its HP lowered by 25%.
Could you explain to me which variables in this respond to which enemy so I can repeat this for different amounts of minion enemies? Other than that, thank you very much, this is exactly whast I was looking for!

(By 'variables' here I mean the ones in the script, not the in-engine ones.)
Could you explain to me which variables in this respond to which enemy so I can repeat this for different amounts of minion enemies? Other than that, thank you very much, this is exactly whast I was looking for!

(By 'variables' here I mean the ones in the script, not the in-engine ones.)
So just for convenience and shorthand I've created a variable called e1 which stores troop member 0 (the first bat) and one called e2 which stores troop member 1 (the second bat).
So just for convenience and shorthand I've created a variable called e1 which stores troop member 0 (the first bat) and one called e2 which stores troop member 1 (the second bat).
I set it all up, hopefully right, and when I defeat the Minotaur, the bats get.... NaN. I have installed a plugin to show damage on enemies just to test.

wip 2.PNG

wip 1.png
I set it all up, hopefully right, and when I defeat the Minotaur, the bats get.... NaN. I have installed a plugin to show damage on enemies just to test.

View attachment 273874
View attachment 273875
I think that's your plugin rather than the battle event, it works fine for me.

1692476609218.png
I think that's your plugin rather than the battle event, it works fine for me.

View attachment 273884
Is there an ingame way to check if the calculation works? I just want to check, in case.
Also, the plugin should still be able to show the number, I think. NaN makes me think something is wrong with the variables.
Is there an ingame way to check if the calculation works? I just want to check, in case.
Also, the plugin should still be able to show the number, I think. NaN makes me think something is wrong with the variables.
You can open the developer console with F8 or F12 and enter code manually.

What plugin is this?
You can open the developer console with F8 or F12 and enter code manually.

What plugin is this?
The plugin can be found here:

I'll take a look!

EDIT: So, I looked at it again, and now when I defeat the Minotaur, the bats are undefeatable. If the Minotaur is alive, they are defeated as normal. This happens regardless of whether the plugin is active.
Seems like a very simple way to test is to turn off the layered gauges plugin and test again. There's nothing in the code @Trihan provided that should result in NAN.

It's worth mentioning that there's a slight error/typo in that code, however:
In this example, when the Minotaur is killed, each bat will have its HP lowered by 25%.
Doing setHp(Math.floor(e2.hp*.25)) will set the HP to 25%, e.g. lowered by 75%.

It might not be terribly relevant at the moment for testing purposes, but just for the sake of mathematical accuracy 😉
Fair point, well spotted.
Seems like a very simple way to test is to turn off the layered gauges plugin and test again. There's nothing in the code @Trihan provided that should result in NAN.

It's worth mentioning that there's a slight error/typo in that code, however:

Doing setHp(Math.floor(e2.hp*.25)) will set the HP to 25%, e.g. lowered by 75%.

It might not be terribly relevant at the moment for testing purposes, but just for the sake of mathematical accuracy 😉
I already turned off the plugin, like I said in my reply, that did nothing to fix it. I removed the portion of the code that assigned the variables and that fixed it, but now I would very much like to figure out why it did not like the variable there.
I already turned off the plugin, like I said in my reply
Sorry, I did miss that part.

What MV version is your project? Open rpg_core.js and look at the top. I believe MV got updated to ES6 which supports the const variable type partway through its development cycle.

If your project isn't 1.6.1 or 1.6.2, that could explain why the variables didn't work correctly and you should update your core scripts.
Sorry, I did miss that part.

What MV version is your project? Open rpg_core.js and look at the top. I believe MV got updated to ES6 which supports the const variable type partway through its development cycle.

If your project isn't 1.6.1 or 1.6.2, that could explain why the variables didn't work correctly and you should update your core scripts.
Nope, it is 1.6.2, as I expected it to be (I only re-downloaed the maker recently.)
Well, creating variables isn't necessary to make the code work. You can copy and paste the long reference:
Code:
$gameTroop.members()[0].setHp($gameTroop.members()[0].hp*.25)

But it should work as Trihan wrote it.
Well, creating variables isn't necessary to make the code work. You can copy and paste the long reference:
Code:
$gameTroop.members()[0].setHp($gameTroop.members()[0].hp*.25)

But it should work as Trihan wrote it.
I have been using the long way. I am curious to know why it is not working, though. Did I make a typo? This was in a new project I did nothing with other than setting up the script/troop.
I wonder if it's because MV doesn't support const.

Does it work if you use "var" instead?
I wonder if it's because MV doesn't support const.

Does it work if you use "var" instead?
Yap, that was apparently the issue. Using var, it works perfectly.
@Trihan That's why I asked about his version above.

const works for me in MV, and according to process.versions in the console it's running the stock NW.js version of 29.4

So unless something has manually made the OP's an earlier version, your suggestion should work.

1692646652326.png

Original thread: https://forums.rpgmakerweb.com/threads/looking-for-a-way-to-lower-overall-enemy-hp-if-one-enemy-in-a-group-is-dead.160426/