VXAce [SOLVED] Error message by Visual Equipment script

Hello!
I am using the Visual Equipment script by BRANDT/Masked
when i interact with an event to use this script, this error pops up
at the lines around 167-168

1.png


When i use this script in a empty new project, everything works just fine..

Here's the script
Spoiler: Script
Ruby:
#==============================================================================
# ** MS - Visual Equipment
#------------------------------------------------------------------------------
# por Masked
#==============================================================================
#==============================================================================
# Instruções:
#------------------------------------------------------------------------------
# Para definir um gráfico para o equipamento, escreva nas notas dele:
# <Graphic = Nome_do_arquivo>
# O arquivo "Nome_do_arquivo" deve estar na pasta Graphics/Characters do seu
# projeto
#
# Para definir mais de um frame, para o caso de um script de extra frame,
# escreva isso nas notas do equipamento:
# <Frames = x>
# Sendo o 'x' o número de frames
#
# Para definir a prioridade (eixo Z) do equipamento:
# <Z = x>
# Sendo o 'x' a prioridade do equipamento
#
# Para definir os gráficos para um evento, é preciso criar um comentário nele
# com o seguinte conteúdo:
# <Equips: x,y,z>
# Sendo x, y e z os IDs dos equipamentos, se x for A1, a armadura de id 1 será
# atribuída ao evento, se y for W3, a arma de id 3 será atribuída a ele,
# você pode colocar quantos IDs quiser na lista
#==============================================================================
($imported ||= {})[:ms_visual_equip] = true
module MBS
  module VisualEquip
#==============================================================================
# Configurações
#==============================================================================
    # Ajuste horizontal da posição do equipamento
    POSITION_ADJUST_X = -16
 
    # Ajuste vertical da posição do equipamento
    POSITION_ADJUST_Y = 0
 
    # Switch que ativa/desativa o visual equip
    SWITCH = 25
 
    # Largura do sprite do equipamento
    BITMAP_WIDTH = 96
 
    # Altura do sprite do equipamento
    BITMAP_HEIGHT = 128
#==============================================================================
# Fim das configurações
#==============================================================================
  end
end
#==============================================================================
# ** Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
  alias ms_initlz initialize
  alias ms_updt update
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #     viewport  : camada
  #     character : personagem (Game_Character)
  #--------------------------------------------------------------------------
  def initialize(viewport, character = nil)
    create_equip_sprite(viewport)
    ms_initlz(viewport,character)
  end
 
  #--------------------------------------------------------------------------
  # * Criação do sprite do equipamento
  #--------------------------------------------------------------------------
  def create_equip_sprite(viewport)
    @equipments = []
    @equip_sprite = Sprite.new(viewport)
    @equip_sprite.bitmap = Bitmap.new(MBS::VisualEquip::BITMAP_WIDTH,MBS::VisualEquip::BITMAP_HEIGHT)
    @equip_sprite.oy = 4
  end
 
  #--------------------------------------------------------------------------
  # Verificação de alteração no equipamento
  #--------------------------------------------------------------------------
  def equip_changed?
    if @character.is_a?(Game_Player) || @character.is_a?(Game_Follower)
      if @character.is_a?(Game_Player)
        return @old != $game_party.members[0].equips
      else
        return @old != $game_party.members[@character.member_index].equips
      end
    elsif @character.is_a?(Game_Event)
      @character.list.each do |command|
        if command.code == 108
          command.parameters[0][/<Equips\s*:\s*([AW0-9,]+)>/im]
          $1.scan(/-*\w+/).collect{|n|n}.each do|equip|
            if equip[0] == "A"
              @equipments << $data_armors[equip[/\d+/].to_i]
            elsif equip[0] == "W"
              @equipments << $data_weapons[equip[/\d+/].to_i]
            end
          end
        end
      end 
      return @old != @equipments
    end
  end
 
  #--------------------------------------------------------------------------
  # * Atualização da tela
  #--------------------------------------------------------------------------
  def update
    ms_updt
    if ($game_switches || [])[MBS::VisualEquip::SWITCH]# && equip_changed?
      update_equipment
    else
      @equip_sprite.dispose
    end
  end
 
  #-------------------------------------------------------------------------
  # * Atualização do gráfico de equipamento
  #-------------------------------------------------------------------------
  def update_equipment
 
    @equipments.clear
 
    pattern = @character.pattern < 3 ? @character.pattern : 1
    frames = 3
    if !@equip_sprite
      create_equip_sprite(self.viewport)
    elsif @equip_sprite.disposed?
      create_equip_sprite(self.viewport)
    end
    @equip_sprite.bitmap.clear
    bitmap = Bitmap.new(32,32)
 
     pr = ->(equip) {
      next if equip.nil?
        equip.note.each_line {|line|
        bitmap = Cache.character($1) if line =~ /<Graphic\s*=\s*([[:ascii:]]+)>/i
        frames = $1.to_i if line =~ /<Frames\s*=\s*(\d+)>/i
        }
        rect = Rect.new(pattern*(bitmap.width/frames),(@character.direction/2-1)*(bitmap.height/4),bitmap.width/frames,bitmap.height/4)
        @equip_sprite.bitmap.blt((frames/3-1)*4,0,bitmap,rect)
    }
 
    if @character.is_a?(Game_Player) || @character.is_a?(Game_Follower)
  
      if @character.is_a?(Game_Player)
  
      $game_party.members[0].equips.each {|equip|
        @equipments << equip
      }
        @old = $game_party.members[0].equips
      else
      return unless $game_party.members[@character.member_index]
      $game_party.members[@character.member_index].equips.each {|equip|
        @equipments << equip
      }
       @old = $game_party.members[@character.member_index].equips
      end
  
    elsif @character.is_a?(Game_Event)
      @character.list.each {|command|
        if command.code == 108
          command.parameters[0][/<Equips\s*:\s*([AW0-9,]+)>/im]
          $1.scan(/-*\w+/).collect{|n|n}.each {|equip|
            if equip[0] == "A"
              @equipments << $data_armors[equip[/\d+/].to_i]
            elsif equip[0] == "W"
              @equipments << $data_weapons[equip[/\d+/].to_i]
            end
          }
        end
      } 
      @old = @equipments
      end

      @equipments.compact.sort do |a, b|
        (a.note =~ /<z[ ]*=[ ]*(\d+)[ ]*>/i ? $1.to_i : 0) <=> (b.note =~ /<z[ ]*=[ ]*(\d+)[ ]*>/i ? $1.to_i : 0)
      end.each {|equip|
        pr[equip]
      }
  
      @equip_sprite.x = @character.screen_x + MBS::VisualEquip::POSITION_ADJUST_X
      @equip_sprite.y = @character.screen_y - bitmap.height/4 + @character.shift_y + @character.jump_height + MBS::VisualEquip::POSITION_ADJUST_Y
      @equip_sprite.z = @character.screen_z + 1
    end
 
    alias mbsdisps dispose
 
    def dispose
      mbsdisps
      @equip_sprite.dispose
    end
end
#==============================================================================
# ** Game_Follower
#==============================================================================
class Game_Follower < Game_Character
  attr_reader :member_index
end
any help?
screen shot of the event?

TheRamenGirl, please do not bump your topic unless it has been 24 hours later since your last post. You can review our forum rules here. Thank you.

screen shot of the event?
1.png

1.png
The script works fine, you just have to set it up correctly.

Event
1657556238477.png


armour - adventurer's garb
1657556269765.png


image
1657556310312.png


before
1657556378977.png
after
1657556441600.png
The problem is that the script makes a mistake twice, it expects to always get a string that matches the note that allows you to visually equip something on the fly. Since there's no match, it returns nil (nothing) and your game crashes. It should include a condition to prevent it from ever happening.
it expects to always get a string that matches the note
I had thought about that, and forgot to test it. It does cause an issue if the comment does not have the proper note.
Not 100% sure how to change it. I did initially try but the code structure is different from what I've seen and I wasn't sure how to best change it without rewriting it almost completely.

Never mind, A simple return works.
return if $1.nil?

Place after line 155 - command.parameters[0]
For the script to work first of all we need to turn on a switch (in my game is set to 28) otherwise the script is not working at all.. The problem is that when i turn on the switch the game crashes with the error 'scan'...
Never mind, A simple return works.
return if $1.nil?

Place after line 155 - command.parameters[0]
about that can you please show me little more details about where do i put the lines? ty!
(even tho i still wouldn't can to start the script because of the switch problem i mentioned above)
1657662081805.png
okk done. at first i was little confused because the 152-158 lines were diferent to my script but i found it

2.png

The switch issue remains tho..

... i have a thought in my mind... when i first added the script in my project it worked fine... but something happened and i deleted it and i went back
to the original post to get it again and then the problems started... maybe, just maybe the maker changed the script and "messed" it accidentaly?
Spoiler: Script
Ruby:
#==============================================================================
# ** MS - Visual Equipment
#------------------------------------------------------------------------------
# por Masked
#==============================================================================
#==============================================================================
# Instructions:
#------------------------------------------------------------------------------
# To define a graph for the equipment, write in its notes:
# <Graphic = Filename>
# The file "Filename" must be in the Graphics/Characters folder of your
# project
#
# To define more than one frame, in the case of an extra frame script,
# write this in the equipment notes:
# <Frames = x>
# Where 'x' is the number of frames
#
# To set the priority (Z axis) of the device:
# <Z = x>
# The 'x' being the equipment priority
#
# To define the graphics for an event, you need to create a comment on it
# with the following content:
# <Equips: x,y,z>
# With x, y and z being the equipment IDs, if x is A1, the armor of id 1 will be
# assigned to event, if y is W3, weapon of id 3 will be assigned to it,
# you can put as many IDs as you want in the list
#==============================================================================
($imported ||= {})[:ms_visual_equip] = true
module MBS
  module VisualEquip
#==============================================================================
# Configurações
#==============================================================================
    # Horizontal adjustment of the equipment position
    POSITION_ADJUST_X = -16
  
    # Vertical adjustment of the equipment position
    POSITION_ADJUST_Y = 0
  
    # Switch that enables/disables visual equip
    SWITCH = 1
  
    # Equipment sprite width
    BITMAP_WIDTH = 96
  
    # Equipment sprite height
    BITMAP_HEIGHT = 128
#==============================================================================
# Fim das configurações
#==============================================================================
  end
end
#==============================================================================
# ** Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
  alias ms_initlz initialize
  alias ms_updt update
  #--------------------------------------------------------------------------
  # * Inicialização do objeto
  #     viewport  : camada
  #     character : personagem (Game_Character)
  #--------------------------------------------------------------------------
  def initialize(viewport, character = nil)
    create_equip_sprite(viewport)
    ms_initlz(viewport,character)
  end
  #--------------------------------------------------------------------------
  # * Criação do sprite do equipamento
  #--------------------------------------------------------------------------
  def create_equip_sprite(viewport)
    @equipments = []
    @equip_sprite = Sprite.new(viewport)
    @equip_sprite.bitmap = Bitmap.new(MBS::VisualEquip::BITMAP_WIDTH,MBS::VisualEquip::BITMAP_HEIGHT)
    @equip_sprite.oy = 4
  end
  #--------------------------------------------------------------------------
  # Verificação de alteração no equipamento
  #--------------------------------------------------------------------------
  def equip_changed?
    if @character.is_a?(Game_Player) || @character.is_a?(Game_Follower)
      if @character.is_a?(Game_Player)
        return @old != $game_party.members[0].equips
      else
        return @old != $game_party.members[@character.member_index].equips
      end
    elsif @character.is_a?(Game_Event)
      @character.list.each do |command|
        if command.code == 108
          command.parameters[0][/<Equips\s*:\s*([AW0-9,]+)>/im]
          $1.scan(/-*\w+/).collect{|n|n}.each do|equip|
            if equip[0] == "A"
              @equipments << $data_armors[equip[/\d+/].to_i]
            elsif equip[0] == "W"
              @equipments << $data_weapons[equip[/\d+/].to_i]
            end
          end
        end
      end   
      return @old != @equipments
    end
  end
  #--------------------------------------------------------------------------
  # * Atualização da tela
  #--------------------------------------------------------------------------
  def update
    ms_updt
    if ($game_switches || [])[MBS::VisualEquip::SWITCH]# && equip_changed?
      update_equipment
    else
      @equip_sprite.dispose
    end
  end
  #-------------------------------------------------------------------------
  # * Atualização do gráfico de equipamento
  #-------------------------------------------------------------------------
  def update_equipment
    @equipments.clear
    pattern = @character.pattern < 3 ? @character.pattern : 1
    frames = 3
    if !@equip_sprite
      create_equip_sprite(self.viewport)
    elsif @equip_sprite.disposed?
      create_equip_sprite(self.viewport)
    end
    @equip_sprite.bitmap.clear
    bitmap = Bitmap.new(32,32)
     pr = ->(equip) {
      next if equip.nil?
        equip.note.each_line {|line|
        bitmap = Cache.character($1) if line =~ /<Graphic\s*=\s*([[:ascii:]]+)>/i
        frames = $1.to_i if line =~ /<Frames\s*=\s*(\d+)>/i
        }
        rect = Rect.new(pattern*(bitmap.width/frames),(@character.direction/2-1)*(bitmap.height/4),bitmap.width/frames,bitmap.height/4)
        @equip_sprite.bitmap.blt((frames/3-1)*4,0,bitmap,rect)
    }
    if @character.is_a?(Game_Player) || @character.is_a?(Game_Follower)
      if @character.is_a?(Game_Player)
      $game_party.members[0].equips.each {|equip|
        @equipments << equip
      }
        @old = $game_party.members[0].equips
      else
      return unless $game_party.members[@character.member_index]
      $game_party.members[@character.member_index].equips.each {|equip|
        @equipments << equip
      }
       @old = $game_party.members[@character.member_index].equips
      end
    elsif @character.is_a?(Game_Event)
      @character.list.each {|command|
        if command.code == 108
          command.parameters[0][/<Equips\s*:\s*([AW0-9,]+)>/im]
                    return if $1.nil?
          $1.scan(/-*\w+/).collect{|n|n}.each {|equip|
            if equip[0] == "A"
              @equipments << $data_armors[equip[/\d+/].to_i]
            elsif equip[0] == "W"
              @equipments << $data_weapons[equip[/\d+/].to_i]
            end
          }
        end
      }   
      @old = @equipments
      end
      @equipments.compact.sort do |a, b|
        (a.note =~ /<z[ ]*=[ ]*(\d+)[ ]*>/i ? $1.to_i : 0) <=> (b.note =~ /<z[ ]*=[ ]*(\d+)[ ]*>/i ? $1.to_i : 0)
      end.each {|equip|
        pr[equip]
      }
      @equip_sprite.x = @character.screen_x + MBS::VisualEquip::POSITION_ADJUST_X
      @equip_sprite.y = @character.screen_y - bitmap.height/4 + @character.shift_y + @character.jump_height + MBS::VisualEquip::POSITION_ADJUST_Y
      @equip_sprite.z = @character.screen_z + 1
    end
    alias mbsdisps dispose
    def dispose
      mbsdisps
      @equip_sprite.dispose
    end
end
#==============================================================================
# ** Game_Follower
#==============================================================================
class Game_Follower < Game_Character
  attr_reader :member_index
end
For the script to work first of all we need to turn on a switch (in my game is set to 28) otherwise the script is not working at all.. The problem is that when i turn on the switch the game crashes with the error 'scan'...
Ok... Maybe that was something with one specific map i was using the script in, apparently..
When i tested the script in different map the issue stopped.
Also i tried to turn on the switch on it's own separate event page and then change page and do the settings.. maybe that helps too? i dunno anymore...

Also Roninator2 Thank you for giving the script again because i really needed to check if it was the same with the one i had..
maybe that helps too?
Not unless you want to provide your project. I've tested it in a test demo and turning the switch on and off works fine.

Original thread: https://forums.rpgmakerweb.com/threads/solved-error-message-by-visual-equipment-script.148793/