(XP) Critical Cut-In/Animation Script

Hello there! I've been searching tirelessly for a script that does this, but haven't been able to find one for RPG Maker XP. Any help would be greatly appreciated.

What I'm looking for is a way to recreate that "critical cut-in" system from Fire Emblem: Awakening. If you're unfamiliar with the system, essentially, whenever a critical hit is landed or a skill is activated in that game, the character's face will appear on-screen briefly and they will say a quote exclusive to that character. All examples of this can be found in this video.

All I'm looking for is the ability to have each character speak a quote (preferably with their sprite appearing on-screen) when they land a critical hit, either before or after the hit occurs. I feel like it'd be easiest to simply have the engine play a second battle animation whenever a critical hit occurs. If someone could help me accomplish that, and help me make it vary by character, I could handle making the animations and take it from there. I've got absolutely no knowledge when it comes to scripting, unfortunately, but if anyone can lend me a hand with this, you'll find your username in the special thanks section of my game 🙂

Thank you in advance, and thank you for reading.

~ Molly Avast
This should do the trick for you. It's pretty short, so I didn't test it out significantly. If you experience bugs, let me know.
Spoiler
Code:
#===============================================================================
# Mobius' Critical Animations
# Author: Mobius XVI
# Version: 1.0
# Date: 3 JAN 2019
#===============================================================================
#
# Introduction:
#
#   This script allows you to add custom animations that trigger on critical hits.
#
# Instructions:
#
#  - Place this script below all the default scripts but above main.
#
#  - The customization section below has additional instructions on 
#    how to set up.
#
# Issues/Bugs/Possible Bugs:
#
#   - None
#
#  Credits/Thanks:
#    - Mobius XVI, author
#    - MollyAvast, for requesting it
#
#  License
#   
#    This script is available in its entirety for commercial and non-commercial
#    use. View the specific license terms below.   
#
#    The portions of this script written by me is licensed under the MIT License:
#
#    The MIT License (MIT)
#
#      Copyright (c) 2018 darmes
#
#       Permission is hereby granted, free of charge, to any person obtaining a copy
#       of this software and associated documentation files (the "Software"), to deal
#       in the Software without restriction, including without limitation the rights
#       to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#       copies of the Software, and to permit persons to whom the Software is
#       furnished to do so, subject to the following conditions:
#
#       The above copyright notice and this permission notice shall be included in all
#       copies or substantial portions of the Software.
#
#       THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#       IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#       FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#       AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#       LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#       OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#       SOFTWARE.
#   
#      Further, if you do decide to use this script in a commercial product, 
#      I'd ask that you let me know via a forum post or a PM. Thanks.
#
#==============================================================================
# ** CUSTOMIZATION START
#==============================================================================
module Mobius
    module Critical_Animations
        # ACTOR ANIMATION IDs #
        ACTOR_ANIMATION_IDS = {
        # Actor 1 => [ Possible animation IDs in the database],
        1 => [98,99,100],
        # Actor # => [ID1,ID2,ID3],
        2 => [100],
        # Start with actor_id then make this symbol '=>' then put an opening
        # square bracket '[' then all the IDs for animations that you want
        # separate IDs with commas ','. Finish with a closing square bracket ']'
        # Lastly, place another comma after the square bracket.
        }
        ACTOR_ANIMATION_IDS.default = 0
    end
end
#==============================================================================
# ** CUSTOMIZATION END
#------------------------------------------------------------------------------
# ** EDIT BELOW THIS LINE AT OWN RISK!!!
#==============================================================================   
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle

    # Create Alias
    alias mobius_update_phase4_step4 update_phase4_step4
   
    #--------------------------------------------------------------------------
    # * Frame Update (main phase step 4 : animation for target)
    #--------------------------------------------------------------------------
    def update_phase4_step4
        # init critical flag to false
        crit_flag = false
        # check all possible targets for critical hits
        for target in @target_battlers
            # if critical hit occurred
            if target.critical
                # set flag and exit loop early
                crit_flag = true
                break
            end
        end
        # if critical hit occurred
        if crit_flag
            # Set animation id
            animation_id_array = Mobius::Critical_Animations::ACTOR_ANIMATION_IDS[@active_battler.id]
            @active_battler.animation_id = animation_id_array[rand(animation_id_array.size)]
            @active_battler.animation_hit = true
        end
        # call original method
        mobius_update_phase4_step4
    end

end
Thank you very much...! This is really helpful! I believe I can absolutely make this work, and testing it has turned out well.

My only question is this: is there a way to prevent enemies from scoring critical hits? It seems like this would be easy to do, so I feel I may be overlooking something. But when enemies score criticals, it seems to cause issues with the script. (And, to be honest, I'd rather enemies be unable to perform critical hits anyways.)

Thank you in advance, and thank you again for the amazing script! <3
Yea, my bad. Change line 107 from this:
Code:
if crit_flag
to this:
Code:
if crit_flag and @active_battler.is_a?(Game_Actor)

That should make it so enemies don't trigger the extra animations.
Thank you very much, that worked! This is besides the point of the original post, but I don't suppose you'd know how to disable critical hits entirely for enemies? (Not just the animation.)

If not, that's completely fine, I just figured I would ask. I greatly appreciate the work you have done for me already, and will certainly credit you when my game releases (very soon, actually!)
Disabling critical hits for enemies depends on what battle system you're using as well as add-ons. If you're using the default system (and only the default system), I could write something for you right now. Otherwise, I'd need to know what you have to ensure compatibility.
I'm using the default battle system! I don't believe any of the scripts I'm using would conflict with it, the only two scripts I have that really change up the battle system at all are the Critical Animation script that you wrote for me, and PK8's damage font control script.

If you could write up a script for me, words cannot describe how much I would appreciate it! You're making life so much easier for me.
Cool. Here you go then.
Spoiler
Code:
class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : battler
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = [attacker.atk - self.pdef / 2, 0].max
      self.damage = atk * attacker.str / 10
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if (rand(100) < 4 * attacker.dex / self.agi) and self.is_a?(Game_Actor)
          self.damage *= 2
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end

end
Mobius, I don't know how to thank you enough! You're a lifesaver.
No problem. Just PM me a link when you finish your game.

Original thread: https://forums.rpgmakerweb.com/threads/xp-critical-cut-in-animation-script.103909/