Galv’s Character Animations V.1.7

This is the old version – Uses Separate Charsets for dash/walk/idle.
The new version – can be found Here (Uses one charset for all poses).

#------------------------------------------------------------------------------#
#  Galv's Character Animations
#------------------------------------------------------------------------------#
#  For: RPGMAKER VX ACE
#  Version 1.7
#------------------------------------------------------------------------------#
#  2013-01-07 - Version 1.7 - Slight tweaks
#  2012-10-06 - Version 1.6 - Updated alias names for compatibility
#  2012-10-06 - Version 1.5 - Added dash speed option. Fixed some code
#  2012-09-21 - Version 1.4 - Optimised the code significantly (to my ability)
#                           - Some bug fixes
#  2012-09-21 - Version 1.3 - Added ability to repeat common event
#                           - Added follower animations
#  2012-09-20 - Version 1.2 - fixed compatibility with Galv's Region Effects
#  2012-09-20 - Version 1.1 - added idle common event, removed unnecessary code
#  2012-09-20 - Version 1.0 - release
#------------------------------------------------------------------------------#
#  Designed to give actors additional animations such as:
#  - Idle
#  - Walking
#  - Dashing
#  - Custom (run a common event if you've been idle for a period of time)
#
#  INSTRUCTIONS:
#  1. Copy this script below materials and above main
#  2. Create your charset files with extensions (see setup options)
#   by default these are:
#        - "Actor1.png" for idle
#        - "Actor1_walk.png" for walking
#        - "Actor1_dash.png" for dashing
#  Make sure the actor's sprites are in the same position in each charset.
#  (you can have 8 actors in each spritesheet)
#
#------------------------------------------------------------------------------#
#
#  KNOWN ISSUES:
#  - Move Route Change graphic commands only work when the switch is on.
#    Then if you turn it off again, the graphic changes back to the original.
#    Use "Set Actor Graphic" event command to change instead.
#
#------------------------------------------------------------------------------#  
#  !!!!! WARNING - I am a learning scripter. Use this at your own risk!!!!!!
#------------------------------------------------------------------------------#

($imported ||= {})["Chara_Anims"] = true
module Chara_Anims
  
#------------------------------------------------------------------------------#  
#  SETUP OPTIONS
#------------------------------------------------------------------------------#

  WALK_EXTENSION = "_walk"    # appends to end of file names to determine
                              # the walking charsets.

  DASH_EXTENSION = "_dash"    # appends to end of dashing charset filename
                              # Make it the same as walk extension to disable
  DASH_SPEED = 1.2            # 1 is RMVX default dash speed.
  

  PAUSE = 5                   # frames before idle animation starts
                              # (60 frames per second). I was planning something
                              # with this but you shouldn't change it for now.

  ANIM_SWITCH = 1             # ID of a switch to disable this effect.
                              # Turn switch ON in order to use change graphic
                              # move route commands. Turn off to restore anims.
  
  STEP_ANIMATION = true       # If "Stepping" is on or off by default.
                              # Can be true or false.

  COMMON_EVENT = 1            # Common event ID that plays after a certain time
  COMMON_EVENT_TIME = 200     # Frames idle before common event called.
  REPEAT_EVENT = false        # Repeat this common event if player remains idle?
                              # (restarts the common event time) true or false.
#------------------------------------------------------------------------------#  
#  END SETUP OPTIONS
#------------------------------------------------------------------------------#

                                  
end # Chara_Anims


class Sprite_Character < Sprite_Base
  alias galv_charanim_initialize initialize
  def initialize(viewport, character = nil)
    @idletime = 0
    galv_charanim_initialize(viewport, character)
  end

  alias galv_charanim_update update
  def update
    galv_charanim_update 
    return if $game_switches[Chara_Anims::ANIM_SWITCH]
    return move_anim if $game_player.moving?
    @idletime += 1
    idle_anim if @idletime == Chara_Anims::PAUSE
    idle_event if @idletime == Chara_Anims::COMMON_EVENT_TIME
  end

  def idle_anim
    $game_player.step_anime = Chara_Anims::STEP_ANIMATION
    $game_party.battle_members.each { |m|
      default = m.character_name.chomp(Chara_Anims::DASH_EXTENSION)
      m.set_g(default.chomp(Chara_Anims::WALK_EXTENSION))
    }
    $game_player.refresh
    @idletime += 1
  end

  def move_anim
    $game_party.battle_members.each { |m|
      if $game_player.dash?
        if !m.character_name.include?(Chara_Anims::DASH_EXTENSION)
          m.set_g(m.character_name.chomp(Chara_Anims::WALK_EXTENSION) + Chara_Anims::DASH_EXTENSION)
        end
      else
        if !m.character_name.include?(Chara_Anims::WALK_EXTENSION)
          m.set_g(m.character_name.chomp(Chara_Anims::DASH_EXTENSION) + Chara_Anims::WALK_EXTENSION)
        end
      end
    }
    $game_player.refresh
    @idletime = 0
  end

  def idle_event
    $game_temp.reserve_common_event(Chara_Anims::COMMON_EVENT)
    @idletime = 0 if Chara_Anims::REPEAT_EVENT
  end
end # Sprite_Character < Sprite_Base


class Game_CharacterBase
  alias galv_charanim_init_public_members init_public_members
  def init_public_members
    galv_charanim_init_public_members
    @step_anime = Chara_Anims::STEP_ANIMATION
  end
  
  alias galv_charanim_real_move_speed real_move_speed
  def real_move_speed
    galv_charanim_real_move_speed
    @move_speed + (dash? ? Chara_Anims::DASH_SPEED : 0)
  end
end # Game_CharacterBase


class Game_Actor < Game_Battler
  def set_g(character_name)
    @character_name = character_name
  end
end # Game_Actor < Game_Battler


class Game_Player < Game_Character
  attr_accessor :step_anime
end # class Game_Player < Game_Character

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s