State Applying on Missed Attack

So, I'm using RPG Maker MV. I cannot figure out how to fix this, but when my enemy uses a special ability that applies a state to the character... that state still applies if the attack misses. Is there anyway I can make the state not apply if the attack misses, or if the target evades?

I am using Yanfly's Action Sequence 1-3, but I can't find anything within those plugins for states not applying if missed.

*EDIT* Actually, I do most of my skills/attacks through the note section using Yanfly's Action Sequence packs. I can't find anything (possibly under Lunatic Mode) but is there a way I could, maybe, create a conditional branch of "if attack misses/evades" nothing... else... "action plays out and state applies?" I just can't find anything regarding an attack missing/evading.

Requested this be moved to plugin support.
Your best bet would be to share the sequence in question.
Someone will very likely be able to pick out what is causing the issue once you do.
"if attack misses/evades"

Actions have a result that you can check. Game_Action has result.missed and result.evaded, if you specifically want to check for a miss or evade. Game_ActionResult also has isHit() which simply returns if the action was neither evaded or a miss.

I am not familiar with Yanfly's action sequences or the related notetag syntax, but if you post what you currently have either I or someone else can see what you are trying to do. The required code will probably depend on what phase of the action you are trying to check.
Sure. Thanks for your help everyone. Here's what my notetag syntax looks like currently under the skill in question. Just to give you an idea what it's doing. Enemy does a ranged attack that applies an acid state. Based on what I have below... even if the attack misses (or gets evaded) the acid state still applies (6-8 are different levels of that state).

I was thinking I could use an "If" statement to check if the attack misses/evades, I'm just not sure how the syntex should be worded/look. I can't find anything within Yanfly's action sequence.

1651546973844.png

1651546995428.png

1651547015864.png

1651547036447.png


Let me know if you need any other details or screenshots 🙂

Thanks again!
@AeroFunk80 Give these threads a look:
Thank you so much for that! The second link is what's working for me. However; I think I'm missing something in my code. When a miss happens, the animations don't play out... and the first state does apply... but then after that the other 2 states won't apply. So I appear to have it set up (almost) correctly. I may have an END or ELSE positions wrong, but I can't figure it out.

Basically, if the enemies attack hits, it applies State 6. If that enemy hits the player again... it deletes State 6 and then addes State 7. Hit again... remove State 7 and add State 8.

Right now, with the syntax below... when missed, it doesn't do the hit animation but applies State 6 the first time. However; when the enemy hits again... it doesn't apply State 7 or State 8... so... it's doing it partly. Not sure why it's applying State 6, though...

1651560342154.png

1651560360018.png

1651560376333.png

1651560401368.png

1651560732944.png

1651560748210.png


For the part above after

ELSE
if target.isStateAffected(8)

I do have a space between that and the next ELSE

I've moved this thread to Plugin Support. Thank you.

The problem is you have nested if statements. Yanfly's Action Sequences aren't designed to parse that.

A few notes for you:
- Using better indenting will help you to keep track of things. For example:
Code:
if target.isStateAffected(2)
    animation
    ...
    wait for animation
else
    perform action
    action effect
    if !target.result.missed()
Here you can easily see that the if is still inside of the previous else.

- Tied to this, there are two places lower down where you do
Code:
else
if
This will fail the way you've typed it, because you're putting an if inside of an else. If you had left it on one line, else if is recognized by Action Sequences per the documentation for AS 1.

In your specific case, that's a moot point because all of that is still nested inside of your first if.

This plugin will allow you to do what you're trying to do:

Presuming that you actually want things nested that way. Like I said, with your formatting it's a bit hard to be sure that you actually want things where you put them 😉

Last suggestion: next time, post your code inside of code tags (the </> on the top bar) instead of posting pictures of text. I would've put more detailed examples of stuff for you, but I'm not going to look at your pictures to retype your code 😛
The problem is you have nested if statements. Yanfly's Action Sequences aren't designed to parse that.

A few notes for you:
- Using better indenting will help you to keep track of things. For example:
Code:
if target.isStateAffected(2)
    animation
    ...
    wait for animation
else
    perform action
    action effect
    if !target.result.missed()
Here you can easily see that the if is still inside of the previous else.

- Tied to this, there are two places lower down where you do
Code:
else
if
This will fail the way you've typed it, because you're putting an if inside of an else. If you had left it on one line, else if is recognized by Action Sequences per the documentation for AS 1.

In your specific case, that's a moot point because all of that is still nested inside of your first if.

This plugin will allow you to do what you're trying to do:

Presuming that you actually want things nested that way. Like I said, with your formatting it's a bit hard to be sure that you actually want things where you put them 😉

Last suggestion: next time, post your code inside of code tags (the </> on the top bar) instead of posting pictures of text. I would've put more detailed examples of stuff for you, but I'm not going to look at your pictures to retype your code 😛
You're the best! Thanks! I added the plugin to my game. So, I feel like I'm getting closer. Everything I want to happen is except one thing... here's my code, copy and pasted (not sure why I didn't do this the first time LOL):

<target action>
MOTION MISSILE: user
SE: VA_Minion_Attack2, 100, 120, 0
WAIT: 5
SE: Enemy_Spit, 100, 100, 0
wait: 10

if target.isStateAffected(2)
animation 137: target
Wait: 30
animation 172: user
ACTION EFFECT: user
SE: VA_Minion_Hurt1, 60, 100, 0
wait for animation
ELSE
perform action
action effect: target

if !target.result().missed && !target.result().evaded
animation 169: target
if target.isStateAffected(6)
remove state 6: target
add state 7: target
ELSE
if target.isStateAffected(7)
remove state 7: target
add state 8: target
ELSE
if target.isStateAffected(8)
...
ELSE
add state 6: target
END
END
END
END
wait for movement
END
</target action>


I probably have too many ENDs or not in the right place. The thing is...

When my enemy spits acid at the player and hits... it applies state 6. When they spit acid again... it applies state 7. Same thing. It will then apply state 8. This all works when the attacks hit.

When the enemy spits acid at the player and it misses... it still applies state 6. However; when the enemy spits acid again and misses... this time it doesn't apply state 7. Same thing with the third attack. It doesn't apply state 8. So, not sure why it's applying the first state but not the others...

Other than that... everything else appears to be working. I feel like I'm 80% there LOL

Also... I'm getting there. Are you, at least, slightly proud of me @ATT_Turan ? 😛
I probably have too many ENDs or not in the right place.
This would be much easier to check if you took my advice about proper formatting 😉

We're going to get rid of it being bolded and put it in code tags and indent properly. (why are some commands randomly capitalized, and others randomly all upper case? It doesn't break anything, but it looks weird)

As I start doing this, I see it actually has some indentation now, but for some reason you bolded it instead of using the code tag, so indentations are lost.

Code:
<target action>
MOTION MISSILE: user
SE: VA_Minion_Attack2, 100, 120, 0
WAIT: 5
SE: Enemy_Spit, 100, 100, 0
wait: 10

if target.isStateAffected(2)
  animation 137: target
  Wait: 30
  animation 172: user
  ACTION EFFECT: user
  SE: VA_Minion_Hurt1, 60, 100, 0
  wait for animation
ELSE
  perform action
  action effect: target
This looks wrong to me. You probably want all of these following checks to happen regardless, but they're actually inside this first ELSE still. That means all of this only gets looked at if the target does not have state 2.

Code:
  if !target.result().missed && !target.result().evaded
    animation 169: target
  if target.isStateAffected(6)
Right here, this is wrong. Your if is inside of an if, so it should be further indented. If it's not supposed to be, put your end first.

So, fixing that and moving on...
Code:
  if !target.result().missed && !target.result().evaded
And same idea here. Everything from here on out is inside of this check to say the attack did not miss.
Code:
    animation 169: target
    if target.isStateAffected(6)
      remove state 6: target
      add state 7: target
    ELSE
      if target.isStateAffected(7)
       remove state 7: target
       add state 8: target
      ELSE
        if target.isStateAffected(8)
          ...
        ELSE
          add state 6: target
        END
      END
    END
  END
  wait for movement
END
</target action>

When the enemy spits acid at the player and it misses... it still applies state 6.
I'm not sure why, it looks like it's buried deep inside of the check for a successful hit.
@ATT_Turan Aha! That did it. I was writing my code within the database notetag, which made it more challenging due to not being able to see it all, but my big brain eventually realized that writing it out in a word document first helped. 😎 I'll do that going forward.

Thanks again!!
Just a word (ha) of warning: unless you explicitly disable it, rich text editors like MS Word may automatically replace some characters, e.g. "text" -> “text”, which can break or change the meaning of code. So it might be a better idea to use a simpler text editor instead, e.g. Notepad. 👋

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/state-applying-on-missed-attack.147266/