Script bug - FenixFyreX MultiFrame sprites

Have to paste the original script here as the original page/files are lost.

This script doesn't seem to work with large (8 character) sheets, specifically because of "frame_max". Idk how to fix this.

When writing in the module for a solo ($) sprite, making frame_max the amount of total frames horizontally will work.

Example: The game actor's sprite is part of an 8-character sheet, and has a max_frame count of 5. If you put max_frames to 5, it won't divide character frames properly. If you put it any higher or lower, it'll show this error after walking for a bit:
1581315787179.png


The module set below has a test suffix for 5-framed characters if you want to try out the script.

Code:
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# MultiFrame Sprites - Ace v1.0
# FenixFyreX
# RPG Maker VxAce
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #
# This script allows you to setup a symbol, which returns a
# pattern array, idle_frame index, and frame max. These will be applied to all
# sprites with said symbol in their image name.
#
# The % sprite example belongs to Despain, as he made the sprite. Credit for it
# or feel his wrath.
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #

module FyxA
  module CustomSprites
    Patterns = {

    # Key => [ pattern_array, idle_frame, frame_max, speeds ],
    #
    #   pattern_array - the order in which each frame is shown
    #   idle_frame    - the frame the sprite sits on when still
    #   frame_max     - the amount of frames overall in the image
    #   speeds        - how fast the sprite cycles through frames running/walking
    # If speeds is not present, the default 1.5,1 will be used.

    #  RMXP shows frame 0, then 1, then 2, then 3. When the sprite is idle, it
    #  shows frame 2. There are 4 frames total in an rmxp sprite. We also want
    #  to display these frames a bit faster, so speeds are set to [2.5, 2]
      "_test" => [[0,1,2,3,4], 0, 5, [1.5,1]], ##5 frame max
    }
  end
end

class Game_CharacterBase
  attr_reader :pattern_index

  alias initialize_pat_ind_fyx_mfs initialize unless $@
  def initialize(*a,&bl)
    @pattern_index = 0
    initialize_pat_ind_fyx_mfs(*a,&bl)
    @original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
  end

  alias update_anim_speeds_fyx_mfs update_anime_count
  def update_anime_count(*a,&bl)
    if mfs_sprite?
      s1,s2 = *mfs_sprite?(true)[-1]
      if moving? && @walk_anime
        if (moving? || stopping?)
          @anime_count += s2
        else
          @anime_count = 0
        end
      elsif @step_anime || @pattern != @original_pattern
        @anime_count += s1
      end
    else
      update_anim_speeds_fyx_mfs(*a,&bl)
    end
  end

  alias update_anim_pat_fyx_mfs update_anime_pattern
  def update_anime_pattern(*a,&bl)
    if mfs_sprite?
      key,pattern_array,@original_pattern,fm = *mfs_sprite?(true)
      max_frames = pattern_array.include?(@original_pattern) ? fm : fm-1
      if !@step_anime && @stop_count > 0
        @pattern_index = -1
        @pattern = @original_pattern
      else
        @pattern_index = (@pattern_index + 1) % max_frames
        @pattern = pattern_array[@pattern_index]
        if (@pattern == @original_pattern) && (!pattern_array.include?(@original_pattern))
          @pattern_index = (@pattern_index + 1) % max_frames
          @pattern = pattern_array[@pattern_index]
        end
      end
    else
      update_anim_pat_fyx_mfs(*a,&bl)
    end
  end

  def mfs_sprite?(ret=false)
    FyxA::CustomSprites::Patterns.each_pair do |key,a|
      pa,op,fm,sa = *a
      if @character_name.include?(key)
        sp = sa.nil? ? [1,1.5] : sa
        return ret ? [key,pa,op,fm,sp] : true
      end
    end
    return ret ? [nil,[1,2,0],1,3,[1,1.5]] : false
  end
end

class Game_Player < Game_Character

  alias initialize_plyr_ind_mfs initialize unless $@
  def initialize(*a,&bl)
    initialize_plyr_ind_mfs(*a,&bl)
    @original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
  end

  alias refresh_mfs refresh
  def refresh(*a,&bl)
    refresh_mfs
    @original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
    @pattern = @original_pattern
  end
end

class Game_Event < Game_Character

  alias initialize_evnt_ind_mfs initialize unless $@
  def initialize(*a,&bl)
    initialize_evnt_ind_mfs(*a,&bl)
    @original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
  end

  alias refresh_mfs refresh
  def refresh(*a,&bl)
    refresh_mfs
    @original_pattern = mfs_sprite? ? mfs_sprite?(true)[2] : 1
    @pattern = @original_pattern
  end
end

class Sprite_Character < Sprite_Base

  alias initialize_player_refresh initialize
  def initialize(*a,&bl)
    a[-1].refresh if a[-1].is_a?(Game_Player)
    initialize_player_refresh(*a,&bl)
  end

  alias set_char_bmp_mfs set_character_bitmap
  def set_character_bitmap(*a,&bl)
    if [email protected]_sprite?
      set_char_bmp_mfs(*a,&bl)
    else
      key,pattern_array,op,fm = *@character.mfs_sprite?(true)
      self.bitmap = Cache.character(@character_name)
      sign = @character_name[/^[\!\$]./]
      if sign && sign.include?('$')
        @cw = bitmap.width / fm
        @ch = bitmap.height / 4
      else
        @cw = bitmap.width / fm * 4
        @ch = bitmap.height / 8
      end
      self.ox = @cw / 2
      self.oy = @ch
    end
  end

  alias update_src_r_mfs update_src_rect
  def update_src_rect(*a,&bl)
    if @character.mfs_sprite?
      key,pa,op,fm = *@character.mfs_sprite?(true)
      max_frames = pa.include?(op) ? fm : fm-1
      if @tile_id == 0
        index = @character.character_index
        pattern = @character.pattern_index < max_frames ? @character.pattern : op
        sx = (index % 4 * 3 + pattern) * @cw
        sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
        self.src_rect.set(sx, sy, @cw, @ch)
      end
    else
      update_src_r_mfs(*a,&bl)
    end
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/script-bug-fenixfyrex-multiframe-sprites.118091/