Applying shield based on HP and dealing DMG after shield breaks

Hi folks!

I'm hitting a wall with a battle gimmick of one of my characters.
The character in question is based on different skills related to his HP - to call it simple he's some sort of blood-mage/vampire.
Most skills are easy to set up as well as his damage output, nothing to fancy but there is a passive state that given me a headache.

Once his HP reaches a certain percentage - like 50% of his max HP - he should generate a shield (Bloodshield) that absorbs any damage. The shield itself works but I can't get it to show up when his HP drops below 50%.
The shield itself is created via Visustellas Anti-Damage Barriers plugin and is set up as an Absorption Barrier. After it's absorbed the 50 damage I'm using for testing it goes off and everything is fine.
BUT I want that shield to deal damage when it goes off! If the shield breaks it should deal '50/number of living enemies' damage to every enemy on the field, e.g if there are 2 living enemies and the shield breaks each enemy should get 25 HP damage or if 3 enemies living every enemy should get 16 Hp damage.

To sum up the flow:
HP of Blood Mage drops below 50%
-> Bloodshield (Absorption Barrier) came up
Once Absorption Barrier breaks -> deal damage to the remaining enemies equal to 'HP of Barrier/ number of current enemies'

Is it possible and if so how?
I'm fiddling with it for a few days now and I can't even get the shield show up once the HP drops below the 50% treshold x___x
Have you tried setting a battle event for when you character drops below 50% hp?
Visustella battle core allows you to set one troops event to run on every battle(battle core>base troop ID).

Then Have a look at Skills and states core..
Namely javascript notetags: on add/erase/expire
Which allow you to run code in notetags when the state(barrier) erases or expires.




Required plugins:
VizuMZ_0_CoreEngine
VizuMZ_1_SkillsStatesCore
VizuMZ_3_AntiDmgBarriers
Switches Reserved:
S:0050(or whichever you choose-- see step 1)

Step 1: Create the Bloodshield State
Spoiler: Bloodshield State
State.png
-In the note box paste this in:
Code:
<All Absorb Barrier: 500>

<JS On Erase State>
target.forceAction(250, 0);
BattleManager.forceAction(target);
$gameSwitches.setValue(50, false);
</JS On Erase State>

While this state is active, a barrier with 500(or whatever amount) is created which absorbs ALL damage up to 500 points.
JS on Erase State will force the character to use skill 250(or whichever you choose-- see step 2), then change switch 50 to OFF.

Step 2: Create skill which attacks enemies when barrier breaks.
Spoiler: Blood Burst
Skill.png
-Change SCOPE to All Enemies
-Change Damage Type to HP Damage
-In the Damage Formula, paste this in:
Code:
500 / $gameTroop.aliveMembers().length

This will attack all enemies by 500 divided by the number of enemies currently alive.
Change 500 to how much TOTAL damage you wish to apply(reference is barrier total).

Step 3: Create Troops Battle Event
Spoiler: Troop Event
troop.png
-From: BattleCore>Mechanics Settings>Base Troop>Base Troop ID's you can determine which troop to duplicate page events from(these events will run on every battle troop). Alternatively, you can choose to copy the following event page onto multiple troop event pages if you like.
-Set condition to Actor HP(choosing the actor who uses Bloodshield) 50%
-Set Span to Turn
-In the Event:
Code:
◆If:Bloodshield is OFF
  ◆Change State:Reid, + Bloodshield
  ◆Control Switches:#0050 Bloodshield = ON
  ◆
:End
-Condition (switch 50 is OFF)
-Change State(actor who uses Bloodshield) +State(Bloodshield)
-Change Switch (switch 50 to ON)

What this Battle Event will do is: every turn, it will check if the actor has 50% or less HP.
If it does, it will then check to see if the switch is OFF. If it is, it will apply Bloodshield State(and the barrier), then turn the switch ON. This way it wont continuously apply the state. When the barrier is used up it will use the skill to attack all enemies, then turn the switch back OFF, ready to check again if the actor has 50% or less HP before applying the State/Barrier. You will have to add extra things to suit your needs, such as making the actor regen HP when using Blood Burst(in order to stop the reapply loop as it's HP may stay below 50%); or have a reapply delay somehow, that's up to you.

I hope this helps you achieve that which you are wanting to achieve.
Use whatever you learn from this to expand your understanding of what can be possible.
Happy Game Making!
Have you tried setting a battle event for when you character drops below 50% hp?
Visustella battle core allows you to set one troops event to run on every battle(battle core>base troop ID).

Then Have a look at Skills and states core..
Namely javascript notetags: on add/erase/expire
Which allow you to run code in notetags when the state(barrier) erases or expires.




Required plugins:
VizuMZ_0_CoreEngine
VizuMZ_1_SkillsStatesCore
VizuMZ_3_AntiDmgBarriers
Switches Reserved:
S:0050(or whichever you choose-- see step 1)

Step 1: Create the Bloodshield State
Spoiler: Bloodshield State
-In the note box paste this in:
Code:
<All Absorb Barrier: 500>

<JS On Erase State>
target.forceAction(250, 0);
BattleManager.forceAction(target);
$gameSwitches.setValue(50, false);
</JS On Erase State>

While this state is active, a barrier with 500(or whatever amount) is created which absorbs ALL damage up to 500 points.
JS on Erase State will force the character to use skill 250(or whichever you choose-- see step 2), then change switch 50 to OFF.

Step 2: Create skill which attacks enemies when barrier breaks.
Spoiler: Blood Burst
-Change SCOPE to All Enemies
-Change Damage Type to HP Damage
-In the Damage Formula, paste this in:
Code:
500 / $gameTroop.aliveMembers().length

This will attack all enemies by 500 divided by the number of enemies currently alive.
Change 500 to how much TOTAL damage you wish to apply(reference is barrier total).

Step 3: Create Troops Battle Event
Spoiler: Troop Event
-From: BattleCore>Mechanics Settings>Base Troop>Base Troop ID's you can determine which troop to duplicate page events from(these events will run on every battle troop). Alternatively, you can choose to copy the following event page onto multiple troop event pages if you like.
-Set condition to Actor HP(choosing the actor who uses Bloodshield) 50%
-Set Span to Turn
-In the Event:
Code:
◆If:Bloodshield is OFF
  ◆Change State:Reid, + Bloodshield
  ◆Control Switches:#0050 Bloodshield = ON
  ◆
:End
-Condition (switch 50 is OFF)
-Change State(actor who uses Bloodshield) +State(Bloodshield)
-Change Switch (switch 50 to ON)

What this Battle Event will do is: every turn, it will check if the actor has 50% or less HP.
If it does, it will then check to see if the switch is OFF. If it is, it will apply Bloodshield State(and the barrier), then turn the switch ON. This way it wont continuously apply the state. When the barrier is used up it will use the skill to attack all enemies, then turn the switch back OFF, ready to check again if the actor has 50% or less HP before applying the State/Barrier. You will have to add extra things to suit your needs, such as making the actor regen HP when using Blood Burst(in order to stop the reapply loop as it's HP may stay below 50%); or have a reapply delay somehow, that's up to you.

I hope this helps you achieve that which you are wanting to achieve.
Use whatever you learn from this to expand your understanding of what can be possible.
Happy Game Making!

Thank you so much! It works like a charm!
I fiddle a bit after my post and get to the solution with the base troops and the state for the shield by myself but a bit different. My problem was the resulting damage after the shield breaks!
Learned a lot thanks to you.
Welcome, friend. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/applying-shield-based-on-hp-and-dealing-dmg-after-shield-breaks.140974/