Skill reconogizing if the Target has a State

I'm trying to make some special skills that has an additional effect under different circumstances. For example, if the enemy is Confused, Psychic attacks will trigger a bonus effect like regenerating Mana. I do this running a common event. However, I can't seem to find a way to make it work. Basically the order of things I've been trying goes like this:

1- Target is confused
2- Psychic attack normal effect
3- Detect if Target is confused, if so, run a Common event (these can contain different effects, such as Life steal, regenrating mana, draining Mana, etc.)

Anyone knows how to do this?

Thanks!
wrong sequence with the detection.

if you want to do this without plugins, you'll have to run the common event every time and check the conditions inside the common event before doing something. Use insivible target states to determine who was it and so on.

Alternative ways to handle this is using plugins (especially action sequence type plugins) or javascript in the damage formula (has some disadvantages however and you can't do everything inside the damage formula
wrong sequence with the detection.

if you want to do this without plugins, you'll have to run the common event every time and check the conditions inside the common event before doing something. Use insivible target states to determine who was it and so on.

Alternative ways to handle this is using plugins (especially action sequence type plugins) or javascript in the damage formula (has some disadvantages however and you can't do everything inside the damage formula
I'm using Action Sequences from Yanfly.
I can do some skills that depends on if the actor has a state.
1688368113002.png

But when it comes to enemies, I'm struggling to detect the target as there is no way (I think) to say "Selected target"
1688368173820.png

So if I understood correctly, it won't check the target, it will only check if an enemy in the group has it, so even if the target doesn't have the state, if other enemy has it, it will trigger? What can I do to check the selected target? I wonder if Im not seeing a command somewhere.
____
For reference, with Actor skills I do this.

If Actor 1 is Blind,
Use Skill + Common event
Detect if Actor(user) has Blind (Picture 1)
If so, Force action > Extra Skill on Last Target or other Effect

But I cant seem to find a way to replicate it when an enemy or target has the state.

I hope this extra context helps.
So if I understood correctly, it won't check the target, it will only check if an enemy in the group has it, so even if the target doesn't have the state, if other enemy has it, it will trigger? What can I do to check the selected target? I wonder if Im not seeing a command somewhere.
If you navigate to Troop events (Database -> Troops -> Battle Event) and create your Action Sequence there, the question marks should populate with the enemies for each battle scenario. That's where you're going to want to define your terms. Sorry if that doesn't help 100%.
But when it comes to enemies, I'm struggling to detect the target as there is no way (I think) to say "Selected target"
you can do that indirectly
you create an invisible target state that does nothing, has no messages and no icon.
you place that state as one target effect in the skill.

In the common event, you check every enemy index if it has that state - if yes you found the target of the skill.
you can do that indirectly
you create an invisible target state that does nothing, has no messages and no icon.
you place that state as one target effect in the skill.

In the common event, you check every enemy index if it has that state - if yes you found the target of the skill.
I'm hoping I'm not missunderstanding, but the issue comes with the targeted enemy.

As long one enemy with the state exist in the battlefield, using the skill will trigger the effect no matter if the enemy targeted is the one having it.

I did this a test with poison.

1688412922187.png


I inflicted all with poison, but when attackng Enemy 1 with the Skill, every enemy triggers the sound effect. So rather than detecting if the enemy is selected, it just detects if the enemy with the status exists in the battlefield.
If you navigate to Troop events (Database -> Troops -> Battle Event) and create your Action Sequence there, the question marks should populate with the enemies for each battle scenario. That's where you're going to want to define your terms. Sorry if that doesn't help 100%.
I think the issue still comes as the game will detect if the enemy with the status exists, rather than it being targeted, so if an enemy with the status exists, even if you use the Skill with another enemy, the skill effect will take place since the condition meets even if it wasnt your target.

Unless I missunderstood you.
As long one enemy with the state exist in the battlefield, using the skill will trigger the effect no matter if the enemy targeted is the one having it.
no, that happens due to you using a too simple logic structure.
that is why you need a target state that has no other functions, and why you need to make each branch for each enemy index an exclusive one (either using labels or exit event processing, abandoning the sequences after the first target is identified.

In your example from the first post, you cannot simply check for confusion because that can be on many enemies.
Instead you'll have to create a state "Psychic attack target" and check every target for that, then check that specific target for the confusion state and then do the effect you want to add.
The easy way to do this is with Yanfly's Skill Core. It's most effective if you take your stuff out of a common event and put it into code. So, for example, draining mana.

Code:
<Post-Damage Eval>
if (target.isStateAffected(22))
{
    target.gainMp(-10);
    user.gainMp(10);
}
</Post-Damage Eval>

replacing 22 with the ID of your confused state.
Thanks to all for the help!
I'll give it a try and experiment around.

Original thread: https://forums.rpgmakerweb.com/threads/skill-reconogizing-if-the-target-has-a-state.158902/