Add state on miss?

Is there a way to apply a state to an enemy if an attack misses? I've been looking around and trying to figure out something but what I've tried doesn't seem to work.
I think you'll need a script for this, though there might be a way to get clever with the damage formula. Will move it to script requests for you.
The problem with using the damage formula is that it isn't even looked at unless the attack hits. You'd probably have to build something like this into a custom script that aliases the point in battle where it checks misses.

For example, this would apply Blind to any target that evaded or was missed by an ability (though it doesn't discriminate on what that ability is, be it skill or item, heal or damage, so if you wanted more control over it you'd have to tighten up the checks a little)

Code:
Game_Battler.class_eval do
  alias :tri_item_apply :item_apply
  def item_apply(user, item)
    tri_item_apply(user, item)
    if @result.missed || @result.evaded
      self.add_state(3)
    end
  end
end
You could make the skill Certain Hit to guarantee hit, then reference hit change in the damage formula itself to determine what applies. (Sorry, I don't remember which words to use, but I know you can compare them)
The problem with using the damage formula is that it isn't even looked at unless the attack hits. You'd probably have to build something like this into a custom script that aliases the point in battle where it checks misses.

For example, this would apply Blind to any target that evaded or was missed by an ability (though it doesn't discriminate on what that ability is, be it skill or item, heal or damage, so if you wanted more control over it you'd have to tighten up the checks a little)

Code:
Game_Battler.class_eval do
  alias :tri_item_apply :item_apply
  def item_apply(user, item)
    tri_item_apply(user, item)
    if @result.missed || @result.evaded
      self.add_state(3)
    end
  end
end

Alright, I got this working, but I want it to specify a single enemy on the field. For example, say there's two enemies, if one misses an attack it gains a boost in stats, but not the other one. How would I do this by modifying the script?
You could add an if statement to the item_apply alias which checks the enemy ID (assuming they're different enemy types). Alternatively if you're planning on making this an important gameplay mechanic you could code a little script that allows you to specify something like a <miss boost> notetag which will make the effect happen.
alright i tried doing that and got the following error:
fLiFLgdVTjOPucoSEvaG1w.png


i'm not really sure what i'm exactly doing with this script yet so this is probably all sorts of wrong, but this is what i have:
Code:
Game_Battler.class_eval do
if user = (@battler.46)
  alias :tri_item_apply :item_apply
  def item_apply(user, item)
    tri_item_apply(user, item)
    if @result.missed || @result.evaded
      user.add_state(85)
    end
else
end
  end
end
anyone?
bump again?
ok i did a little more futzing around in code and produced this, which doesnt crash but also doesn't seem to generate any states from the battler like i want it to:

Code:
Game_Battler.class_eval do
  if @enemy_id == (45)
  alias :tri_item_apply :item_apply
  def item_apply(user, item)
    tri_item_apply(user, item)
    if @result.missed || @result.evaded
      user.add_state(85)
    end
  end
end
end

the only problem here is that it doesn't apply the missed state. for reference enemy_id 45 references the 45th enemy in the enemies list right?

EDIT: I got it working for my purposes, but I don't think it would work for the purposes of anyone else. Basically I edited the above script so it checks for the target's id and not the user's, using the same if statement that checks for misses.
If you got it working, good for you. Just take note that each of your 3 last posts are all within 72 hours of the one before it. This is against forums rules. You should read those.
You must edit your last post if you have to add more information, until 72 hours have passed and then you can post a new one.

Original thread: https://forums.rpgmakerweb.com/threads/add-state-on-miss.85948/