Battle Rules


This script allows you to set up “battle rules” for victory or defeat. All battle rules must be met in order to achieve victory (or defeat).

The default battle rules are

default victory rules: all enemies are dead
default defeat rules: all actors are dead

There are four scopes for battle rules

  • Global battle rules
    These apply to all battles. These are the “default” rules.
  •  Map battle rules
    These apply to all battles that occur on the current map
  •  Troop battle rules
    These apply to any encounter with this troop.
  •  Event battle rules
    These apply to encounters on a per-event basis

There are two ways to specify rules for a battle

  1. Set rules. These overwrite any previous rules. So for example, if you had defined map rules and troop rules, but then have “set” event rules, then all of the map rules and troop rules will not apply for this battle.
  2. Add rules. These are added on top of any previous rules, so you can add event battle rules to any troop rules or map rules.


Script: download here
Addon: Battle Rule Display – displays the battle rules

Note that the current version is not compatible with the battle rule display. You will need to use the previous version, though it does not come with rule groups. You can get the previous version here.


Place this script below Materials and above Main


All rules use the same syntax as follows:

<victory rule: add>
cond: some victory condition
desc: some description
group: 1
</victory rule>

<defeat rule: set>
cond: some defeat condition
desc: some description
group: 2
</defeat rule>

cond is the condition of this rule, as a ruby statement that evaluates to
true or false.

desc is a description of this rule. This is not necessary, but maybe some
other scripts will find some use for it.

group is the rule group that this rule will be placed in. If the group is not specified, is will default to 1.

Add and set types apply to both victory and defeat rules. They are just
example syntax.


For maps, they will be written in the note-box
For troops and events they will be written as comments.

All rules must be satisfied in order for a victory or defeat condition to be
met, so if you have 3 victory rules, then you must meet all 3 rules in order
to win a battle.

In the configuration, you can modify the default rules as necessary.

Rules Groups and Multiple victory/defeat conditions

Sometimes you would like to be able to say victory is achieved if one task is completed, or maybe another task is completed. For example, perhaps the victory conditions are

  1. Kill all enemies, OR
  2. Wait 5 turns

You can accomplish this using logical OR’s in your formula like this:

<victory rule: set>
Cond: (the appropriate condition, as a ruby statement. Could be very long)
Desc: kill all slime OR wait five turns
</victory rule>

Alternatively, you can use Rule Groups. These groups come with the following properties:

  • All rules WITHIN a group must be satisfied in order to satisfy the group
  • Only ONE group needs to be satisfied in order to achieve victory (or defeat)

The above victory condition can be re-written as follows:

<victory rule: set>
Desc: Kill all slime
Cond: $ {|mem| == 1}.empty?
Group: 1
</victory rule>

<victory rule: set>
Desc: Wait 5 turns
Cond: $game_troop.turns >= 5
Group: 2
</victory rule>

By using rule groups to organize your battle rules, it becomes much easier and cleaner to manage rules for a battle.

Endless battles

It is possible that you may end up in a situation where the battle simply cannot end because the rules are set up so that at some point you will be unable to complete them. There is currently no default way to handle this, so you just have to make sure there is always a way to end a battle

You may also like...

43 Responses

  1. Johnny says:

    Hi Hime,

    Is it possible for this to be translated to MV Javascript? It would be great if there is a MV version of this!

    Thank you!


    • Hime says:

      I will explore some solutions on how to best implement the victory/defeat conditions. The general idea is to be able to create custom victory/defeat conditions (potentially for specific battles, specific maps, and so on), but it would be nice if it wasn’t limited to a comment.

  2. Amyrakunejo says:

    Anyone remember the Final Fantasy games? How if your entire party were inflicted with certain states you’d lose? I’m having trouble implementing such states.

    Can anyone assist?

    • Hime says:

      In the configuration section of the script, you can modify the Defeat Rules by adding more conditions.

      Here is an example where if the entire party has state 1 or state 2, then it is game over:

      "$game_party.all_dead? || $game_party.battle_members.all?{|mem|mem.state?(2)}" => "All allies defeated"

      The relevant parts are the || which means “or”, and the part after which checks all members that are currently in battle for state 2.

      You can replace the existing rule with this one and then test it out to see it in action.

      • Amyrakunejo says:

        Sweet. It works. Now, how to make this so the effect happens with multiple immobile states? I’d try to guess it on my own, but I don’t want to mess anything up and potentially lose my project. But merci beaucoup for the great help! Means a lot.

        • Hime says:

          Instead of using || which is OR, you can use && which means AND. So if you require multiple states to be applied before game over occurs, you can use &&.

          • Amyrakunejo says:


            So, it would look like this…?

            “$game_party.all_dead? && $game_party.battle_members.all?{|mem|mem.state?(#)} && $game_party.battle_members.all?{|mem|mem.state?(#)} && $game_party.battle_members.all?{|mem|mem.state?(#)}” => “All allies defeated”

            But, say I wanted just one of these states to apply, but had several possibilities. It would look like this…?

            “$game_party.all_dead? || $game_party.battle_members.all?{|mem|mem.state?(#)} || $game_party.battle_members.all?{|mem|mem.state?(#)} || $game_party.battle_members.all?{|mem|mem.state?(#)}” => “All allies defeated”

            Now then, if that is completely correct, How would I flip this to make it to where the enemy is defeated if these states are applied to all enemies?

            Would I simply change “$game_party.” to “$game_troop”?

            Of course, I know to place it in the Victory Conditions.

            Also, if I did the whole ‘one state or another’ thing, let us say I have two different immobile states, and use the OR option for them. Would it still work the same if two of my party members were afflicted with one state, and the other two with the other state? Or would that require a different type of scripting?

            Sorry for the long reply. I’m just trying to, as they’d say, ‘get all my ducks in a row’. I’m sure I could figure this out, but ‘when in doubt, call the expert’, and here that’s you, not me. Thanks much for the help. Much appreciated, milady (I presume you’re a woman).

          • Hime says:

            Yes, you would just change it to the game troop to check all enemies. They do not have battle members though, so you would need to use $game_troop.members instead.

            If you would like to check if all members have any of those states, you could say

            $game_party.battle_members.all? {|mem| mem.state?(#1) || mem.state?(#2) }

            Which checks if all members in the battle have either state #1 or state #2.

  3. MoonPrincess says:

    What email do I send this tiny game file to?

    • Hime says:

      Use the contact me form.

      • MoonPrincess says:

        I tried contacting you via that contact form… And a person can’t upload files to that.
        Unless you’re talking about that github thing.
        Frankly, I have NO IDEA what I’m looking at. I’m just an average person. I feel like I’m reading Latin, that github pages makes no sense.
        Why can’t I just email this to you or send a link via Google Drive? I’m not a programmer.

        • Hime says:

          The contact form sends a message to my primary email used for this site.

          If you already have the files on google drive then you can copy a link to the drive files and paste it in the body of the contact form. There is no reason why you would need to re-upload the files again via email attachment.

          • MoonPrincess says:

            Too late. I’ve already made an account with your github. Besides, you ignored me when I used that contact form. Check it out there, or not. Whatever you want. At this point I’m so frustrated. If you’re also in Japan, I can send you money to make this headache go away. Just fix this problem.

          • Hime says:

            I’ve replied to the github topic.

  4. MoonPrincess says:

    AH, the conflict lies with ‘Actor Voices’ in Battle by DiamondandPlatinum3..

    • Hime says:

      If you send me a project set up with only those two scripts showing the problem I could see what’s going on. Remove the dll for the system folder. Ideally your project would be less than 500 KB

  5. MoonPrincess says:

    I have no understanding of Ruby, so this is impossible for me to use alone.

    What if I want to make an' escort to safety mission'. If a certain actor (actor #13) dies, it is game over. How do I make that a rule and where to I plug it in?

    Thanks for any help you can give.

  6. Wavelength says:

    Hi Hime! I've been trying out several of your scripts and I'm amazed how flawlessly they work, but this one is giving me trouble. I want to add a Troop-level condition that immediately ends the battle in Victory if you defeat the Boss monster (the first monster in the enemy party).

    I tried placing the following in an Event Page Comment for the troop, experimenting with both a page of its own (with an "Always ON" switch that's activated on Turn 0) and at the top of the first page (which runs on Turn 0). The span of both event pages is 'Battle'. This is the only Victory/Defeat Rule I'm trying to add.

    [victory rule: add]
    cond: $game_troop.members[0].hp == 0
    desc: Destroy the Boss Monster
    group: 1
    [/victory rule]

    (The [ ] brackets are correctly typed as carats in the script but it messes up the post to use them.)

    I used the same code from the "cond:" line ($game_troop.members[0].hp == 0) inside a Custom Page Condition on the next Event Page for the troop, and it worked perfectly, running the event's code when the Boss Monster was defeated. So I'm thinking I must be putting the Victory Condition in the wrong place.

    Think you can point me to the right place to add it? Thanks!!

    • Hime says:

      Adding victory rules means it is in addition to whatever rules are applied for this battle (global rules, map rules, etc.)

      If you want the particular battle to use its own rules, use "set" instead of "add"

      • Wavelength says:

        I just tried changing "add" to "set" and it worked perfectly – thanks so much! ^_^

        If I wanted to have a battle where two different conditions both needed to be met in order to win that battle, I would use one SET condition and then one ADD condition to the same group?

        • Wavelength says:

          Never mind the above – I played around with it more, and it looks like I would use two SET rules to accomplish that. The idea of "overwriting" previous rules was throwing me off but it looks like it only overwrites rules that have higher scopes.

          I appreciate your help leading me onto the right path with SET, much obliged.

  7. Pixel Brady says:

    Only problem with this is that it seems to require knowing ruby code to make any conditions other than the default “everyone dies” options. Could possibly add in a wee section of suggested options or possibilities for those of us who are code-blind! 😀

    Other than that; do me a wee favour and help me with the specific one I’m looking for? 😀
    I’m wanting to set event driven battles so that if you kill the baddy, you win (which is already in the script) but if they run away, you lose. Any chance you could let me know what the ruby would be for that? 🙂

    Cheers for the nifty script~

    • Tsukihime says:

      I think it’s easier to just ask someone how to write a rule.

      For escaping, if you do not have any special states in your game, you can check if they have escaped using the following condition


      Where 0 is the first member in the troop, 1 is the second, etc.

      • Pixel Brady says:

        Fair enough; I suppose people’s needs would vary a lot anyways~

        Cheers for that wee code; solves a wee problem I had no idea how to fix ^^
        Right on time as well, I was just about to leave the library (and my internet) for a few days 😀

        But aye, cool scripts. Have been on a script hunting mission today for a new project and kept finding myself realising it was one of yours: good work, good work~ 🙂

  8. Hugs says:

    Is there a way to make a Law System (like in FFTA) with this script? For example, make it forbidden the usage of fire spells in battle?

Leave a Reply

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