MV Skill that can be used only if enemy is affected by a state

Hi all! I need help with creating a skill that can be used only if the enemy is affected by a state such as stun or knockdown otherwise cant be used at all. I was searching a lot and i found how to do a skill that can do extra damage is the enemy is affected by a state but i cant find or figure out how to make a skill completely unusable if the enemy is not affected by a specific state but once the enemy has that state then the skill can be used.

I have all Yeps plugins and i was looking into the skill core and under the explanation there is a section that says:

For those with a bit of JavaScript experience, you can use the following
notetags to restrict a skill and what kind of code to process when executing
the said skill.
Skill Notetags:

<Custom Requirement>
if ($gameParty.gold() > 1000) {
value = true;
} else {
value = false;
}
</Custom Requirement>
If value is set to true, the skill will be useable provided that all other
requirements have been met. If the value is set to false, the skill won't
be useable.

<Custom Execution>
$gameParty.loseGold(1000);
</Custom Execution>
This runs the code between the notetags upon using the skill.

Now my javascript knowledge is well....bad, but could i somehow use similar notetag but instead of making gold condition requirement specific state instead? I really want to learn how to do stuffs like this because i plan to make many conditional powerful skills like this. Maybe there is some easier way? Any help is appreciated really. Thanx in advance!
it is posible with states too or buffs.
but keep in mind that gameParty.gold() > 1000 is checking if the gold
is over 1001 or more, so if it has 1000 or more, you should use >= instead.

as for the state, you need to check the user.isStateAffected(x) x being the ID
of the state.

but I dont know much lunatic code, or the YEP plugin you use for it.
as there are alot of lunatic codes and tips and tricks that can help you
what you need with small modification.
Thx a lot for your answer ShadowDragon! After trying several things i got it to work perfectly with this notetag:

<Custom Requirement>
if (user.isStateAffected(4)) {
value = true;
} else {
value = false;
}
</Custom Requirement>
But there is a problem...instead the skill being able to be used when the enemy is affected with the state n4 its available when the actor is affected with the state instead because of the user in the code. I have tried if (enemy.isStateAffected(4)) { but its not working. I have also tried b and target instead of user and its still not working. How do i fix this?
When the requirements are checked, no target has been selected yet, so there is no target to reference.

I think this'll be true iff there is at least one opponent affected by state ID 4:

<Custom Requirement> value = user.opponentsUnit().members().some(function(m) { return m.isStateAffected(4); }); </Custom Requirement>
If you want to restrict who can be selected as a target, consider a plugin like YEP Selection Control:
[Quick edit: replaced $gameTroop with user.opponentsUnit().]
Thanks a lot Caethyril! Your code works exactly as i wanted my skill to be. I have so much to learn and to understand about javascript. I saw there are many tutorials on this forums so ill start there somewhere. Thx again for your help ^_^, Shadowdragon too.
Great, you're welcome! 👋

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-can-be-used-only-if-enemy-is-affected-by-a-state.155511/