MZ Need help creating Shocked state

Im using RPG Maker MZ with some Visustella plugins. Wanted to create a shocked state, which would damage the user if it uses an attack. It works as I want it, however, when the user is killed by this damage from the Shocked state, the game throws an error:

Capture.PNG

Could anyone please help me with this ?

JavaScript:
<JS Pre-Start Action>
if (this.isAttack()) {
    let hpLoss = Math.floor(user.mhp * 0.55);
    
    user.gainHp(-hpLoss);
    user.startDamagePopup();
    
    if (user.isDead()) {
        this.subject().clearActions();
        return;  // Stop further execution of this action
    }
}
</JS Pre-Start Action>
Im surprised any damage is being done in the first place. according to the help section for the battle core, <JS Pre-Start Action> is ran as a part of BattleManager.startAction(). so your references to "this" doesnt sound like itd be to a Game_Action - which is where isAttack() would be a function.
it might be bounced to a battler at some point for execution though. i think the yanfly MV version of the tag does

what happens if you try this?
Code:
if (user.currentAction().isAttack()) {
    user.gainHp(-Math.floor(user.mhp * 0.55));
    user.startDamagePopup();
    if (user.isDead())
        user.clearActions();
}
If I use the code you provided, it throws the same error as before.
Isn't this just a poison state with a different name?

Why not just use that instead and just rename it Shock?
Isn't this just a poison state with a different name?

Why not just use that instead and just rename it Shock?
it isnt.
it damages the actor whenever they act only if they use their "Attack" skill and is also intended to be able to kill them before they act if they attempt to perform it without enough hp.

If I use the code you provided, it throws the same error as before.
ill have to play around with it then at some point. I know what you tried to do works with the yanfly plugins in MV because i have a state that does a similar thing there

VS might have rewritten the code behind action setup in a way that causes a crash when a battler has their action cleared between action start and its execution. if you try using user.forceAction(x,-2) to queue up some skill that doesnt do anything as they die, does it still crash? id test it myself, but id have to go and redownload the sample
Wherever I put the user.clearActions(); into the code, it still throws the same error.
Wherever I put the user.clearActions(); into the code, it still throws the same error.
thais why i said
VS might have rewritten the code behind action setup in a way that causes a crash when a battler has their action cleared between action start and its execution
have you tried
using user.forceAction(x,-2) to queue up some skill that doesnt do anything as they die
instead of clearing the action?
BattleManager.startAction normally only gets called for actions that exist (core validity check happens beforehand), and I imagine VisuStella didn't add any checks for the custom code deleting all actions.

I'd consider substituting the attack for a different skill that has no effect. E.g. if this is a reference to the action, then this.setSkill(123);, where skill ID 123 is a "do nothing" skill. (Replace this if necessary.)
Just to throw in a quick side note - the return statement in your code does nothing.

There are already no code statements after that to be executed, and it has no effect on whatever is happening outside of the notetag.

(your comment makes it read like you think the return will stop the current action from happening, but it won't)

Original thread: https://forums.rpgmakerweb.com/threads/need-help-creating-shocked-state.172191/