Make a counter-like attack

Hey, im new to rpg maker and I’m trying to make a skill that works like this: When I use it, I receive a state that makes it so that if a hit would normally kill me, I stay at 1 HP — that is, I don’t die. I need it to work in this way: the state activates, the enemy hits, and then I hit in the same turn through the skill itself, kind of like a parry.


The idea is for it to be a last-resort skill: if I’m about to die, I activate it, it saves me from a killing blow, and I deliver a devastating hit. If the enemy doesn’t die from that hit, the user dies.


Right now, I have the skill add the state using the following command:
<JS Pre-Damage as Target>if (value >= target.hp && Math.random() < 100) {value = target.hp - 1;}</JS Pre-Damage as Target>

Can you guys help me get my character to do the hit, and die if the enemy doesnt?
At the moment, I’m using VisuStella plugins. thank you<3
How do you want it to happen? If you want skill sequence to happen in the middle of enemy action, I think you need to put conditionals inside enemy action sequences. If it's enough for it to just play some kind of quick animation and show a damage number at the same time as the enemy attack is happening, then you can do it in those notetags. Change animationId and deal what damage you want (you could also script VS emulate skill effect).

<JS Pre-Damage as Target>
if (value >= target.hp) {
value = target.hp - 1;
target._megaCounter = true;
}
</JS Pre-Damage as Target>

<JS Post-Damage as Target>
if (target._megaCounter) {
$gameTemp.requestAnimation([user], animationId);
user.gainHp(-100);
if (user.hp > 0) {
target.gainHp(target.hp * -1);
}
}
delete target._megaCounter;
</JS Post-Damage as Target>

EDIT: Edited property checks to control when counter activates.

Original thread: https://forums.rpgmakerweb.com/threads/make-a-counter-like-attack.182468/