Check to see if a skill's target has a state (Yanfly plugins)

Because I can't seem to stop needing the forum's help...

I am using pretty much all of Yanfly's plugins - this question focuses on his Battle Engine and Element Core.

I want to build a skill that checks an enemy for state A, and if they have it, adds element A to the skill, otherwise it checks for state B, and if it finds it, adds element B, and if not then checks for state C .... you see where I'm going with this. Every enemy in the game will have one of these states, so there's no need for any == nil stuff....

Here's a non-JS version of what I think it should look like. I'm just not sure how to reflect this using actual JS (I'm learning, but I honestly am having trouble finding a good repository where I can clearly see exactly what JS string references what...)

<setup action>
If target has state A, then ADD ELEMENT: A
else target has state B then ADD ELEMENT: B
else target has state C then ADD ELEMENT: C
...
...
</setup action>

Anyone able to point me at how I check this using JS? Thank you guysssss.
EDIT: Naveed got what you we're trying to do more than I did. my bad

You baiscally just wrote it.
Code:
if (target.isStateAffected(STATE ID HERE)){
target.addState(STATE ID HERE)
}

You can pretty much just make a bunch of if branches like that and it should work fine.

There's probably better more custom pluginy ways of doing it, but it should work regardless
Try:

<setup action>
if target.isStateAffected(stateId1)
add element: elementId1
else if target.isStateAffected(stateId2)
add element: elementId2
else if target.isStateAffected(stateId3)
add element: elementId3
else if ...
...
...
else if target.isStateAffected(stateIdX)
add element: elementIdX
end
</setup action>

Change the text in red with the appropriate State Id and Element Id.
That solved it perfectly, thank you kindly Naveed, you are a scholar and a gentleman.
I'm having a similiar problem, the diferrence is that I think I actually need the nil stuff, but i don't do a lot of javascripting. So i'm doing a skill that will work this way:

Apply a state to the enemy -> use skill again -> if enemy has already the state do damage instead

I've come to this action sequence:

<Target Action>
If target.isStateAffected (12)
Action effect (Coment: this will be the damage)
Else
Add State 12: target
End
</Target Action>

The problem is that the skill will always deal damage and won't apply the state any time.
If someone can help me, I'll be very gracefull.
Necro-post notice: Geriancomp
It is also hi-jacking, that is, asking a different question from that of the OP.

I suggest you start a new thread with your particular query. If it helps explain things, you can link back to this thread.

Moderator note: Closing.

Original thread: https://forums.rpgmakerweb.com/threads/check-to-see-if-a-skills-target-has-a-state-yanfly-plugins.81720/