Battle - Shake Screen when playing frames of animation

Good Morning / Day / Afternoon / Evening everyone.

I have a request for a certain kind of snippet

So I would like the following:

1. The ability to make the battle screen shake during selected frames of animation

If this isn't too difficult I would really appreciate the help
Here you go:
Spoiler: Script
Ruby:
=begin
#==============================================================================#
#   AMN Animation Shake
#   Version   1.02
#   Author:   AMoonlessNight
#   Date:     04 Jul 2020
#   Latest:   05 Jul 2020
#==============================================================================#
#   UPDATE LOG
#------------------------------------------------------------------------------#
# 04 Jul 2020 - created the script
# 05 Jul 2020 - fixed bug with frame ID, made compatible with TheoAllen's 
#               Multiple Animations script
#==============================================================================#
#   TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
#   script (do not edit this script directly) and provide proper credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#

This script makes it so that you can set the screen to shake during certain
frames of an animation.

=end
module AMN_Animations
  SHAKE = {}
#==============================================================================
# ** EDITABLE REGION BELOW
#------------------------------------------------------------------------------
#  Change the values in the area below to suit your needs.
#==============================================================================

# SHAKE[ANIMATION_ID] = {
#   FRAME_ID => [POWER, SPEED, DURATION],
# }

  SHAKE[1] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    2 => [4, 4, 10],
  }
  
  SHAKE[68] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    3 => [8, 8, 10],
  }
  
  
#==============================================================================
# ** END OF EDITABLE REGION
#------------------------------------------------------------------------------
#  Please do not edit below this point unless you know what you are doing.
#==============================================================================

end

class RPG::Animation
  include AMN_Animations
  
  def init_animation_shake_timings
    @timings.each { |timing| timing.init_shake_timings }
    if SHAKE.key?(@id)
      SHAKE[@id].each do |frame_id, shake_array|
        timing = RPG::Animation::Timing.new
        timing.shake_power = [[shake_array[0], 9].min, 0].max
        timing.shake_speed = [[shake_array[1], 9].min, 0].max
        timing.shake_duration = shake_array[2]
        timing.frame = frame_id
        @timings << timing
        @timings.sort_by! { |timing| timing.frame }
      end
    end
  end

end

class RPG::Animation::Timing
  attr_accessor :shake_power, :shake_speed, :shake_duration

  def init_shake_timings
    @shake_power = 0
    @shake_speed = 0
    @shake_duration = 0
  end

end

module DataManager
  class << self; alias :amn_anishake_datamgr_loaddb :load_database; end

  def self.load_database
    amn_anishake_datamgr_loaddb
    init_animation_shake_timings
  end
  
  def self.init_animation_shake_timings
    $data_animations.each { |obj| obj.init_animation_shake_timings unless obj.nil? }
  end
  
end

class Sprite_Base < Sprite
  
  def animation_process_shake(timing)
    if timing.shake_power > 0 && timing.shake_speed > 0 && !@ani_duplicated
      screen = $game_party.in_battle ? $game_troop.screen : $game_map.screen
      screen.start_shake(timing.shake_power, timing.shake_speed, timing.shake_duration)
    end
  end
  
  alias amn_anishake_spritebase_aniproctiming animation_process_timing
  def animation_process_timing(timing)
    amn_anishake_spritebase_aniproctiming(timing)
    animation_process_shake(timing) unless $imported && $imported[:Theo_MultiAnime]
  end
  
end

if $imported && $imported[:Theo_MultiAnime]
  class Sprite_MultiAnime < Sprite_Base
    
    alias amn_anishake_spritemultanim_aniproctiming animation_process_timing
    def animation_process_timing(timing)
      animation_process_shake(timing)
      amn_anishake_spritemultanim_aniproctiming(timing)
    end
    
  end
end

EDIT: updated code
animation shake.png


I am NOT properly doing something correctly or maybe I have a script that is making this incompatible

I'm using TheoAllen's multiple animations also, in conjunction with your other Z animation script... maybe there is an incompatibility

Unfortunately it doesn't seem to work, I code the animation id and the frames, but in game, the shake effect ALWAYS only happens when the animation starts... maybe it's one of the scripts i'm using....

EDIT:

Nope, it doesn't seem to work in a new clean project either, no matter which frame I code it in, the shake effect always starts in the first frame for some reason.

Is there anything here I am not doing right?
You have animations that have 118 frames? that's a long animation.
Yeah some abilities I have have some big animations.

Unfortunately this snippet doesn't seem to work in a new clean project either, no matter which frame I code it in, the shake effect always starts in the first frame for some reason.

Is there anything here I am not doing right?
Updated the original. Forgot to add something in about the frame ID, so this version should work now, and should work with Theo's script (although I haven't tested extensively).
After testing it:

YES. So far so good and it works perfectly so far.

I will let you know if I encounter any errors, but amazing job and thank you very much for this!!
ive been trying to use your script but for some reason it dosent seem to work even on a clean project
Here you go:
Spoiler: Script
Ruby:
=begin
#==============================================================================#
#   AMN Animation Shake
#   Version   1.02
#   Author:   AMoonlessNight
#   Date:     04 Jul 2020
#   Latest:   05 Jul 2020
#==============================================================================#
#   UPDATE LOG
#------------------------------------------------------------------------------#
# 04 Jul 2020 - created the script
# 05 Jul 2020 - fixed bug with frame ID, made compatible with TheoAllen's
#               Multiple Animations script
#==============================================================================#
#   TERMS OF USE
#------------------------------------------------------------------------------#
# - Please credit AMoonlessNight or A-Moonless-Night
# - Free for non-commercial use; contact for commercial use
# - If you would like to edit/adjust this script, please make edits as a new
#   script (do not edit this script directly) and provide proper credit
# - I'd love to see your game if you end up using one of my scripts
#==============================================================================#

This script makes it so that you can set the screen to shake during certain
frames of an animation.

=end
module AMN_Animations
  SHAKE = {}
#==============================================================================
# ** EDITABLE REGION BELOW
#------------------------------------------------------------------------------
#  Change the values in the area below to suit your needs.
#==============================================================================

# SHAKE[ANIMATION_ID] = {
#   FRAME_ID => [POWER, SPEED, DURATION],
# }

  SHAKE[1] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    2 => [4, 4, 10],
  }
 
  SHAKE[68] = {
  # FRAME_ID => [POWER, SPEED, DURATION],
    3 => [8, 8, 10],
  }
 
 
#==============================================================================
# ** END OF EDITABLE REGION
#------------------------------------------------------------------------------
#  Please do not edit below this point unless you know what you are doing.
#==============================================================================

end

class RPG::Animation
  include AMN_Animations
 
  def init_animation_shake_timings
    @timings.each { |timing| timing.init_shake_timings }
    if SHAKE.key?(@id)
      SHAKE[@id].each do |frame_id, shake_array|
        timing = RPG::Animation::Timing.new
        timing.shake_power = [[shake_array[0], 9].min, 0].max
        timing.shake_speed = [[shake_array[1], 9].min, 0].max
        timing.shake_duration = shake_array[2]
        timing.frame = frame_id
        @timings << timing
        @timings.sort_by! { |timing| timing.frame }
      end
    end
  end

end

class RPG::Animation::Timing
  attr_accessor :shake_power, :shake_speed, :shake_duration

  def init_shake_timings
    @shake_power = 0
    @shake_speed = 0
    @shake_duration = 0
  end

end

module DataManager
  class << self; alias :amn_anishake_datamgr_loaddb :load_database; end

  def self.load_database
    amn_anishake_datamgr_loaddb
    init_animation_shake_timings
  end
 
  def self.init_animation_shake_timings
    $data_animations.each { |obj| obj.init_animation_shake_timings unless obj.nil? }
  end
 
end

class Sprite_Base < Sprite
 
  def animation_process_shake(timing)
    if timing.shake_power > 0 && timing.shake_speed > 0 && !@ani_duplicated
      screen = $game_party.in_battle ? $game_troop.screen : $game_map.screen
      screen.start_shake(timing.shake_power, timing.shake_speed, timing.shake_duration)
    end
  end
 
  alias amn_anishake_spritebase_aniproctiming animation_process_timing
  def animation_process_timing(timing)
    amn_anishake_spritebase_aniproctiming(timing)
    animation_process_shake(timing) unless $imported && $imported[:Theo_MultiAnime]
  end
 
end

if $imported && $imported[:Theo_MultiAnime]
  class Sprite_MultiAnime < Sprite_Base
   
    alias amn_anishake_spritemultanim_aniproctiming animation_process_timing
    def animation_process_timing(timing)
      animation_process_shake(timing)
      amn_anishake_spritemultanim_aniproctiming(timing)
    end
   
  end
end

EDIT: updated code
@Sanzational Sorry, I just saw this now. Works fine for me in a clean project. How are you setting up your animations?
works fine for me as well! Maybe you are doing something wrong with how you're setting it up?

Original thread: https://forums.rpgmakerweb.com/threads/battle-shake-screen-when-playing-frames-of-animation.122601/