Cover ability, substitute flag, using a states instead of HP?

So a common question I see from people is about how to make substitute work on allies at any HP, instead of just low HP. I was wondering the same thing for a while, until I found a great solution which I've been using. I found someone had posted that if you install this in your materials section in your script editor, everything will work as intended.

Code:
class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # overwrite : Check Substitute Condition
  #--------------------------------------------------------------------------
  def check_substitute(target, item)
    (!item || !item.certain?)
  end
end

Which is great! Works perfectly! It's there for anyone to use it if they'd like!


What I want to know, is if there is a way to further change the above formula, so that instead of looking for a discrepancy in HP values (or rather, looking that there is none? ... Which I'm pretty sure it's still not even doing!), it checks to see if enemies have a state on them instead. Allies with a state on them will be covered, while others will still be attacked as per normal.


It'd be nice to have a cover ally ability that doesn't require outside scripts, and I'm just wondering if this is possible!
Hello there. Replace the above code with this :

Code:
class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # overwrite : Check Substitute Condition
  #--------------------------------------------------------------------------
  def check_substitute(target, item)
    (!item || !item.certain?) and target.state?(state_id) #replace state_id with state's id number
  end
end

I did some testing and worked to me, but recommend you to test too.
Replace state_id with digit - the sate id number from your database.
Hope it helps.
Where is the script editor?
Before this topic closes up, here's some pointers:

1. Posting to old posts is frowned upon. If you have a question as general as that, it would have been better to start a new topic in the appropriate section or a topic that is at least recent and relevant. In fact, it's probably an answer covered in some stickied beginner topic.

2. In RPG Maker VX Ace, you should find the Script Editor on the top of your main window, next to Database, Resources, Music and Character Editor. This answer also applies to XP and VX

3. If your next reply is "but I am using RPG Maker MV", then you're posting to the wrong section. Sadly, I don't know if MV has a built-in editor in their Plugin section, but as MV uses Java and VX Ace uses Ruby, this code won't work with MV.

---

Hm, the script's pretty simple and useful.

Original thread: https://forums.rpgmakerweb.com/threads/cover-ability-substitute-flag-using-a-states-instead-of-hp.69985/