Battle Reactions

This script provides functionality for setting up “battle reactions”, which are actions that are automatically invoked in response to certain actions. A reaction is similar to a counter-attack, except instead of responding to any attack, it only responds to specific “reaction triggers” and responds with an appropriate “reaction response”.

For example, your actor might have a shield that casts “heal” on the wearer whenever the wearer is targeted by the “attack” skill. The reaction trigger is the “attack” skill, while the reaction response is to cast heal.

You can have multiple reactions occur simultaneously and all of them will be executed.

battleReactions1

Description

This script introduces the concept of “reaction objects”, which is basically
any object that supports reactions. Actors, Classes, Items, Skills, Weapons,
Armors, Enemies, and States all support reactions.

Reactions have two parts to them: the “Reaction Trigger” which activates the reaction, and the “Reaction Response” which is how the reaction will respond when it is triggered. The reaction trigger consists of a “Trigger Type” and a “Trigger ID”, while the reaction response consists of a “Reaction Type” and a “Reaction ID”.

The following reaction triggers are available:

  • Skill Reactions Triggers – when targeted by a specific skill
  • Skill Type Reaction Triggers – when targeted by a skill with a specific skill type
  • Element Type Reaction Triggers – when targeted by a skill with a specific element type

The targets are determined by the scope of the skill. By default, if the scope is for opponents, then the target is the attacker. If the scope if for allies, then the target is the defender.

Download

Script – Demo

Installation

Place this script below Materials and above Main

Usage

The following lists the reaction triggers currently available and how to use them.

Skill Reaction Triggers

To create a reaction that responds to skills, note-tag any reaction object with

<skill reaction: skill_id react_id chance forced>

Where

`skill_id` is the ID of the skill to react to
`react_id` is the ID of the skill to use in response
`chance` is the probability that it is used. 100 is always, while 0 is never. Decimals not supported.
`forced` means it basically acts like a forced action (no MP/SP consumption)

The chance can be specified as a formula, with the following variables
available to use

a - react user (ie: the battler that will react)
b - react target
p - game party
t - game troop
v - game variables
s - game switches

Note that you literally type in “forced” if you want the raction to be the
same as a “forced action”.

Skill Type Reactions Triggers

To create a reaction that responds to skill types, note-tag reaction objects
with

<stype reaction: stype_id react_id chance forced>

Where the stype_id can be looked up in the terms database.
When a skill with the specified skill type ID is used, the reaction will
be triggered.

Element Reaction Triggers

To create a reaction that responds to certain elements, note-tag any
reaction object with

<element reaction: element_id react_id chance forced>

Where the element_id can be looked up in the Terms database.
When a skill with the specified element is used, reaction will be triggered.
Note that this only considers the element of the skill, not features.

Reaction Condition

You can add conditions to your reactions. A reaction will only occur if the
reaction condition has been met.

Reaction conditions are specified as formulas. They can be any formula, and
use the same formula variables that are available to battle reactions.

To create a reaction condition, use the following note-tag

<reaction condition: id1,id2, ... >
  FORMULA
</reaction condition>

The ID’s are important: they are the reactions that the condition applies to,
where each ID is separated by a comma.

Each reaction has a unique ID, in the order that they are written in your note
box. The first reaction is 1, the second reaction is 2, and so on. Refer to
the example to understand how reaction conditions can be used

Reaction Timing

Reactions can occur before or after an action is executed. By default, a
reaction occurs after, but you can set a reaction to occur when an action
has been declared, but before it hits.

So for example, if an enemy attacks you, you may react to this by putting up
a shield, effectively increasing your defense, before the attack lands.

To set a reaction to occur before an action hits, use the note-tag

<pre react: id1, id2, ... >

Where the ID’s are the reactions that you want to apply this setting to.

Examples

The following skill reaction responds to skill 1 with skill 12 with a chance of 50% and is treated as a forced action

 <skill reaction: 1 12 50 forced>

To respond to any “Magic” skill (assuming skill type 2) with skill 14

 <stype reaction: 2 14>

To respond to any “Fire” elemental skills (assuming element ID 3) with skill 54

 <element reaction: 3 54>

Now suppose we have two reactions. The first is a skill reaction that reacts to
the attack skill (skill 1), and responds with a triple attack (skill 23).

The second is a skill type reaction that reacts to all “magic” skills (stype 2) with a heal spell (skill 51).

Both reactions will only occur if state 23 is applied.

You can begin by writing the reactions, and then write the reaction condition

<skill reaction: 1 23>
<stype reaction: 2 51>

<reaction condition: 1,2>
a.state?(23)
</reaction condition>

If you want the stype reaction to occur before the skill lands, you can simply
add the following to your note

<pre react: 2>

You may also like...

86 Responses

  1. Vossler says:

    Is there any fix to damage numbers not appearing on an attack that is “reacted to” if using the “sideview” script? It is the same script used in Blackmoon Prophecy II and Legend of Balance.

  2. Coolie says:

    Is there a way to make states applied to the character doing the reaction not lose 1 on their turn duration when using a reaction ability? Let’s say you have a status that lasts 4 actions, if the character reacts four times from one enemy attack, they lose that status condition because reactions count as taking another action. I’d like to have reactions act as free actions, and not reduce the number of turns left on a state. How can I do this?

  3. Anonymous says:

    Who’s still using VX Ace in 2019? Apparently me ^^

    Is there a way to make the reaction NOT happen if the triggering ability misses?

  4. K says:

    May I ask if the current download link is still the latest version (2013)? After utilizing it, it seems that only the skill react works with me. The element, skill type and pre action reactions all fail to show up from my build. I’d assume that there’s something off about the note tag I placed, but I think I followed through with the guide.

  5. WeganB says:

    Hi Hime!
    I am really liking the code you have designed, as it looks very useful for many situations. I am a bit confused on how to use it though.

    I am trying to create a State(26), that when the actor or enemy inflicted with it tries to preform a physical attack, they are forced to preform the skill (141) before continuing with their attack.
    These are the names of the objects:
    State: 26: Electro Trap
    Skill: 141: Get zapped (Hurts the user of the skill)

    Someone that the following script is not working because it only triggers when an actor/enemy target’s themselves with the basic attack:

    a.state?(23)
    </reaction condition>

    <

    pre-react: 1>

    Am I missing something, or is their an easier way?

  6. Grawel88 says:

    Hello Hime is possibile do this
    SO enemy whit this state replace all magic attack skill whit the same skill?

  7. Thegrop says:

    Is it possible to make multiple skill IDs trigger the reaction? Sorry if this is a stupid question. Do I just put the IDs with commas?

  8. Otabo says:

    Is it normal for the reaction to occur even after the target dies? Like, say if the target enemy reacts to wind spells and is killed by a wind spell, the enemy still responds? Is there a way to stop the enemy from reacting once killed?

    • Hime says:

      No, if the target dies as a result of the attack, the reactions will not fire off unless they are “forced” reactions. Check if you have the latest version of the script, as this was an issue at one point.

    • Arsist says:

      Just put
      return false if !a.alive?; insert_condition_here

  9. Feldherren says:

    Hello, Tsukihime. I want to use this script in conjunction with your Effect: Set Variable script; in this case, causing a skill to set a variable that is used to determine the chance of a character blocking the attack and reducing its damage. However, I suspect this won’t work as-is, because the battle reaction will need to be preemptive to reduce the damage taken.

    If I had a skill with the Set Variable effect and a battle reaction set to preempt it, would the following be the order in which things would resolve?

    a. Attacker attempts to use skill A on target

    b. Target checked if preemptive battle reaction occurs, preemptively reacts with skill B

    c. Skill A execute on target, setting variable

    If this is the case, is there any way to make Set Variable work before the reaction?

    • Feldherren says:

      Alternatively, is there a way to get the ID of the skill being used for reaction conditions? For example, I have a reaction set to potentially occur for any attack of a particular element, but want to check the specific skill used in the reaction condition. Is this possible?

      • Hime says:

        Try b.current_action.item.id which should return the ID of the skill or item that the battler just used.

        • Feldherren says:

          That’s exactly what I needed. Thank you.

          Sorry for the extra comment below. I checked back some time after the first and didn’t see this one here, so forgot whether I’d posted in the first place.

    • Feldherren says:

      Or is there a way to get the triggering skill’s ID for a reaction condition, without having to specify a reaction and condition for each skill that can trigger it? I want a reaction that occurs for particular elements, but want to check something for each skill (using, say, the Self Data Suite script for skills) – but in this case I need to know the ID of the skill triggering the reaction.

  10. Murd says:

    How could we set condition for reaction that if the actor learns a skill?

    I have tried neither a.learn_skill?(id) nor a.skill?(id) work.

  11. Joey Desud says:

    Hi, I kind of have a bit of a request for an edit… I don’t think it’s very big. But I need to be able to insert code for certain skills to complete ignore reactions. What I mean is, let’s say I have a weapon that reacts with a Lightning spell when the character’s attacked. If that character is healed though, it also reacts… there ends up being strange situations where an enemy has reflect on it, I heal my character, it react-attacks an enemy with lightning, and it kills the character I tried to heal. lol

    I don’t want to have to add every element individually (it would be a pain in the butt)… I just want to be able to insert a code into the script like “return if skill.id == 123”. If you could point me in the right direction on how to do this that would be great 🙂

  12. Alex says:

    Hello.

    Just a small chrismass request about this (awesome) script if you ever have the time/will for it.

    I’d like to be able to hide the reaction message for some (but not all) battle reaction.
    I’m thinking to a tag like .

    It’s just a small thing but may avoid unecessary message for one or two ideas of me.

    For exemple, i made a skill protecting the user agaisnt fire only once.
    In effect it add a state with two reaction the fire skills :
    First a pre reaction adding a state that reduce fire rate to 0
    Second a post reaction removing the two states.

    It works great! But it makes a lot of messages that may bore the player.

    • Hime says:

      I will look into adding a “no-message” tag in your note-tag to specify that the particular reaction will not display a message.

  13. Anonymous says:

    There is something going on with the script. I’ve found that the battle reaction still carries out even after the enemy (or actor) has already been defeated. Is there a way to fix that?

    • Hime says:

      Are you using the latest version?

      • Anonymous says:

        The latest one is from the 13th of May, right? If it is, then yes, I have that.

        • Hime says:

          Do you mean that when an enemy hits an actor, and the actor reacts to it, the reactions occur even if the actor has died? Or that reactions continue to occur even after the original enemy died?

          • Anonymous says:

            When the actor kills an enemy, the enemy still reacts after death. When an enemy kills an actor, the actor still reacts after death. So it’s happening both ways.

          • Hime says:

            Does this occur in a new project?

          • Anonymous says:

            It also happens in a brand new project – I gave a reaction for Slime to use Fire Breath. When Eric kills the slime, it still uses Fire Breath. Likewise, I had set Heal to be a reaction for Eric and set the slime’s attack power to kill him in one hit; he still used Heal after he hit 0 HP.

          • Hime says:

            I set up a slime to use heal in response to Attack, and I noticed that the “Slime reacts to Attack!” is displayed even though it died, but the slime doesn’t actually use it.

            So the display is a bit weird. Are you actually seeing the slime healing itself after it disappears?

          • Anonymous says:

            That happens, too. But the thing is that happens when there aren’t any other targets. If there was a second slime with it, the Heal would have been used on the second slime. I have a few pieces of equipment in my project that have the actor respond with things like Heal or protect spells or something like that, and when that actor dies, he responds with the spell, but it gets targetted onto the next actor, but it doesn’t show when that actor is the last actor left. The animation for attack skills and spells have definetly been showing after the response of the KO’ed ally/enemy.

          • Hime says:

            Create a new project and send it to me. I’m unable to reproduce it but maybe my setup isn’t correct.

          • Anonymous says:

            http://www.mediafire.com/download/r33n6p0ts77k8k6/Project2.zip

            Test battle with the two Slimes and kill the first one. Both slimes are set to react with Heal 100% of the time. The KO’ed Slime’s reacted Heal is targetted onto the other slime.

            Then test battle with the two Bats. They have 999 attack power. Both Eric and Natalie are set to respond with Heal when they’re attacked 100% of the time. Let them kill the whoever they target first and you’ll see that he/she will still respond with Heal, but it gets targetted onto the other actor.

          • Hime says:

            Ok I see what’s gong on. Because you’re using a forced action, the action will always go through regardless whether it is usable or not.

            This is how the default “forced action” works.

          • Anonymous says:

            I see what you were talking about earlier; by removing forced, the reaction still goes off after death, but the animation isn’t shown. Is there a way to prevent the message from displaying after the target dies?

          • Hime says:

            I’ve updated the script as follows: if the battler cannot move, then the reaction does not take place unless the reaction is forced.

            Because forced actions should always go through even if you can’t use it.

  14. Otabo says:

    I don't know if this was already addressed, but here goes. I have been using this script for a while now. Since all of the counter attack scripts out there haven't been working for me, I had to remove all counterattacks from the actors (enemies still keep them, though). I made a system where each actor reacts depending on the weapon that's equipped (basically, each weapon has a skill tied to it, and it is that skill that the actor reacts with when attacked). Anyway, the issue I'm currently facing is non-damaging skills used by the actor onto himself: The actor will react by attacking the enemy (AND sometimes forces a counterattack) when he/she uses a non-damaging skill on him/herself, and I can't figure out why it's doing that. Since they're non-damaging skills, they don't have an element attached to them, but yet the actor reacts to it anyway.

    i.e. One of my actors has a skill where it increases his blocking rate with a shield, and it only affects him. He uses it, and the reaction goes off, so he attacks an enemy as well. That's what it's doing. It only seems to happen with some non-damaging skills; it doesn't happen with things like healing spells or stat buff spells or anything like that.

    I'm also using Yanfly's Core script and Battle Engine, so I'm suspecting that there's something going on with one of those somewhere. Any ideas?

    • Hime says:

      Even if a skill is "non-damaging" they still have an element, and if the element matches the reaction criteria then the reaction will go off.

      Looking at the code, there is no check against who you're using the skill on.

      The way the default target system works is that, for example, if the reaction skill's scope is enemies and you had used a skill on yourself, then whichever enemy corresponds to your actor's index is will be the target of the reaction skill.

      Try changing the element of the skill.

      • Otabo says:

        Try changing the element of the skill that the actor uses on himself? Or the skill that the actor reacts with? I can't change the element of the self-use skill since it doesn't do damage in the first place. My react skills are set to normal attack, so do I need to change it to physical or something?

        • Hime says:

          Ya there's this thing with RM that "normal attack" is the default element even if you don't select any.
          Try selecting a damage type, changing the element, and then change it back to None damage type.

          • Otabo says:

            Worked out perfectly. I was getting quite frustrated, because while I was waiting for your response, I was testing two of my non damaging skills, the skill I mentioned earlier and a reflect skill I have set up. The first skill was causing the reaction, but the second skill wasn't triggering the reaction at all. I was very confused as to why one would trigger the reaction while the other wouldn't when neither of them had elements or anything to them. I'll have to go through the skills/spells of my actors that can trigger reactions and see if they're set correctly so that they don't trigger any reactions.

            It turns out that when I gave it a damage type, the skill was set to normal attack. Thank you so much. This was annoying me for a long time now. Really appreciate this!

  15. Anodos7 says:

    This is a great script. Thank you!

    One thing I noticed is that it seems that the element post-reactions will activate for both actor and enemy targets even if the target is KOed by the user's skill (including when the reaction doesn't have a force tag). That is, although the target has 0 HP and the death state is applied, the action(s) will fully carry out before the death animation and the rest of the death processing. I tried it on a fresh VX Ace project and in the demo you posted and this seems to be the default behavior (though I could be missing something). I'd imagine that for most people this would be a different-than-expected result. While personally it took me only a few seconds for me to tweak the script to adjust this (or else add extra if hp>0 conditions to each reaction), do you think it might be worth updating the script with an option to allow or disallow reactions upon KOs?

    • Hime says:

      So if there were two slimes, and the target died, reactions should no longer occur even if the other slime is still around?
      This becomes a question of "should a character stop attacking once its selected target is dead"

      • Anodos7 says:

        Thank you for your responding. I'm sorry, I didn't explain clearly enough in my last comment.

        What I mean is that let's say that <i>an actor</i> has some battle reactions (just like in your demo). If one of the slimes kills <i>the actor</i>, the actor will have 0 HP, but <i>the dead actor</i> will still carry out his battle reactions first (even though he is supposed to be dead) and then finally die. (I tested this in the demo by raising the slimes' atk stat to 550+). Likewise, if an actor kills an enemy that has a battle reaction, <i>the enemy</i> will still carry out its battle reaction (even though it has 0 HP and is supposed to be dead) before finally dying.

  16. rubydragon44 says:

    I'm confused by this:
    This script introduces the concept of "reaction objects", which is basically
    any object that supports reactions. Actors, Classes, Items, Skills, Weapons,
    Armors, Enemies, and States all support reaction objects.

    You can't tag an item or skill. So when it says it supports items and skills, it just means that actors, classes, weapons, armors, enemies, and states can react to items?
    At first I thought that I could tag a bomb so that there is a chance that being hit by fire will ignite the bomb (which is terrible for test battles unless you remove them at the start, I know) but I could also have it so that a state, Main, is always applied and if $game_party.has_item?($data_items[x]) && rand(100) <= 33
    then the skill Bomb Blow Up is forced

  17. Crazy Rob says:

    It's me again. Now it will only work as a single skill reaction script. Using

    stype reaction: 5 45 100 forced

    with arrows goes nothing, replacing the 5 with the attacking skill's id gets results.

    Did the syntax for skill type reactions change?

    • Hime says:

      The comment box has been updated to support arrows correctly.

      I tested the note-tag you're using by putting on an enemy and when I attack the enemy with a skill of that type, it responded with the appropriate skill.

  18. Crazy Rob says:

    Dear Hime,

    I’m trying to make it so that the condition for the skill to react is that the actor has learned a certain skill, in this case “Fire Wall”, which means being hit by “Enemy”(7) or “Attack”(5) commands results in a retaliatory fire spell.

    This is what I have.

    a.learned_skill?(661)

    As far as whether I typed the formula right for having the learned condition, I’m unsure. What is happening is that putting this in the actor’s class section means that the reaction happens regardless of whether or not the skill is learned.

    Wrong what doing I am?

    Thanks.

    • Crazy Rob says:

      “”
      “”
      “”
      “a.learned_skill?(661)”
      “”

      It didn’t like my first post. Sorry.

      • Crazy Rob says:


        (arrows)stype reaction: 7 662 100 forced(arrows)
        (arrows)stype reaction: 5 662 100 forced(arrows)
        (arrows)reaction condition: 1,2(arrows)
        a.learned_skill?(661)
        (arrows)/reaction condition(arrows)

        I swear I’m not trying to look like an idiot. It comes naturally.

    • Hime says:

      With that set up it should be crashing since that method doesn’t exist.

      a.skill_learn?($data_skills[61])
      

      Make sure you save your game, and that your class is set up correctly.

  19. Joey Desud says:

    Hey Hime, props for the version of the script that doesn’t depend on Forced Actions. I thought this would give compatibility to YEA’s Battle Engine with YSA Classical ATB, but sadly it and it simply freezes up whenever the target tries to react 🙁

    Thanks a lot for trying though. 🙂

  20. aegixdrakan says:

    First of all, I LOVE this script and plan to make it an integral part of my game because it has so many possibilities.

    However I have 2 questions:
    1) Is it possible to make reaction skills call a common event? Because I can’t seem to make that happen.
    I’m trying to make a skill where, when the enemy is hit by physical damage, they will call the “divide” common event, which spawns a new monster.
    The event works when it’s called via a skill normally, but not when the skill is a reaction. Why is that?

    2) Element react only react if the skill is set explicitly to the element you specify. It does not take into account the “same as normal attack” element.

    For example, let’s say I want an enemy to react to physical attacks. However, normal attacks (which have the “same as normal attack” element”) do not cause a reaction despite the character holding a weapon that gives his normal attacks the “physical” element.

    I hope I worded this right and I hope you are able to resolve my issues.
    (goes back to poking through the code to see if I can find some way to do that myself, but it’s unlikely)

    • Hime says:

      By default, events are processed at very specific times of the battle sequence. My script did not have event processing during the reaction processing, so your common events would be called at a later point in time. I am unable to reproduce a situation where the common event is *never* executed.

      The element check is very simple: it only checks the skill that was used, and nothing about the state of the battler that used it. So for example if you had a state that applied fire damage to all attacks regardless what skill you use, the script would never know. It is possible to consider the attacker as well, but I have not thought about how that might be done.

      When I wrote the script, it was designed primarily around the fact that you use a skill, and you can react to a skill. It never really considered who was using the skill or what kind of state they were in when they performed an action. You can use the issue tracker to see if anyone has any input on how it could be implemented.

      • aegixdrakan says:

        On further testing, you are totally right. And it does in fact run common events. it turns out my event logic was totally faulty. I think I will go cry in a corner now, because I fee like a fool. XD

        I’ll look into the issue tracker for the element thing. If I don’t find a solution in there, I’ll just find a workaround somehow in the game engine itself if I want the game to react to enchanted attacks.

        Thank you for your swift response Hime. 🙂

  21. Joey Desud says:

    Hi there. Thanks for the script, have it working great. There’s a compatibility problem though if I put it with “YSA’s Battle System: Classical ATB”. With this I get an error on line 703: NoMethodError occurred. undefined method `shift’ for #. If you’re able to provide a fix or point me in the right direction on how to fix this that would be awesome =)

    • Hime says:

      My script is less than 500 lines I don’t know where that’s coming from.

      Though, I think Yami’s scripts basically require yanfly’s ace battle engine, which has terrible bugs with forced action (it basically doesn’t work). You will need Yanfly’s Ace Core Engine to fix some force action issues, but I don’t know if that solves the problem.

  22. KaizoVorna says:

    Hello, it’s me again with an another possible bug. When I attack an enemy using an item, it gives me a NoLineMethod-error for “stype” even though there isn’t a possibility of making enemies react to items in the script itself. I double checked and it’s not possible to implement Skill Types on items, so might it be that it tries to read the skill type on the item even though items have no skill types and crashes?

    • Hime says:

      That is a reasonable conjecture. I don’t recall checking whether the action used is actually a skill or not.
      It also led to another bug: the enemy actually reacted it to the item when it’s only supposed to react to skill #1.

      The issue has been resolved.

  23. Fusilier says:

    That it does! Thank you very much!

  24. Fusilier says:

    Hi! Loving the script, but when I use it, the “x reacts to y!” message constantly appears even when the actor failed the % roll to actually react. The battle window ends up being spammed with notifications that someone is reacting, and nothing actually happening. Could you possibly think of a clean way to remove this? Or should I just start deleting strings until it works. Any help would be appreciated!

  25. KaizoVorna says:

    I think there might be a bug. I tried to make an enemy that randomly counters attacks 20% of the time, but instead it counters 100% of the time. I just made his reaction “battlereaction: 1 164 20” (With arrows as in the script header.) and assumed it would use skill 164 if attacked with physically, which it does but not only 20% of the time, but ALWAYS. (Even upon death it says that X reacted to Attack even if it doesn’t actually use the attack.) And no, I’m not just unlucky because even when chance is set to 1% it ALWAYS reacts.

    • Hime says:

      Yes, it was a bug. When you write 20, I didn’t actually divide it by 100 to make it 20%, so it was literally being treated as 2000%. Same with the 1: it was 100% instead of 1%.

      I have updated the script to address the issue.

  26. Moo says:

    How might I change framerate mid-game, not just in a testplay script? That, and what’s the game’s default framerate? You had it at 120. I want to make it so when watching other people battle, the framerate is sped up.

  27. Otabo says:

    Found a little issue using the script. I have a fire skill set on one of my actors, and an enemy that counters fire skills with one of its water skills. For the most part it works, but sometimes the enemy uses one of its other skills as the reaction instead of the fire skill. Then, when the enemy’s turn comes up, it does nothing at all. If my actor does nothing at all, the enemy gets its turn as normal. It seems like when the enemy counters, it’s using up its action for its turn. I’ve been trying to figure out what’s wrong for a little while now and haven’t found a solution yet. Hoping I can get some help here.

    • Hime says:

      It was a bug. I used the default “force action” which basically prevented the battler from taking its own turn after performing a reaction.

  28. Hime says:

    Skill type and element type reaction triggers have been implemented.

  29. lita says:

    can you upload this script demo?

  1. May 13, 2014

    […] is an update for Battle Reactions. Originally, all reactions would occur after an action is executed. For example, an enemy attacks […]

Leave a Reply

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