Help Needed Creating “Glitch” State with Action-Fail + Conditional Damage Logic

Hi everyone! I’m working on a custom state effect in RPG Maker MZ using the VisuStella Battle Core plugin, and I’ve run into a wall I just can’t seem to climb over.
I'm creating a State called “Glitch” that functions like this:


  • When afflicted, the target has a 50% chance to fail any action they attempt.
  • If the action fails, they:
    • Take minor Void-elemental MATK damage.
    • Have a 10% chance to be re-inflicted with Glitch.

Think of it as a semi-stun with backlash punishment for trying to act.

What I’ve Tried So Far:​

  • Set up the state in the database with Restriction = None.
  • Used the <Action Start Eval> notetag in the state to try to run conditional JS on each action.
  • Tried integrating it via the JS Pre-Action Start field in the Battle Core plugin settings.
  • Made sure the plugin load order is correct, and even reinstalled the plugin.

Still, the enemy can act freely and the damage/effect doesn’t trigger.
I even get errors like:
TypeError: this.subject is not a function
TypeError: user.requestAnimation is not a function
TypeError: Cannot read property 'scope' of null

Details You Might Need:​

  • RPG Maker MZ (latest version)
  • VisuStella Core Engine + Battle Core plugins installed
  • Glitch State ID: 0011
  • I attempted using state.meta["Action Start Eval"] from inside plugin eval scripts
  • I’m not using any Skill Sequences plugin, since it’s not part of the current VisuStella bundle
  • Tried placing the logic in Battle Core's JS Pre-Start Action as well


    What I’m Looking For:​

    • Is there a correct way to check and intercept an action attempt while a State is applied?
    • Should I be using a different plugin (e.g. Skill Sequences or Buffs & States Core, if available)?
    • Am I putting the logic in the wrong place (plugin eval section vs state notetag)?
    • Is this something doable with just Battle Core? Or do I need another plugin/plugin combo.

I know this is a pretty advanced request and probably a weird edge case, but I’d really appreciate any insight, workaround, or correction. I’ve been banging my head on this for a while


Let me know if you need to see screenshots or test project files!


— CEA
Hmmm, aren't you like mixing VS and ATT_Turan plugin notetags? Did some AI give you that?
And you didn't show how you made the fail? You can bake it into action sequences, but you'd have to do it in every sequence. Or I guess you can try something like:

<JS Pre-Start Action>
if (Math.randomInt(2)){
this.item().successRate = 0;
user.gainHp(-X);
if (Math.random() < 0.1){
$gameVariables.setValue(Y, 1); // use this to store that you need to reapply state later
}
}
</JS Pre-Start Action>

But that would just show a miss (and you'd have to set it back with another notetag), maybe someone else knows something better (there's always the A-sequences route). You can also control a variable in that notetag to save if the glitch activated and then use another notetag to apply the state at like turn-end or whatever with a conditional user.addState(X)(and put variable back to 0).


EDIT: Hmmm, actually that successRate solution is bulls***, since it only takes effect after. So the only solution I have are the actionsequences.

EDIT2: No wait, I'm just confusing myself. It does seem to work with setting the sucessRate.
But that would just show a miss (and you'd have to set it back with another notetag), maybe someone else knows something better (there's always the A-sequences route).
instead of failure being a miss, you could make failure be not being able to act. you could adapt the yanfly tip for pokemon paralysis since it does most of what was asked.
This is Trihan's visustella version of it
Code:
<JS Pre-Start Action>
  const paralyzeRate = 0.75;
  if (Math.random() < paralyzeRate) {
    $gameTemp.requestAnimation([user], 64);
    if (user.currentAction()) {
      user.useItem(user.currentAction().item());
    }
    this.setSkill(286);
    const logWindow = SceneManager._scene._logWindow;
    if ($dataStates[71].message3) {
      const msg = '<CENTER>' + user.name() + $dataStates[71].message3;
      logWindow.addText(msg);
      logWindow.refresh();
    }
  }
</JS Pre-Start Action>
and you make a new skill be the one that gets used if the roll fails that deals damage to the user and has a 10% chance of reapplying the state
If you don't mind the visuals that come with it, you could also try to replace your actors action in place with a "Glitched" skill that applies the damage and state to the user. I have not tested this:

JavaScript:
<JS Pre-Start Action>
  let glitchChance = 0.5;
  let glitchSkillId = 17;
  if (glitchChance > Math.random()) {
    this.setSkill(glitchSkillId);
  }
</JS Pre-Start Action>

Edit: Robro was faster
Edit2: Fixed a misconception, "this" seems to refer to the action here, not the BattleManager.

Still, the enemy can act freely and the damage/effect doesn’t trigger.
I even get errors like:
TypeError: this.subject is not a function
TypeError: user.requestAnimation is not a function
TypeError: Cannot read property 'scope' of null
You have not posted what code exactly you tried, but based on the error messages:
1. You could try BattleManager._subject (Assuming "this" is supposed to be the BattleManager here)
2. You could try $gameTemp.requestAnimation([user], animationId )
3. Not sure what happened here, but you may have tried to access an action that does not exist.
Cool, yeah didn't know it was that easy to swap the skill with a single line. Btw what's happening with Trihan's notetag? Like why is there first a line to use the current action item? And after that a line to set the skill?
Like why is there first a line to use the current action item?
Its how Yanfly originally set it up. one of the effects of the state was that the skill costs for the current skill would be paid like normal even if the state were to cancel and replace it. useItem() doenst actually lead to invoking the skill. it more or less handles all the things that should happen on its execution like cooldowns, consuming items, mp costs, etc
Hey all! Just wanted to say thank you to everyone who chimed in—especially @rpgLord69, @Robro33, and @Another Fen . Y’all were a huge help.


I’ve settled on using this.setSkill() in a <JS Pre-Start Action> to swap the target's action with a custom “Glitch Feedback” skill if the RNG check hits. It’s not 1:1 with what I originally imagined (a full paralysis + damage proc), but it’s simple, effective, and doesn’t break the engine. The advice about scope issues and animations also helped me stop crashing the game


If anyone ever attempts something similar using Action Sequences instead, I’d love to hear it.


Appreciate the help again!
a full paralysis + damage proc
thats easily doable, but the thing is that...
minor Void-elemental MATK damage
is something that only really exists through a skill/item. When youre working outside of skills, damage is just damage. it wont go through the normal damage calculation steps actions do and factor things like element unless you make it.

Code:
if (Math.random() < .5) {
  $gameTemp.requestAnimation([user], 64);
  user.clearActions();
  user.gainHp(-Math.ceil(user.mat*user.elementRate(9)))
  if (Math.random() < .1)
      user.addState(state.id)
}
above is the basic form of what you said where it completely cancels the skill when it procs, plays an animation, deals damage based on an element rate, and has a chance to reapply itself, but itll do only that

Edit:
left out the negative sign 🤣

Original thread: https://forums.rpgmakerweb.com/threads/help-needed-creating-glitch-state-with-action-fail-conditional-damage-logic.178405/