Display Animation Behind Battler Graphic

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Good Morning / Day / Afternoon / Evening everyone.

I am looking for a script that displays animations BEHIND the battler graphic rather than on the default. Make it so I can choose which animations will be displayed behind or on front.

Any help would be appreciated.
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
649
Reaction score
424
First Language
English
Primarily Uses
RMVXA
This sounded like an interesting challenge, so I made something:
Ruby:
=begin
#==============================================================================#
#   AMN Animation Z Values
#   Version   1.01
#   Author:   AMoonlessNight
#   Date:     03 Jul 2020
#   Latest:   03 Jul 2020
#==============================================================================#
#   UPDATE LOG
#------------------------------------------------------------------------------#
# 03 Jul 2020 - created the 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 change the Z value for animations. You can
change the value of whole frames, whole animations or just specific cells. This
means you can make it so that certain animations play below the target sprite.

=end

module AMN_Animations
  ANIMATIONS = {}
=begin
    
  Set up each animation below here. Follow the example:
  
  ANIMATIONS[ID] = {
    :cells => {         # To set individual cells in each frame:
      FRAME_ID => {
        Z_VALUE => [cell_id, cell_id, ...],
      },
    :frames => {        # To set whole frames:
      Z_VALUE => [frame_id, frame_id, ...],
    },
  } # closing bracket doesn't need comma
  
  ID is the ID of the animation in the Database. You can find this by going into
  the Animations tab in the Database and looking at the number next to the
  animation in the animations list (left-most list).
  
  FRAME_ID is the ID number of the frame. You can find this by going into the
  Animations tab in the Database, finding the animation in the animations list
  and selecting it. It's the list that has 'Frame List' in the help window when
  you hover your cursor over it.
  
  CELL_ID is the ID number of the cell. Each frame can have 16 cells. The cell
  is the image in the animation: in the animation editor, it will have a box
  around it with a number in the top-left corner---this is the CELL_ID.
  
  Z_VALUE can be integer, a string that eval to an integer (for Ruby scripters)
  or one of these symbols:
    :below = below sprite
    
  For the string, you can use the following shortcuts:
    b = the sprite (battler/character)
    v = variable
    s = switch
    i = frame index
    p = $game_party
    t = $game_troop

    
  The frames/cells that you leave out of the hash will play above the sprite
  as per the default.
  
=end

#==============================================================================
# ** EDITABLE REGION BELOW
#------------------------------------------------------------------------------
#  Change the values in the area below to suit your needs.
#==============================================================================

  # ANIMATIONS[ANIMATION_ID] = {
  ANIMATIONS[112] = {
  # To set individual cells in each frame:
    :cells => {
        # FRAME_ID => {
        4 => {
          # Z_VALUE => [ARRAY OF CELL IDS],
          :below => [1], # cell IDs that should be Z
        },
    },
  # To set whole frames:
    :frames => {
      # Z_VALUE => [ARRAY OF FRAMES],
      :below => (0..9).to_a + [13,14], # whole frames that should be Z
    },
  }
    
  ANIMATIONS[1] = {
  # To set the whole animation:
  # :all => Z_VALUE
    :all => "b.z - 10", # z value (in this case, the sprite's z value minus 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
  attr_reader :z_hash
  
  def init_animation_z_hash
    @z_hash = ANIMATIONS.key?(@id) ? ANIMATIONS[@id] : {}
    @z_hash[:frames] = {} unless @z_hash.key?(:frames)
    @z_hash[:cells] = {} unless @z_hash.key?(:cells)
  end

  def z_hash_all?
    return false unless @z_hash.key?(:all)
  end

end

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

  def self.load_database
    amn_anime_datamgr_loaddb
    init_animation_z_hash
  end
  
  def self.init_animation_z_hash
    $data_animations.each { |obj| obj.init_animation_z_hash unless obj.nil? }
  end
  
end

class Sprite_Base < Sprite
  include AMN_Animations

  def get_z_value(obj, index)
    default = self.z + 300 + index
    begin
      value = case obj
      when String then eval_z_value(obj, self, index) rescue default
      when Integer then obj
      when Symbol then obj == :below ? self.z - 1 : default
      else default
      end
    end
    value.is_a?(Integer) ? value : default
  end
  
  def eval_z_value(string, b, i, p=$game_party, t=$game_troop, v=$game_variables, s=$game_switches)
    eval(string)
  end
  
  def set_index_z_value(frame_index, sprite, index)
    return unless @animation.z_hash[:cells].key?(frame_index)
    pair = @animation.z_hash[:cells][frame_index].find {|k,v| v.include?(index) }
    return unless pair
    sprite.z = get_z_value(pair[0], index)
  end
  
  def set_frame_z_value(frame_index, sprite, index)
    pair = @animation.z_hash[:frames].find {|k,v| v.include?(frame_index) }
    return unless pair
    sprite.z = get_z_value(pair[0], index)
  end
  
  def set_z_value(frame, sprite, index)
    cell_data = frame.cell_data
    pattern = cell_data[index, 0]
    return if !pattern || pattern < 0
    frame_index = @animation.frame_max
    frame_index -= (@ani_duration + @ani_rate - 1) / @ani_rate
    set_frame_z_value(frame_index, sprite, index)
    set_index_z_value(frame_index, sprite, index)
    if @animation.z_hash.key?(:all)
      sprite.z = get_z_value(@animation.z_hash[:all], index)
    end
  end
  
  alias amn_anime_spritebase_animesetsprites  animation_set_sprites
  def animation_set_sprites(frame)
    amn_anime_spritebase_animesetsprites(frame)
    @ani_sprites.each_with_index do |sprite, i|
      next unless sprite
      set_z_value(frame, sprite, i)
    end
  end
  
end

There might already be a script out there that does something like this (sounds like something TheoAllen would've made, but I couldn't find anything), but this is what I've come up with. Let me know how you go.
 

Panda_Artist

Humble RPG Fan
Veteran
Joined
Dec 22, 2018
Messages
192
Reaction score
12
First Language
Portuguese
Primarily Uses
RMVXA
Wow, this is very interesting... However I seem to be having trouble setting it up...
03.07.2020_09.10.09_REC.png

Maybe there is something I am doing wrong.... the first one works just fine, but when I add the new one I get so many errors...

0aaaa.png

maybe i'm not doing it correctly

EDIT: I figured it out!! Silly me I shouldn't place a comma there!!

This script is amazing and gives me alot of more freedom to create my animations, amazing job and you'll definitely be credited for this!!
 

A-Moonless-Night

WINTER IS COMING
Veteran
Joined
Mar 17, 2012
Messages
649
Reaction score
424
First Language
English
Primarily Uses
RMVXA
Cool, glad you've got it working. Looks like you might have an extra curly brace there as well. Let me know if you have any issues.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

One 3-day jam and a Game Awards... this month is moving... \o/
Maker-ing has been being the best thing that happened to me this year so far. it is so good to rescue some old skills fo creativity and the people I have met are really incredible. I love my coffelanders and tocudos buddies. Maybe one day I will reach other countries folks too. S2
Well... My game plays better at 1920x1080, so I guess that's the new resolution. Still runs at 60FPS. :LZSexcite: Also... I really want a boss to be able to build new maps around the player... Mostly because it's visually spectacular! I'm er... not quite sure yet how I can do that without making MV explode.... But I'll find a way, anything in service to the "sparkles"! :kaopride:
How to change your netbooks screen resolution

Forum statistics

Threads
100,794
Messages
979,597
Members
132,437
Latest member
Vollar45
Top