[XP] to [VX] Elemental Reflector?

Started by Jragyn, August 26, 2009, 05:16:43 pm

Previous topic - Next topic

Jragyn

So I posted up a script here.

Teh Script:
|||
  V
Spoiler: ShowHide
#==============================================================================
# * Hima's Elemental Reflector v. 1.3
#------------------------------------------------------------------------------
#     This script will allow you to set your character or enemies to reflect any element
#    you want. You can also create armors or skills that create elemental reflector.
#
#    Version History
#    ---------------------------------------------------------
#    1.0    -    First Released
#    1.1    -    Fixed infinite reflect problem
#    1.2    -    More features added
#                a.) You can now choose to reflect any physical or magical skill.
#                b.) Physical reflect will also reflect any basic attack.
#                c.) Basic attack with element will also be reflected from elemental reflector.
#    1.3    -    Fixed some bugs that occur when you don't put all the ELEMENTS you defined into the database.
# ---------------------------------------------------------
# contact : ninomiya_mako@hotmail.com
#==============================================================================
module HIMA_REFLECT
    #--------------------------------------------------------------------------
  # - Customize Point -
    # ELEMENTS     - This is where you create the name of element you want to reflect. This is how it works
    #           {Name => Reflected Element ID, Name => Reflected Element ID, ...}
    #           The name can be anything, and ID is ID of the element that this will reflect. You have to
    #           create a new element that match what you input here.
    #           Special Element ID are as follows :
    #
    #            "Physical" -> For any physical skill, with atk_f greater than 0
    #            "Magic"    -> For any magic skill, with int_f (mind_f) greater than 0
    #
    #    WORD             - Message that will pop up when reflection occurs.
  #--------------------------------------------------------------------------
    ELEMENTS = {"Reflect Physical" => "Physical",
                "Reflect Heat" => 2,
                "Reflect Cold" => 3,
                "Reflect Thunder" => 4,
                "Reflect Liquid" => 5,
                "Reflect Ground" => 6,
                "Reflect Air" => 7,
                "Reflect Energy" => 8,
                "Reflect Void" => 9,
                "Reflect Magic" => "Magical"}
    WORD = "Reflect"

end

module RPG
    class Skill
        def type_of_skill
            if @int_f > 0
                return "Magical"
            elsif @atk_f > 0
                return "Physical"
            else
                return nil
            end
        end
    end
end

class Game_Battler
  attr_accessor :reflect                   # Reflect Flag
    alias hima_reflect_init initialize
    def initialize
        @reflect = 0    #0 = no reflect, 1 = basic_attack, 2 = skill_effect
    hima_reflect_init
    end
   
    alias hima_reflect_attack_effect attack_effect
    def attack_effect(attacker)
        # Check for reflect basic attack
        element_to_reflect = HIMA_REFLECT::ELEMENTS.index("Physical")
        reflect_id = $data_system.elements.index(element_to_reflect)
        if reflect_id != nil
            if self.element_reflect(reflect_id) == 1
                if attacker.element_reflect(reflect_id) == 1
                    self.damage = "Block"
                    self.reflect = 0
                else
                    self.damage = HIMA_REFLECT::WORD
                    self.reflect = 1
                end
                return false
            end
        end
        # End of reflect basic attack
       
        # Check for reflect element of basic attack
        for q in 0...attacker.element_set.size
            element_id = attacker.element_set[q]
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if self.element_reflect(reflect_id) == 1
          if attacker.element_reflect(reflect_id) == 1
              self.damage = "Block"
              self.reflect = 0
          else
              self.damage = HIMA_REFLECT::WORD
              self.reflect = 1
          end
          return false
                end
            end
        end #end for       
        # End of reflect element of basic attack
        hima_reflect_attack_effect(attacker)
    end
   
    alias hima_reflect_skill_effect skill_effect
  def skill_effect(user, skill)
        # Reflect physical or magic skill
        if skill.type_of_skill != nil
            element_id = skill.type_of_skill
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if reflect_id != nil
                    if self.element_reflect(reflect_id) == 1
                        if user.element_reflect(reflect_id) == 1
                                self.damage = "Block"
                                self.reflect = 0
                        else
                                self.damage = HIMA_REFLECT::WORD
                                self.reflect = 2
                        end
                        return false
                    end
                end
            end
        end
       
        # Reflect specific element
        for q in 0...skill.element_set.size
            element_id = skill.element_set[q]
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if reflect_id != nil
                    if self.element_reflect(reflect_id) == 1
                        if user.element_reflect(reflect_id) == 1
                                self.damage = "Block"
                                self.reflect = 0
                        else
                                self.damage = HIMA_REFLECT::WORD
                                self.reflect = 2
                        end
                        return false
                    end
                end
            end
        end #end for
        hima_reflect_skill_effect(user,skill)
  end
   
    def element_reflect(element_id)
        if self.is_a?(Game_Actor)
        result = $data_classes[self.class_id].element_ranks[element_id]

            for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
                armor = $data_armors[i]
                if armor != nil and armor.guard_element_set.include?(element_id)
                    result = 1
                end
            end
   
            for i in @states
                if $data_states[i].guard_element_set.include?(element_id)
                    result = 1
                end
            end
        else
            result = $data_enemies[self.enemy_id].element_ranks[element_id]
            for i in @states
                if $data_states[i].guard_element_set.include?(element_id)
                    result = 1
                end
            end
        end
    # Method end
    return result
  end
end

class Game_Enemy < Game_Battler
    attr_accessor        :enemy_id
end

class Scene_Battle
    alias hima_update_phase4_step5 update_phase4_step5
  def update_phase4_step5
        hima_update_phase4_step5
    reflect = 0
        for target in @target_battlers
          if target.reflect != 0
                reflect = target.reflect
                target.reflect = 0
      end
    end
        if reflect > 0
      @target_battlers = []
            @target_battlers.push(@active_battler)
            case reflect
                when 1
                    @active_battler.attack_effect(@active_battler)
                when 2
                    @active_battler.skill_effect(@active_battler,@skill)
            end #case
            @phase4_step = 4
        else
      @phase4_step = 6
    end
  end
end

Teh Details:
http://forum.chaos-project.com/index.php?topic=4469.0

Its all about reflecting!

However I like to hop to and from projects in VX and XP,
and was hoping someone could assist me with a conversion.

Firstly, I use this so I can see my battlers in battle:
Spoiler: ShowHide
#==============================================================================
# ** Actor Battler Graphics
#------------------------------------------------------------------------------
#    by DerVVulfman
#    version 1.0
#    03-01-2008
#    RGSS2
#------------------------------------------------------------------------------
#
#  INTRODUCTION:
#
#  This system permits you to include 'Actor Battler' graphics that were not
#  included in the RPGMaker VX system.   This script mimics many of the lost
#  features, and includes a new one:  Actor Battler Centering.

#------------------------------------------------------------------------------
#
#  USAGE:
#
#  --Positioning--
#   A nice feature to this system  is the ability to adjust the left/right &
#   up/down position of your battlers.
#
#   Actually, the vertical up/down position  can be adjusted by changing the
#   value of the SCREEN_Y variable.   The left/right positioning is a little
#   different.
#
#   The CENTER_X value is a true/false value  that sets whether the battlers
#   line up from the left and space themselves out  in the manner of the de-
#   fault RPGMaker XP  or whether the system calculates and centers them ac-
#   ross the screen.
#
#   The DEFAULT_X value establishes  how many actors  are typically shown in
#   the battlefield. While this is the default value, the maximum value used
#   can be changed with a script call.
#
#   Finally,  the TRANSPARENT value is another true/false value that you can
#   use to make the battlers lightly transparent until they're about to per-
#   form an attack.  Another feature from RPGMaker XP.
#
#  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
#  --The Actor List--
#  This system DOES require you to edit the configuration system to list all
#  of the 'actor' battlers  that you  are using.   It is assumed  that these
#  battlers will be in the  'Graphics\Battlers'  folder with the rest of the
#  enemy battlers.
#
#  Each value in the ACTOR array holds two values:   filename and hue.  This
#  not only allows you to add battle graphics  for your heroes,  but adjusts
#  the character's hue as well.  If you do not include the hue setting, it
#  goes to the default setting of '0'.
#
#------------------------------------------------------------------------------
#
#  SCRIPT CALLS:
#
#  There's only two script calls that you need to know.
#
#  --Changing Battlers--
#  Given that this system allows you to use 'Actor' battlers, you may find a
#  need to 'change' the battler in-game.  Unfortunately, this cannot be done
#  with a pre-rendered map event, so I had to make a script call:
#
#           $game_actors[ID].set_battler("filename", hue)

#  By using this call, you can change the graphic and hue of a battler while
#  the game is running. 
#
#  As an example:  $game_actors[1].set_battler("Ylva")

#  ...would set actor #1's battler to use "Ylva.png" as the graphic desired.
#  You may note that the 'hue' was not included  in this call.   The default
#  value of '0' was used.
#
#  NOTE:  Just calling $game_actors[2].set_battler() would erase the battler
#         from actor #2, rendering it invisible on the battlefield.
#
#  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
#  --Changing Position Value--
#  This script allows you to have the battlers centered in the battlefield
#  and spaced out evenly.  Under most circumstances, you have four members
#  in your party.  But what if you want to increase the number of members
#  to 5 or 6?
#
#  Now, this system does not increase the number of members in your party,
#  but it is already set up to adjust the spacing of your members in the
#  battlefield.  With a simple script call:
#
#           $game_system.actorbattler_max = 7
#
#  You can make the system space the battlers on the field with the under-
#  standing that up to 7 members are in the party.
#
#------------------------------------------------------------------------------
#
#  EDITS AND MODIFICATIONS:

#  This system Aliases the following methods:
#  * initialize                     (RPG::Actor)
#  * initialize                     (Game_Temp)
#  * initialize                     (Game_System)
#  * initialize                     (Game_Actor)
#  * update                         (Sprite_Battler)
#  * start                          (Scene_Battle)
#  * start_party_command_selection  (Scene_Battle)
#  * process_victory                (Scene_Battle)
#  * execute_action                 (Scene_Battle)
#
#  This system redefines the following methods:
#  * use_sprite?                    (Game_Actor)
#  * create_actors                  (Spriteset_Battle)
#  * update_actors                  (Spriteset_Battle)

#
#------------------------------------------------------------------------------
#
#  TERMS AND CONDITIONS:
#
#  Free to use, even in commercial projects.  Just note that I need some form
#  of due credit... even a mere mention in some end titles.
#
#==============================================================================



#==============================================================================
# ** Actor_Battler Module
#------------------------------------------------------------------------------
#  A module containing configurable data for the Actor Battler Graphic system.
#==============================================================================

module Actor_Battler
  # Actor battler array
  ACTOR = Array.new  # Do not touch -_^

   #========================================================================
   #  **  C  O  N  F  I  G  U  R  A  T  I  O  N      S  Y  S  T  E  M  **  #
   #======================================================================== 
 
  # --Positioning--
  # Actor Battler positioning system
  #
    CENTER_X    = true    # If true, centers actors rather than default lineup.
    DEFAULT_X   = 5       # Default party Max
    SCREEN_Y    = 400     # Vertical height of battlers
    TRANSPARENT = false    # If true, makes lightly transparent until attacking.
 
   
  # --Actor List--
  # Add your actor battlers here
  #
  # Actor#      Filename,   Hue (optional)
    ACTOR[1] = ["Rubikiss"]
    ACTOR[2] = ["Bennett"]
    ACTOR[3] = ["Ulrika",  0]
    ACTOR[4] = ["Ralph",     0]
    ACTOR[5] = ["Lydia", 0]
    ACTOR[6] = ["Aluxes",    0]
    ACTOR[7] = ["Eryn",     0]
    ACTOR[8] = ["Kitoshi",    0]

   
   #========================================================================
   #  **  E  N  D     O  F     C  O  N  F  I  G  U  R  A  T  I  O  N   **  #
   #======================================================================== 
end



#==============================================================================
# ** RPG Module
#------------------------------------------------------------------------------
#  A module containing RPGVX Data Structures.
#==============================================================================
module RPG
  #============================================================================
  # ** Actor
  #----------------------------------------------------------------------------
  #  Data class for actors
  #============================================================================ 
  class Actor
    #------------------------------------------------------------------------
    # * Alias Listings
    #------------------------------------------------------------------------ 
    alias actorbattler_init initialize
    #------------------------------------------------------------------------
    # * Object Initialization
    #------------------------------------------------------------------------ 
    def initialize
      # Perform the original call
      actorbattler_init
      @battler_name = ""
      @battler_hue = 0
    end
  end
end



#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
# The instance of this class is referenced by $game_temp.
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :battle_main_phase        # battle flag: main phase
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------   
  alias actorbattler_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Perform the original call
    actorbattler_initialize
    # Set the main phase flag to false
    @battle_main_phase = false
  end
end



#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  This class handles system-related data. Also manages vehicles and BGM, etc.
# The instance of this class is referenced by $game_system.
#==============================================================================

class Game_System
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :actorbattler_max         # Max. size for centered battlers
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------   
  alias actorbattler_initialize initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Perform the original call
    actorbattler_initialize
    # Set 'Centered' battler max to 4 (default)
    @actorbattler_max = Actor_Battler::DEFAULT_X
  end
end



#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles actors. It's used within the Game_Actors class
# ($game_actors) and referenced by the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------- 
  attr_accessor :screen_x                 # battle screen X coordinate
  attr_accessor :screen_y                 # battle screen Y coordinate
  #--------------------------------------------------------------------------
  # * Alias Listings
  #-------------------------------------------------------------------------- 
  alias actorbattler_init initialize
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor_id : actor ID
  #--------------------------------------------------------------------------
  def initialize(actor_id)
    # Perform the original call
    actorbattler_init(actor_id)
    # Apply battler graphic
    @battler_name = Actor_Battler::ACTOR[actor_id][0]
    # Apply battler hue if exists, else default of '0'
    if Actor_Battler::ACTOR[actor_id][1] != nil
      @battler_hue  = Actor_Battler::ACTOR[actor_id][1]
    else
      @battler_hue  = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Change Battler
  #     battler_name  : new battler graphic filename
  #     battler_hue   : new battler hue setting (default = 0)
  #--------------------------------------------------------------------------
  def set_battler(battler_name = "", battler_hue = 0)
    @battler_name = battler_name
    @battler_hue = battler_hue
  end 
  #--------------------------------------------------------------------------
  # * Use Sprites?
  #--------------------------------------------------------------------------
  def use_sprite?
    return true
  end 
  #--------------------------------------------------------------------------
  # * Get Battle Screen X-Coordinate
  #--------------------------------------------------------------------------
  def screen_x
    if self.index != nil
      if Actor_Battler::CENTER_X
        # Return after calculating x-coords of centered party members
        return self.index * (544 / $game_system.actorbattler_max) +
              ($game_system.actorbattler_max - $game_party.members.size) *
              (272 / $game_system.actorbattler_max) +
              (272 / $game_system.actorbattler_max)
      else
        # Return after calculating x-coords of default-aligned party members
        return self.index * 136 + 68
      end
    else
      return 0
    end
  end
  #--------------------------------------------------------------------------
  # * Get Battle Screen Y-Coordinate
  #--------------------------------------------------------------------------
  def screen_y
    return Actor_Battler::SCREEN_Y
  end 
  #--------------------------------------------------------------------------
  # * Get Battle Screen Z-Coordinate
  #--------------------------------------------------------------------------
  def screen_z
    # Return after calculating z-coordinate by order of members in party
    if self.index != nil
      return $game_party.members.size - self.index
    else
      return 0
    end
  end
end



#==============================================================================
# ** Sprite_Battler
#------------------------------------------------------------------------------
#  This sprite is used to display battlers. It observes a instance of the
# Game_Battler class and automatically changes sprite conditions.
#==============================================================================

class Sprite_Battler < Sprite_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #-------------------------------------------------------------------------- 
  alias actorbattler_update update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Perform the original call
    actorbattler_update
    # If the actor battlers are lightly transparent until they act
    if Actor_Battler::TRANSPARENT == true
      # If the battler is a visible actor battler
      if @battler.is_a?(Game_Actor) and @battler_visible
        # Bring opacity level down a bit when not in main phase
        if $game_temp.battle_main_phase
          self.opacity += 3 if self.opacity < 255
        else
          self.opacity -= 3 if self.opacity > 207
        end
      end   
    end
  end
end



#==============================================================================
# ** Spriteset_Battle
#------------------------------------------------------------------------------
#  This class brings together battle screen sprites. It's used within the
# Scene_Battle class.
#==============================================================================

class Spriteset_Battle
  #--------------------------------------------------------------------------
  # * Create Actor Sprite
  #    Removes the 'empty' battler image used by the default system and
  #    replaces it.  It also observes the actual size of the party and
  #    not a predetermined 4-party limit.
  #--------------------------------------------------------------------------
  def create_actors
    @actor_sprites = []
    for actor in $game_party.members.reverse
      @actor_sprites.push(Sprite_Battler.new(@viewport2, actor))
    end
  end 
  #--------------------------------------------------------------------------
  # * Update Actor Sprite
  #--------------------------------------------------------------------------
  def update_actors
    # Reset actor battler sprites if party size increases
    if $game_party.members.size > @actor_sprites.size
      dispose_actors
      create_actors
    end
    for sprite in @actor_sprites
      sprite.update
    end
  end 
end



#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle < Scene_Base
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias actorbattler_s start
  alias actorbattler_spcs start_party_command_selection
  alias actorbattler_pv process_victory
  alias actorbattler_ea execute_action
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    actorbattler_s
    $game_temp.battle_main_phase = false
  end
  #--------------------------------------------------------------------------
  # * Start party command selection
  #--------------------------------------------------------------------------
  def start_party_command_selection
    actorbattler_spcs   
    if $game_temp.in_battle
      $game_temp.battle_main_phase = false
    end
  end
  #--------------------------------------------------------------------------
  # * Victory Processing
  #--------------------------------------------------------------------------
  def process_victory
    $game_temp.battle_main_phase = false
    actorbattler_pv
  end
  #--------------------------------------------------------------------------
  # * Start Execution of Battle Processing
  #--------------------------------------------------------------------------
  def execute_action
    actorbattler_ea
    $game_temp.battle_main_phase = true
  end
end


I figured, 'Hey, its less than 200 lines of code, maybe I culd do it myself!'
So I took the liberty of investigating methods and all that from XP vs. VX...
and discovered things that perhaps could aid someone else in doing this:

When I pop it directly into VX with no conversion, the first thing it complains about...
A lack of Phase4 in Scene_Battle!

Phase4, from my checking it out, contains 6 parts.
p1-action preparation (win/lose)
p2-start action
p3-animation of performer
p4-animation for target
p5-damage display
p6-refresh

For those of you unfamilier with VX, it went back to rm2k-style of a message battle format!

So phase4_part3 simply doesn't seem to exist in any sense of the idea.
When you are attacked, the screen flashes(if there is a screen flash in the animation) and it make the sound effect.

Phase4_part4 seems to exist under a different name to some extent: def display_action_effects.

Another difference I've found in the XP script is the reference to armor.guard_element_set.
In VX however, it refers to it as elemental_rate, or element_ranks...

So in all the accumulations of knowledge thus far, I mutated the script to look like this:
Spoiler: ShowHide
#==============================================================================
# * Hima's Elemental Reflector v. 1.3
#------------------------------------------------------------------------------
#     This script will allow you to set your character or enemies to reflect any element
#    you want. You can also create armors or skills that create elemental reflector.
#
#    Version History
#    ---------------------------------------------------------
#    1.0    -    First Released
#    1.1    -    Fixed infinite reflect problem
#    1.2    -    More features added
#                a.) You can now choose to reflect any physical or magical skill.
#                b.) Physical reflect will also reflect any basic attack.
#                c.) Basic attack with element will also be reflected from elemental reflector.
#    1.3    -    Fixed some bugs that occur when you don't put all the ELEMENTS you defined into the database.
# ---------------------------------------------------------
# contact : ninomiya_mako@hotmail.com
#==============================================================================
module HIMA_REFLECT
    #--------------------------------------------------------------------------
  # - Customize Point -
    # ELEMENTS     - This is where you create the name of element you want to reflect. This is how it works
    #           {Name => Reflected Element ID, Name => Reflected Element ID, ...}
    #           The name can be anything, and ID is ID of the element that this will reflect. You have to
    #           create a new element that match what you input here.
    #           Special Element ID are as follows :
    #
    #            "Physical" -> For any physical skill, with atk_f greater than 0
    #            "Magic"    -> For any magic skill, with int_f (mind_f) greater than 0
    #
    #    WORD             - Message that will pop up when reflection occurs.
  #--------------------------------------------------------------------------
    ELEMENTS = {"Reflect Physical" => "Physical",
                "Reflect Heat" => 2,
                "Reflect Cold" => 3,
                "Reflect Thunder" => 4,
                "Reflect Liquid" => 5,
                "Reflect Ground" => 6,
                "Reflect Air" => 7,
                "Reflect Energy" => 8,
                "Reflect Void" => 9,
                "Reflect Magic" => "Magical"}
    WORD = "Reflect"

end

module RPG
    class Skill
        def type_of_skill
            if @spi_f > 0
                return "Magical"
            elsif @atk_f > 0
                return "Physical"
            else
                return nil
            end
        end
    end
end

class Game_Battler
  attr_accessor :reflect                   # Reflect Flag
    alias hima_reflect_init initialize
    def initialize
        @reflect = 0    #0 = no reflect, 1 = basic_attack, 2 = skill_effect
    hima_reflect_init
    end
   
    alias hima_reflect_attack_effect attack_effect
    def attack_effect(attacker)
        # Check for reflect basic attack
        element_to_reflect = HIMA_REFLECT::ELEMENTS.index("Physical")
        reflect_id = $data_system.elements.index(element_to_reflect)
        if reflect_id != nil
            if self.element_reflect(reflect_id) == 1
                if attacker.element_reflect(reflect_id) == 1
                    self.damage = "Block"
                    self.reflect = 0
                else
                    self.damage = HIMA_REFLECT::WORD
                    self.reflect = 1
                end
                return false
            end
        end
        # End of reflect basic attack
       
        # Check for reflect element of basic attack
        for q in 0...attacker.element_set.size
            element_id = attacker.element_set[q]
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if self.element_reflect(reflect_id) == 1
          if attacker.element_reflect(reflect_id) == 1
              self.damage = "Block"
              self.reflect = 0
          else
              self.damage = HIMA_REFLECT::WORD
              self.reflect = 1
          end
          return false
                end
            end
        end #end for       
        # End of reflect element of basic attack
        hima_reflect_attack_effect(attacker)
    end
   
    alias hima_reflect_skill_effect skill_effect
  def skill_effect(user, skill)
        # Reflect physical or magic skill
        if skill.type_of_skill != nil
            element_id = skill.type_of_skill
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if reflect_id != nil
                    if self.element_reflect(reflect_id) == 1
                        if user.element_reflect(reflect_id) == 1
                                self.damage = "Block"
                                self.reflect = 0
                        else
                                self.damage = HIMA_REFLECT::WORD
                                self.reflect = 2
                        end
                        return false
                    end
                end
            end
        end
       
        # Reflect specific element
        for q in 0...skill.element_set.size
            element_id = skill.element_set[q]
            element_to_reflect = HIMA_REFLECT::ELEMENTS.index(element_id)
            if element_to_reflect != nil
                reflect_id = $data_system.elements.index(element_to_reflect)
                if reflect_id != nil
                    if self.element_reflect(reflect_id) == 1
                        if user.element_reflect(reflect_id) == 1
                                self.damage = "Block"
                                self.reflect = 0
                        else
                                self.damage = HIMA_REFLECT::WORD
                                self.reflect = 2
                        end
                        return false
                    end
                end
            end
        end #end for
        hima_reflect_skill_effect(user,skill)
  end
   
    def element_reflect(element_id)
        if self.is_a?(Game_Actor)
        result = $data_classes[self.class_id].element_ranks[element_id]

            for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
                armor = $data_armors[i]
                if armor != nil and armor.element_set.include?(element_id)
                    result = 1
                end
            end
   
            for i in @states
                if $data_states[i].element_set.include?(element_id)
                    result = 1
                end
            end
        else
            result = $data_enemies[self.enemy_id].element_ranks[element_id]
            for i in @states
                if $data_states[i].element_set.include?(element_id)
                    result = 1
                end
            end
        end
    # Method end
    return result
  end
end

class Game_Enemy < Game_Battler
    attr_accessor        :enemy_id
end

class Scene_Battle
# Displaying the damage of the skill
    alias hima_display_action_effects display_action_effects
  def display_action_effects(target, obj = nil)
        hima_display_action_effects(target, obj)
    reflect = 0
        for target in @target_battlers
          if target.reflect != 0
                reflect = target.reflect
                target.reflect = 0
      end
    end
        if reflect > 0
      @target_battlers = []
            @target_battlers.push(@active_battler)
            case reflect
                when 1
                    @active_battler.attack_effect(@active_battler)
                when 2
                    @active_battler.skill_effect(@active_battler,@skill)
            end #case
            @battle_main_phase = false
        else
      @battle_main_phase = false
    end
  end
end


In which if casting a spell that should be reflected, it pops an error:

Script 'elemental reflect' line 195: NoMethodError occured.
Undefined method `each' for Nil:NilClass.

This error pops in one of 2 places:
If I attack first, the skill will cast and do damage, kill the enemy if it is supposed to kill, then pop the error.
If the enemy attacks first, then this error will pop as soon as it should be my turn to act.

I tried.
I failed.
Can anyone else help me with this?
A bright light can either illuminate or blind, but how will you know which until you open your eyes?