Trying to Create a Self-Destruct type move.

You know the one. The enemy suddenly decides out of nowhere to go BOOM dealing great damage to your party...but then killing himself in the process.

The problem I'm having right now is to have the monster automatically KO after using the move. How would I go about doing that?
From Googling "RPG Maker self destruct":




Good luck with your project!
yanfly's skill core, set hp cost of move to 100%
yanfly's skill core, set hp cost of move to 100%
While it's possible that OP posted in the wrong place, this is MZ Support, not MV Support. Please remember to recommend MZ plugins.
While it's possible that OP posted in the wrong place, this is MZ Support, not MV Support. Please remember to recommend MZ plugins.
Visustella skills and something i forgot base Might work as well
As long as you avoid using it in auto-battles (because of a weird thing regarding evaluation of damage formulas) this is possible using the damage formula itself, like so:
JavaScript:
a.setHp(0); a.atk
a.addState(1); a.atk
The first part kills the user, and the second is the damage section, to be replaced with whatever you like.
Visustella skills and something i forgot base Might work as well
If you happen to use the VisuStella Battle Core and either do want to make use of Auto-Battle, or simply like doing this kind of thing through notetags rather than the damage formula, the following should work, courtesy of an old post by @ATT_Turan
Code:
<JS Post-Damage>
user.gainHp(-user.hp);
user.performCollapse();
</JS Post-Damage>
As long as you avoid using it in auto-battles (because of a weird thing regarding evaluation of damage formulas) this is possible using the damage formula itself, like so:
JavaScript:
a.setHp(0); a.atk
a.addState(1); a.atk
The first part kills the user, and the second is the damage section, to be replaced with whatever you like.
It's been awhile since I've gone through RPGMaker, and writing code is not my specialty here. So, I feel kinda stupid for asking this, but where exactly do I put this code?

When I put it in the Script section of the event commands it spits out an error saying that "a" is undefined.

When I put it in the Notes section, nothing happens, and when I stick it in the damage formula section, the move doesn't work at all.

Same goes for this stuff:

<JS Post-Damage>
user.gainHp(-user.hp);
user.performCollapse();
</JS Post-Damage>

The closest thing that works is when I go in and say:

"Change Enemy HP: #1, -9999

or

Change Enemy State: #1, + Dead.

Problem is, the enemy using it won't always be in the #1 slot. So it could either kill the wrong enemy if the #1 enemy is alive, or do nothing if the #1 enemy is already dead. How do I make it kill the user? (Enemy attack by the way)
What I posted is only for the damage formula, preferably nowhere else (although I could probably rewrite it to be put in an action sequence, if you want). Is the move's scope set to The User, though (if action sequence, this won't matter)? And is the enemy able to cast it? Does the move do HP damage? 😴
Okay...Tried it on the Damage formula line. Technically it worked, but the enemy doesn't vanish.
Similar to the notetag above, adding
JavaScript:
a.performCollapse();
after the setHp may work, I did not test it though. That should in theory make it disappear.
It works! Just one more issue. The attack deals 0 damage. I'm trying to set it based on the enemy's current HP so... "a.hp."
What is the formula set to currently? (also, I realize I may have made a mistake with the scope, it should probably be 1 enemy instead)
What is the formula set to currently? (also, I realize I may have made a mistake with the scope, it should probably be 1 enemy instead)
I've got it set to "one enemy." and "Certain Hit."

The formula is "a.addState(1); a.performCollapse(); a.hp;"

A quick note. When I changed it to "a.hp+500" it started doing 500 damage instead of 0.

You know what? I think I might cut my losses on this one. I'll just make it a regular attack instead of doing it directly based off HP.

Thanks for your help.
Ah, I think I see the issue. You just set the enemy's HP to 0, but I assume the formula plays out in order, so by the time it gets to applying the damage, a.hp is already 0. Does the damage have to be equal to whatever HP the enemy lost before collapsing? I think you can record the enemy's HP before it gets set to 0, if you would still like help with that. @Teach
Same goes for this stuff:

<JS Post-Damage>
user.gainHp(-user.hp);
user.performCollapse();
</JS Post-Damage>
You seem to have gotten mostly sorted, but just to answer this anyway, this would be a notetag you put into the notebox of the skill the enemy would use. Only applicable if you utilized the VisuStella Battle Core, as I noted above.
Okay...Tried it on the Damage formula line. Technically it worked, but the enemy doesn't vanish.
If you had read the threads I linked to you in my first reply, those exact commands with the instructions to put it in the damage formula is what they all said.

Everything you've asked about was already in those threads I provided.

where exactly do I put this code?
Same goes for this stuff:
<JS Post-Damage>
user.gainHp(-user.hp);
user.performCollapse();
</JS Post-Damage>
In the post you got that from, #7, it says:
If you happen to use the VisuStella Battle Core and...like doing this kind of thing through notetags

I'm trying to set it based on the enemy's current HP
Again...the threads I gave you in my first reply tell you exactly how to accomplish that.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-create-a-self-destruct-type-move.160433/