Enemy Action Conditions


This script allows you to define multiple custom action conditions on top of the conditions provided by the database.

The database does not allow you to set multiple conditions for a single action. This script addresses this issue by allowing you to create multiple conditions.

In order to provide flexible conditions for game developers, custom action conditions are provided as formulas, allowing you to condition your actions on anything you can imagine.


Script: download here


In the script editor, place this script below Materials and above Main


When setting up the enemy in the database, you can set up the actions that the
enemy can use. Each action has an ID: the first action on the list is ID 1,
the second action on the list is ID 2.


To add an action condition to a particular action, use the note-tag

<action condition: ID>
</action condition>

Where the ID is the action ID, and the FORMULA is any valid formula that
returns true or false. All conditions must be met in order for the action to
be usable.

The following formula variables are available:

a - the enemy
p - game party
t - game troop
s - game switches
v - game variables

You may also like...

39 Responses

  1. DBZFan13 says:

    Hey, I’m trying to check if an enemy is at level 6.

    Example 1: a.level >= 4
    Example 2: a.level == 6

    I use enemy levels and parameter table. Both scripts from this website.

    It only works at level 1, even though it’s at level 6.

    • Hime says:

      Odd that it works at level 1. Have you tried this in a new project and see if it could be a script conflict?

      • DBZFan13 says:

        I figured it out. When I open up a new project, I added ‘parameter table’ first, then ‘enemy action condition’. Lastly, I added enemy levels. And now it works.

        That means there could be incompatible scripts in the other project. I’ll disable those until I find anything incompatible.

        And thanks!

      • DBZFan13 says:

        Turns out this script isn’t compatible with victor engine. Could you edit this script to make it compatible? If not, let me know and I’ll post this to rpgmakerweb.com.

  2. bloodyliao says:

    Excuse me, how to make a skill usable by enemy only when any one of them is hurt?
    I tried this one, but fail.

    !(t.hp_rate * 100) == 100
    </action condition>

    • Hime says:

      That’s because t is the troop itself, not an enemy.

      Assuming there are two enemies, and you want a skill to be usable when one of them is hurt, you can say
      t.members.any?{|mem| mem.hp_rate < 1}

      However if they restore their HP, then the condition is false again.

  3. Emily says:

    Would this work on party members as well? Or at least a way to edit it to make it work? I’d like some party members to have skills that are only usable if a variable is at a certain value or a switch is on. Is that possible?

  4. Anonymous says:

    I know this is late but I was wondering if it’s possible to make the enemy use a skill on an ally enemy when a certain state is applied to their ally. I’m basically trying to get my enemies to have a chance to revive each other.

    • Hime says:

      It would be possible to check if “any” allies have a particular state, but it wouldn’t be possible to check if a specific ally had that state. The script only specifies whether the action can be used, and not whether the action can be used on a specific target (as the script does not handle any target related properties).

      I’m not sure if you would be able to accomplish what you want with this script on its own.

  5. Anonymous says:


    I’m having some trouble with this script and I’d like some advice. If my actor is using attack A, then they’re in state A. When this happens, I want my enemy to attack them over all else. However, if my other actor uses attack B, then they’re in state B. Is there a way to have my enemy attack the actor in state B over the actor in state A?

    • Hime says:

      This script is mainly focused on whether an enemy is able to use a skill.
      Have you considered having state B simply increase the TGR parameter that makes it a more likely target?

  6. Anonymous says:

    Skill chain?

  7. Alex says:


    This is a minor question/comment.

    I’m trying to put cumulative conditions on the same skill.

    In concrete… my acrobat have two skills raising either evade or magic evade.
    I use the conditions so it wont use any of these skills if either state is up.

    I first tried to have both in one condition…

    !a.state? (242)
    !a.state? (243)

    But then the acrobat was using the skills if any of the two wasn’t up.

    Now i use two conditions for the same skill :

    !a.state? (242)

    !a.state? (243)

    And it works as intended, so it’s not a blocking issue.

    Yet i Wonder if there isn’t a simpler/smouther way to write it down.

    If not I hope it’ll help people trying to do the same.

  8. velicue says:

    Hi I’m using the game variable but it seems to be not correct.

    v[2] == 1

    It tells that if variable no.2 is 1 then use action 1. Is this correct?

    • velicue says:

      Oh it’s ok now. The problem is I forgot to save the game file after I inserted the script. The script is great and thanks a lot!

  9. Joey Desud says:

    Do you know of any way to get an enemy to use a skill only on characters without a specific state?

    For example I’m using

    !p.members.any? {|mem| mem.state?(5) }

    to get an enemy to confuse party members that don’t have the status effect. But the enemy still just seems to target randomly anyway.

    • Hime says:

      Unfortunately due to the way actions are processed by default, it chooses which skill to use before it chooses which battler to target.

      The check only occurs during the skill selection step. This is why there is no variable for the target.

  10. Alex says:


    I have some questions for i have no knowledge of formula.

    I’d like to have an enemy using a skill when one member of the party have a specific state.
    I tried with “p.state? (3)” but it doesn’t works, perhaps because “p” means the party and not one character.

    I also Wonder how to reverse this condition.
    For exemple, i’d like the enemy to cast a skill when it doesn’t have a specific state.
    In the same way, is there a way to have an enemy use a skill when no one in the party have a specific state?

    Alternatively, if you know a good place to learn about formula… i could learn to fish.
    I had a look at “How to make the most of custom formulae. Part #1” but it seems focused on damage formula.

    Thanks in advance.

    • Hime says:

      Yes, p refers to the party object. If you want to make it so that a skill is used when any member of the party has state 3, you can say

      p.members.any? {|mem| mem..state?(3) }

      Which simply asks whether any member has state 3.

      For the reverse, you just need to stick a ! in front to negate it

      !p.members.any?{|mem| mem.state?(3)}

      Which means if someone has the state, then it won’t be used.

      If you can do damage formulas then you could do any other formula. The principles are the same. For learning, I’m not sure what would be the best approach because you can basically do anything. That topic is likely a good place to start since it focuses on specific applications.

      • Anonymous says:

        Can I make enemies use magic and special attacks in a specific order with this script?

        • Hime says:

          Not directly, but if you can enforce some sort of order by using conditions (such as variable value) and then having each skill change the variable value, you can then force the enemy to use certain skills in that order based on the variable. Or you can use states. It’s up to you to think about the logic.

    • Alex says:

      Ok i just tested and it works fine. Thanks!
      I’ll have a closer look at the guide.

      • Alex says:

        I am terribly sorry.
        Another question or two.

        if i write “!a.state? (X)” it will use the skill only if it doesn’t have the state? (for self casting buffs)

        Also, i couldn’t find how to use a switch as a condition. “$game_switches[x] ?” doesn’t seems to work.

        Hopefully it should be the last time i bug you (with this script).

        • Hime says:
          1. Yes. Does it do that?

          2. Example

          if s[1]
             # switch one ON
             # switch one OFF
          • Alex says:

            1 – it works all right.
            2 – I don’t manage to make it work.
            Actually i don’t know how to make sure the condition is registered. I tried two things :

            if s[1]


            if s[1]

            None worked.

            At worst i can replace the switch with a state marker inflicted on the whole troup.

            Out of curiosity i also tried …

            !t.members.all? {|mem| mem.state?(177)}

            Hoping the skill wont be used if the whole troup have a specific state, but it doesn’t work…

            Guess it’s not that simple ;p

          • Hime says:

            Try just writing

          • Alex says:

            I can’t reply to the last message so i reply here.
            s[1] works and !s[1] works too.
            Thanks a lot.

  11. WCouillard says:

    I had all four battle members inflicted with a state, and had set the enemy to not select the action unless at least one member wasn't inflicted with the state, and the enemy still randomly selects to use that action.

    "condition eval 2"
    p.any? { |a| !a.state?(33) }
    "/condition eval"

    Replaced the code in quotes so it wouldn't parse weird here.

    Do I have the note tag wrong? Should it be b.state?(33)?

  12. RogueDeus says:

    Just to clarify. Is the use 'rating' selection in the tool set still the primary factor in chances of one ability used over another? Assuming they are available.

Leave a Reply

Your email address will not be published. Required fields are marked *