How do I make skills only work on battlers with a certain state?

I'm making a game where a programmer gets trapped in his own game, but he has powerful Debug skills that allow him to do anything from removing glitchy states, to dealing armor-ignoring damage, to outright blinking an enemy right out of existence. However, his Debug skills are useless unless he has run a memory scan on an enemy to discover its memory address (resulting in the enemy gaining a "Scanned" state).


So my question is this: How do I make it so that a skill only succeeds on a target that has a certain state applied?
I imagine it'd be something like this (let's assume your Scanned state is state #15)

Code:
b.isStateAffected(15) ? 100 : 0
You can do this in the damage formula where you check if the enemy has the state.  If it has, do x and if it hasn't, do y.


I know the Ruby syntax for Ace, but not JS for MV.  Perhaps you know enough to turn this from Ruby to JS


if b.state?(state_id); damage formula here; end; 0


That zero at the end is to tell it to do no damage if the state is not present.


There is a thread with MV damage formula questions.  It would be worth looking over for this and for other ideas.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-skills-only-work-on-battlers-with-a-certain-state.72478/