=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