Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Help With User Attack Animations Script

I found this script that displays an enemy's attack animation. But, the problem is, It plays the sound of the animation twice, when it didn't do that before I installed the script. Here's the script, what could be the problem?

Code:
#==============================================================================
# ** User Attack Animations
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.0
#    04-20-2008
#    RGSS2
#============================================================================== 
#
#  INTRODUCTION:
#
#  This system permits you to include 'User Animations' that were not inclu-
#  ded in the RPGMaker VX system,  and allows you t o mimic the lost feature 
#  when using the default battlesystem.
#
#
#------------------------------------------------------------------------------
#
#  USAGE:
#
#  The system is quite simple.  The configuration system has four hash arrays
#  in which to assign animation IDs (from your RMVX database) to the weapons,
#  skills, items and/or enemies in your project.
#
#  You merely need to type in the actual name of the object that triggers the
#  battle animation followed by the ID of the battle animation you want using
#  the proper syntax.
#
#  ARRAY = { "object name" => ID, "object name" => ID,.....  }
#
#                             *   *   *   *   *
#
#  As far as the 'ENEMY' hash arrays, you must assign two(2) animation IDs in
#  their own little array.  This is to allow enemies to perform a user anima-
#  tion and an optional attack animation.  The syntax is slightly different.
#
#  ENEMY_ANIM_IDS = { "enemy" => [ID1, ID2], "enemy" => [ID1, ID2], ... }
#
#  The first ID within the brackets specifies the 'user' animation that is 
#  shown over the enemy.  The second ID is that of the attack animation.
#
#  Also, you can use a value of '0' for either ID1 and/or ID2 if you decide
#  to not show a battle animation.  As an example:
#
#                           "Slime"      => [4, 0]
#
#  This would assign a 'USER' battle animation to the Slime, but use the de-
#  fault attack/hit system rather than a battle animation on its targets.
#
#
#------------------------------------------------------------------------------
#
#  NOTE: 
#
#  This system can work  with or without the  'Actor Battler Graphics'  system
#  without any problems.   Without said script,  it applies user animations to 
#  enemy battlers only.   But with said script,  all battlers (actor or enemy)
#  will be able to use 'user' animations.
#
#
#------------------------------------------------------------------------------
#
#  EDITS AND MODIFICATIONS:
#  
#  This system Aliases the following methods:
#  * initialize                     (Game_Battler)
#  * execute_action_attack          (Scene_Battle)
#  * execute_action_skill           (Scene_Battle)
#  * execute_action_item            (Scene_Battle)
#
#  This system redefines the following methods:
#  * display_attack_animation       (Scene_Battle)
#
#  This system adds the following methods:
#  * display_user_animation         (Scene_Battle)
#  
#
#------------------------------------------------------------------------------
#
#  TERMS AND CONDITIONS:
#
#  Free to use, even in commercial projects.  Just note that I need some form
#  of due credit... even a mere mention in some end titles.
#
#==============================================================================



#==============================================================================
#==============================================================================
#                                                                             #
#   ****  C  O  N  F  I  G  U  R  A  T  I  O  N      S  Y  S  T  E  M  ****   #
#                                                                             #
#==============================================================================
#==============================================================================

    #==========================================================================
    #   ****               WEAPON ANIMATION HASH ARRAYS                ****   #
    #==========================================================================

    WEAPS_ANIM_IDS    = {"Long Sword" => 1,
                         "Club"       => 3}    

                         
    #==========================================================================
    #   ****               SKILL ANIMATION HASH ARRAYS                 ****   #
    #==========================================================================

    SKILL_ANIM_IDS    = {"Data Drain" => 84,
                         "Ban" => 83,
                         "Dribble" => 69}    

                         
    #==========================================================================
    #   ****                ITEM ANIMATION HASH ARRAYS                 ****   #
    #==========================================================================
                         
    ITEM_ANIM_IDS     = {}               

    
    #==========================================================================
    #   ****               ENEMY ANIMATION HASH ARRAYS                 ****   #
    #==========================================================================

    ENEMY_ANIM_IDS    = {"Aki-san" => [0, 84],
                         "Aki-san" => [0, 83],
                         "Cup Of Water" => [0,69]}
    
    
   #========================================================================
   #  **  E  N  D     O  F     C  O  N  F  I  G  U  R  A  T  I  O  N   **  #
   #========================================================================      
    
   
    
#==============================================================================
# ** Game_Battler 
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================
class Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :animation_user           # For User Attack Animations
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias uaa_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Perform the original call
    uaa_init
    @animation_user   = nil
  end
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias uaa_execute_action_attack execute_action_attack
  alias uaa_execute_action_skill execute_action_skill
  alias uaa_execute_action_item execute_action_item
  #--------------------------------------------------------------------------
  # * Execute Battle Action: Attack
  #--------------------------------------------------------------------------
  def execute_action_attack
    temp_array  = []
    anim_id     = 0
    if @active_battler.is_a?(Game_Enemy)
      # Retrieve the animation id of the enemy
      temp_id = @active_battler.original_name
      temp_array = ENEMY_ANIM_IDS[temp_id] if ENEMY_ANIM_IDS.include?(temp_id)
      anim_id = temp_array[0]
    else
      # Retrieve the animation id of the weapon (unless '0')
      weap_id = $game_actors[@active_battler.id].weapon_id
      if weap_id != 0
        temp_id = $data_weapons[weap_id].name
        anim_id = WEAPS_ANIM_IDS[temp_id] if WEAPS_ANIM_IDS.include?(temp_id)      
      end
    end
    # Perform for valid animation    
    unless anim_id == nil
      unless anim_id < 1
        display_user_animation(@active_battler, anim_id)
        wait_for_animation
      end
    end    
    # Perform the original call
    uaa_execute_action_attack
  end
  #--------------------------------------------------------------------------
  # * Execute Battle Action: Skill
  #--------------------------------------------------------------------------
  def execute_action_skill
    anim_id = 0
    skill   = @active_battler.action.skill
    anim_id = SKILL_ANIM_IDS[skill.name] if SKILL_ANIM_IDS.include?(skill.name)
    # Perform for valid animation
    unless anim_id  < 1
      display_user_animation(@active_battler, anim_id)
      wait_for_animation
    end
    # Perform the original call
    uaa_execute_action_skill
  end 
  #--------------------------------------------------------------------------
  # * Execute Battle Action: Item
  #--------------------------------------------------------------------------
  def execute_action_item
    anim_id = 0
    item    = @active_battler.action.item
    anim_id = ITEM_ANIM_IDS[item.name] if ITEM_ANIM_IDS.include?(item.name)
    # Perform for valid animation    
    unless anim_id  < 1
      display_user_animation(@active_battler, anim_id)
      wait_for_animation
    end    
    # Perform the original call
    uaa_execute_action_item
  end
  #--------------------------------------------------------------------------
  # * Show Attack Animation
  #     targets : Target array
  #    If enemy, play the [Enemy normal attack] sound effect and wait 
  #    a moment. If actor, take dual wielding into account (display left hand
  #    weapon reversed)
  #--------------------------------------------------------------------------
  def display_attack_animation(targets)
    temp_array = []
    if @active_battler.is_a?(Game_Enemy)
      temp_id = @active_battler.original_name
      if ENEMY_ANIM_IDS.include?(temp_id)
        temp_array = ENEMY_ANIM_IDS[temp_id]
        temp_id = temp_array[1]
        display_normal_animation(targets, temp_id, false)
      else
        Sound.play_enemy_attack
        wait(15, true)        
      end
    else
      aid1 = @active_battler.atk_animation_id
      aid2 = @active_battler.atk_animation_id2
      display_normal_animation(targets, aid1, false)
      display_normal_animation(targets, aid2, true)
    end
    wait_for_animation
  end
  #--------------------------------------------------------------------------
  # * Show User Animation
  #     User         : User
  #     animation_id : Animation ID
  #     mirror       : Flip horizontal
  #--------------------------------------------------------------------------
  def display_user_animation(user, animation_id, mirror = false)
    animation = $data_animations[animation_id]
    if animation != nil
      user.animation_id = animation_id
      user.animation_mirror = mirror
      wait(40, true)
    end
    user.animation_user = nil
  end
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top