[XP] Exclusion Elements (Excludes Special Elements from Damage Calculations)

Started by Heretic86, September 07, 2013, 08:18:29 pm

Previous topic - Next topic

Heretic86

Exclusion Elements
Authors: Heretic
Version: 1.0
Type: Scripting Tool
Key Term: Scripting Tool



Introduction

Scripters Tool

This script will allow Multiple Scripts to have Special Elements that are Excluded from Damage Calculations.


Features

For Scripters, just add your Special Elements to the Exclusion Elements list for Damage Calculations to not be affected by your Special Element.


  • Promotes Script Compatability

  • Error Messages for people using your scripts

  • Start a New Game after Installation




Screenshots

No Screenshots


Demo

No Demo


Script

Place this script ABOVE all depenant scripts.

Spoiler: ShowHide

#==============================================================================
#
#      Heretics Exclusion Elements
#      Version 1.0
#      Monday, Sept 3rd, 2013
#
#==============================================================================
#
# THIS IS A SCRIPTERS TOOL
#
# Non Scripters will need this Script if you have any other Scripts that
# are dependant on this one.
#
# Start a NEW GAME after Installing this script or Game will crash.
#
# This script is needed for other scripts that use Special Types of Elements.
# Some scripts treat Elements in special ways in order to do special things.
# What this will do is prevent those Special Elements from being used in
# damage calculations.  For example, KK20 wrote a script by request to
# allow Targetting Anyone.  It is accomplished by treating elements in a
# special way, but we didnt want that Special Element to be used for
# calculating damage.  I've also written another script that uses Elements
# to determine if certain types of equipment will allow an Actor to
# view more detailed information on an Enemy.  I called that script
# Spy Equipment.  Spy equipment also allows an Enemy to Resist Spying
# but we did NOT want to make an Enemy get extra damage because a ring
# allowed an enemy to be spied on.  I just wanted the equipment to be
# used to show an Enemys stats.
#
# Place just below Scene_Debug.  It should be as close to Scene_Debug as
# possible for Compatability.
#
# This Script allows Special Elements to be NOT calculated in which
# Elements a Battler is Weakest against.  Some Elements are not
# really Elements, and are intended for having other uses.  For example
# determining if an Item or Spell can be used to Target Anyone.
#
# The reason this script was different scripts needing to make changes
# to the same Methods for Excluding specific Elements.
#
# IMORTANT: Make an ALIAS of Game System Initalize, do NOT REDEFINE it.
# Redefinitions will break compatability with other scripts.
#
# To use this Script, in your Script, you'll need to make an alias of
# Game System Initialize and push any Element ID's on to the existing
# @exclusion_elements array.  The @exclusion_elements array may be
# accessed by multiple scripts for each Script to add their own ID's
# to the array.
#
# Use "add_exclusion_elements(element_id)" instead of Pushing as this script
# provides some Error Messages when things arent installed.  You can customize
# the error messages to be more clear to others that use your scripts if you
# want.  When someone that uses your script has trouble and can understand
# why a script you may write is not working, they will be able to easily fix
# it themselves.
#
# For Conditional Script Setup, you can use
# if Game_Battler::method_defined?('exclusion_elements')
# outside of your Method Definitions
#
# # If this Script is installed
# if Game_Battler::method_defined?('exclusion_elements')
#   class Some_Class
#     def some_method(some_arg)
#       do stuff
#     end
#   end
# # Script not installed
# else
#   class Some_Class
#     def some_method(some_arg)
#       do stuff differently from other definition
#     end
#   end
# end
#
# This probably wont be too useful for experienced scripters, but for thsoe
# who aspire to become scripters, this will help scripts you write to
# be more compatible with multiple scripts.
#
# An easy way to allow your Script to be set up by people who arent very good
# at scripting is to just use a CONSTANT for the NAME of your ELEMENT.
#
# MY_ELEMENT_TAG = "Element Name"
#
# Then to get the Element ID without burdening Non Scripters with getting
# ID's of Elements, just do this:
# $data_system.elements.index(MY_ELEMENT_TAG)
# That will give you your Element ID.

#==============================================================================
# ** Game_System
#==============================================================================

class Game_System
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :exclusion_elements       # Array of Element ID's for Excluding
  #----------------------------------------------------------------------------
  # * Object Initialization
  #----------------------------------------------------------------------------
  alias battler_elements_correct_initialize initialize
  def initialize
    # Call Original or any other Aliases
    battler_elements_correct_initialize
    # New Property - Elements to Exclude during calculation of Weakest
    @exclusion_elements = []
  end
  #----------------------------------------------------------------------------
  # * Add Exclusion Elements - Allows Error Checking
  #----------------------------------------------------------------------------
  def add_exclusion_elements(element_id)
    # If ID already exists in the Array
    if @exclusion_elements.include?(element_id)
      # If Running Game from the Editor
      if $DEBUG
        # Explain the Error
        print "ERROR in Element Exclusion\n\n",
              "The ID ", element_id, " is already in the Array"
        # This really shouldn't occur unless $data is accidentally changed.
        # $data uses References not Values, so its easy to screw up and
        # alter $data accidentally.
      end
    end
    # If ID already exists in the Array
    if not element_id.is_a?(Integer)
      # If Running Game from the Editor
      if $DEBUG
        # Explain the Error
        print "ERROR in Element Exclusion\n\n",
              "add_exclusion_elements(element_id)\n",
              "The Value entered for element_id (", element_id,
              ") is not a number!\n\n",
              "element_id MUST be a Number!"
        # Give More Information on how to Fix
        if element_id.nil?
          print "The Element ID entered is nil.\n\n",
                "This usually means that you have a Script that is not\n",
                "set up Correctly.  To fix this, you may need to check\n",
                "any recently installed Scripts and make sure you've read\n",
                "the instructions for configuration.\n\n",
                "In plain English, you have a Script that needs\n",
                "to have an Element Name set in the Database\n",
                "and it has NOT been set up.  Check your Spelling too."
        end
      end 
    end   
    # Only accept ID's
    if element_id.is_a?(Integer)
      # Push it on to the List
      @exclusion_elements.push(element_id)
    end
  end
end



#-------------------------------------------------------------------------
# Class Game Battler
#-------------------------------------------------------------------------
class Game_Battler
  #--------------------------------------------------------------------------
  # * Exclusion Elements
  #
  #   - if Game_Battler::method_defined?('exclusion_elements')
  #     Useful for setting up Scripts with Conditional Method Definitions
  #
  #     Also allows you to keep your Code neat and tidy.
  #--------------------------------------------------------------------------
  def exclusion_elements
    # Just returns the Game System
    return $game_system.exclusion_elements
  end
  #----------------------------------------------------------------------------
  # * Add Exclusion Elements - Allows Error Checking
  #----------------------------------------------------------------------------
  def add_exclusion_elements(element_id)
    # Check for Errors when adding New Elements
    $game_system.add_exclusion_elements(element_id)
  end
  #--------------------------------------------------------------------------
  # * Calculating Element Correction
  #     element_set : element
  #
  #     IMPORTANT NOTE: $data_system is a Table (see Table in Enterbrain
  #     Help Documentation) and is NOT an Array or Hash.  Tables are
  #     much faster for huge volumes of information.  When you access
  #     information in a Table, you get Reference, not Value.  Clone
  #     is needed because returning a Reference will cause any edits
  #     to what ever $data spits out to cause $data itself to be edited
  #     and not just the instance of the information returned.
  #
  #     Say you write a script that edits the Name of an Element.  When
  #     that Element Name is edited (like just using element_set[0] = "foo"
  #     that will cause $data to be changed, not just the instance of this
  #     argument.  You might want that in some cases, but just so you know
  #     that this method will make sure you dont accidentally change $data.
  #     That is why CLONE is used here.  Removing .clone will most likely
  #     cause your game to have Bugs that give no errors and only occur
  #     after a while of gameplay testing.
  #--------------------------------------------------------------------------
  def elements_correct(element_set)
    # Important! - Remove Reference to $data so $data is not altered
    element_set = element_set.clone
    # Remove any Excluded Elements from the element_set arg array
    for i in element_set
      # Delete Values from cloned Argument so $data is not altered
      element_set.delete(i) if exclusion_elements.include?(i)
    end
    # If not an element
    if element_set == []
      # Return 100 - Not Weak against anything
      return 100
    end
    # Return the weakest object among the elements given
    # * "element_rate" method is defined by Game_Actor and Game_Enemy classes,
    #    which inherit from this class.
    weakest = -100
    for i in element_set
      # Element with the Highest Rate means it is the Weakest
      weakest = [weakest, self.element_rate(i)].max
    end
    return weakest
  end
end



Instructions

Just install this script above all dependant scripts.


Compatibility


  • Start a New Game after Installation or Game will Crash



Any Scripts that redefine Game_Battler def elements_correct wont be compatible without alterations to code.  It can be made to work however.

KK20 wrote a Script for Target Anyone that does redefine elements_correct.  I made a few changes to it for his script to work either as a Standalone Script and to work with this script when this script is installed above his script.

KK20's Target Anyone
Spoiler: ShowHide
=begin
===============================================================================
Target Anyone Scope
Version 1.0

By KK20

- Heretic Note: This version of the script IS compatible either with or without
  the Exclusion Elements Script.
 
===============================================================================
-[ Introduction ]-
This small script allows the player to make single target scopes reverse its
intended target. In other words, you can now choose to Heal a monster or one
of your allies.

-[ Instructions ]-
1.) Scroll down to the configurations and locate Constant TARGET_ANYONE_TAG.
     Change the string associated with it if you like.
2.) Create a new element in the Database. Name this new element the same as you
     have TARGET_ANYONE_TAG assigned to.
3.) Apply this new element to skills or items that you wish to have this
     effect.

     ~ NOTE: The effect will only work if you set the scope to "One Enemy"
             or "One Ally".
             
     - Heretic NOTE: This version of the script was altered to allow you to
             use "All Enemies" and "All Allies".

-[ Compatibility ]-
* This script was made with the default battle system in mind. Custom battle
   scripts will most likely not work with this script without edits.
* Not tested with SDK
* Changes made to Game_Actor, Game_Battler, and Scene_Battle

Heretic Additions:

Bugfixes: 
   -  Fixed a bug that selected wrong Target Type by cancelling, then
      reselecting the same Item or Skill.
     
   -  Fixed a bug that caused Damage to be improperly calculated.


===============================================================================
Credits:
KK20 - Writing this script
Charlie Fleed - For the idea
===============================================================================
=end

#===========#
# Configure #
#===========#

# The element ID's name that allows the user to target any one battler
TARGET_ANYONE_TAG = "Target Any"

#===============#
# End Configure #
#===============#

#-------------------------------------------------------------------------
# Class Game Actor
#-------------------------------------------------------------------------
class Game_Actor < Game_Battler
  attr_accessor :changed_scope
 
  alias call_init_again initialize
  def initialize(actor_id)
    @changed_scope = false
    call_init_again(actor_id)
  end
 
  def clear
    super
    @changed_scope = false
    @target_type = nil
  end 
 
end

# Heretic
#
# This section is for Script Compatability.
#
# It will check to see if another Script is installed.  If Exclusion Elements
# is installed, it will use Game System.  If Exclusion Elements is not
# installed, then Game Battler is used.  There are NO Performance Hits
# either way, as this section runs ONLY when the game is initially fired up.
# What it does is allows different Methods to be defined depending on what
# Scripts you have installed.  So this script should work just fine regardless
# if you use the Exclusion Elements Script or not, and NO actions are needed
# on your part.
#
# Note: If you use the Exclusion Elements Script, it needs to be ABOVE this one.
#
# See Documentation in Exclusion Elements Script for how to use that script.

# Conditional Method Defintion
if Game_Battler::method_defined?('exclusion_elements')
  #==============================================================================
  # ** Game_System
  #==============================================================================
  class Game_System
    #--------------------------------------------------------------------------
    # * Object Initialization
    #
    #   This call will add the ID of your TARGET_ANYONE_TAG to the list
    #   of Exclusion Elements.  You don't have to worry about what the
    #   ID of your Element is, the Initialization Script does that for you.
    #--------------------------------------------------------------------------
    alias battle_target_anyone_initialize initialize
    def initialize
      # Call Other Aliases
      battle_target_anyone_initialize
      # Get Element ID from Data System
      target_anyone_id = $data_system.elements.index(TARGET_ANYONE_TAG)
      # Check that person using this Script has Game Database set up right
      if target_anyone_id.nil? and $DEBUG
        # Display Useful information on how person using script can fix Error
        print "Error in Battle Target Anyone Script\n\n",
              "You need to put \"", TARGET_ANYONE_TAG, "\" in your Database!\n\n",
              "Press the F9 key to open the Database, then click on your\n",
              "\"System\" Tab (it is the one on the Right), then under\n",
              "the \"Element Names\" list, click \"Change Maximum\" and\n",
              "increase the \"Max\" by One.  Click OK.  Then in the \"Element\n",
              "Names\" list, scroll to the Bottom and select the Last Element.\n",
              "In the Box below the \"Element Names\" list, put \"",
              TARGET_ANYONE_TAG, "\" in\n",
              "the Box and Click OK.\n\n",
              "If you've already done this, CHECK YOUR SPELLING. Tag Names\n",
              "are CASE SENSITIVE, and don't use \"Quotes\" in the Box."
      else
        # Not a New Property, here, we are adding Values to an Existing Element
        add_exclusion_elements(target_anyone_id)
      end
    end
  end
# Exclusion Elements Script Not Defined
else
  #-------------------------------------------------------------------------
  # Class Game Battler
  #-------------------------------------------------------------------------
  class Game_Battler
    #--------------------------------------------------------------------------
    # * Calculating Element Correction
    #     element_set : element
    #     yes, this could have been aliased
    #--------------------------------------------------------------------------
    def elements_correct(element_set)
      # Important! - Remove Reference to $data so $data is not altered
      element_set = element_set.clone
      # Remove any Excluded Elements from the element_set arg array
      for i in element_set
        if i == $data_system.elements.index(TARGET_ANYONE_TAG)       
          element_set.delete(i)
        end
      end
      # If not an element
      if element_set == []
        # Return 100
        return 100
      end
      # Return the weakest object among the elements given
      # * "element_rate" method is defined by Game_Actor and Game_Enemy classes,
      #    which inherit from this class.
      weakest = -100
      for i in element_set
        # Element with the Highest Rate means it is the Weakest         
        weakest = [weakest, self.element_rate(i)].max
      end
      return weakest
    end
  end
end



#-------------------------------------------------------------------------
# Class Scene Battle
#-------------------------------------------------------------------------
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : skill selection)
  #--------------------------------------------------------------------------
  def update_phase3_skill_select
    # Make skill window visible
    @skill_window.visible = true
    # Update skill window
    @skill_window.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End skill selection
      end_skill_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the skill window
      @skill = @skill_window.skill
      # If it can't be used
      if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.skill_id = @skill.id
      # Make skill window invisible
      @skill_window.visible = false
      # Get Index from $data       
      index_anyone = $data_system.elements.index(TARGET_ANYONE_TAG)
      # If effect scope is single enemy or single ally and can target anyone
      if @skill.element_set.include?(index_anyone) and
         (@skill.scope == 1 or @skill.scope == 3 or @skill.scope == 5)
        # Define starting position of the arrow
        @orig_scope = @skill.scope
        start_enemy_select if @skill.scope == 1
        start_actor_select if @skill.scope == 3 or @skill.scope == 5
        @any_target = true
      elsif @skill.scope == 1 
        # Start enemy selection
        start_enemy_select
      # If effect scope is single ally
      elsif @skill.scope == 3 or @skill.scope == 5
        # Start actor selection
        start_actor_select
      # If scope is all enemies or allies
      elsif [2,4].include?(@skill.scope)
        start_select_all(@skill.scope)
        @any_target = true if @skill.element_set.include?(index_anyone)
      # If effect scope is not single
      else
        # End skill selection
        end_skill_select
        # Go to command input for next actor
        phase3_next_actor
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : item selection)
  #--------------------------------------------------------------------------
  def update_phase3_item_select
    # Make item window visible
    @item_window.visible = true
    # Update item window
    @item_window.update
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End item selection
      end_item_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      @item = @item_window.item
      # If it can't be used
      unless $game_party.item_can_use?(@item.id)
        # Play buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.item_id = @item.id
      # Make item window invisible
      @item_window.visible = false
      # Get Index from $data       
      index_anyone = $data_system.elements.index(TARGET_ANYONE_TAG)
      # If effect scope is single enemy or single ally and can target anyone
      if @item.element_set.include?(index_anyone) and
      (@item.scope == 1 or @item.scope == 3 or @item.scope == 5)
        # Define starting position of the arrow
        @orig_scope = @item.scope
        start_enemy_select if @item.scope == 1
        start_actor_select if @item.scope == 3 or @item.scope == 5
        @any_target = true
      # If effect scope is single enemy
      elsif @item.scope == 1 
        # Start enemy selection
        start_enemy_select
      # If effect scope is single ally
      elsif @item.scope == 3 or @item.scope == 5
        # Start actor selection
        start_actor_select
      # If scope is all enemies or allies
      elsif [2,4].include?(@item.scope)
        start_select_all(@item.scope)
        @any_target = true if @item.element_set.include?(index_anyone)
      # If effect scope is not single
      else
        # End item selection
        end_item_select
        # Go to command input for next actor
        phase3_next_actor
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : enemy selection)
  #--------------------------------------------------------------------------
  def update_phase3_enemy_select
    # Update enemy arrow
    @enemy_arrow.update
    # If this skill/item can target anyone
    if @any_target == true
      # If player pressed the key to change targets
      if Input.trigger?(Input::DOWN)
        # Play decision SE
        $game_system.se_play($data_system.cursor_se)
        # Initialize actor select, end enemy select
        end_enemy_select
        if [2,4].include?(@skill_window != nil ? @skill.scope : @item.scope)
          start_select_all(4)
        else
          start_actor_select
        end
        @active_battler.changed_scope = !@active_battler.changed_scope
        # Stop processing
        return
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End enemy selection
      end_enemy_select
      @active_battler.changed_scope = false     
      @any_target = false
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @enemy_arrow.index
      # End enemy selection
      end_enemy_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      @any_target = false
      # Go to command input for next actor
      phase3_next_actor
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (actor command phase : actor selection)
  #--------------------------------------------------------------------------
  def update_phase3_actor_select
    # Update actor arrow
    @actor_arrow.update
    # If this skill/item can target anyone
    if @any_target == true
      # If player pressed the key to change targets
      if Input.trigger?(Input::UP)
        # Play decision SE
        $game_system.se_play($data_system.cursor_se)
        # Initialize actor select, end enemy select
        end_actor_select
        if [2,4].include?(@skill_window != nil ? @skill.scope : @item.scope)
          start_select_all(2)
        else
          start_enemy_select
        end
        @active_battler.changed_scope = !@active_battler.changed_scope
        # Stop processing
        return
      end
    end
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End actor selection
      end_actor_select
      @active_battler.changed_scope = false     
      @any_target = false
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Set action
      @active_battler.current_action.target_index = @actor_arrow.index
      # End actor selection
      end_actor_select
      # If skill window is showing
      if @skill_window != nil
        # End skill selection
        end_skill_select
      end
      # If item window is showing
      if @item_window != nil
        # End item selection
        end_item_select
      end
      @any_target = false
      # Go to command input for next actor
      phase3_next_actor
    end
  end
  #--------------------------------------------------------------------------
  # * Set Targeted Battler for Skill or Item
  #     scope : effect scope for skill or item
  #--------------------------------------------------------------------------
  alias modded_scopes_change_targets set_target_battlers
  def set_target_battlers(scope)
    # If the actor has changed the scope of the skill/item
    if @active_battler.is_a?(Game_Actor) and @active_battler.changed_scope
      # Reset the variable
      @active_battler.changed_scope = false
      # Determine targets
      case scope
      when 1 # single ally
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_party.smooth_target_actor(index))
      when 2 # allies
        for actor in $game_party.actors
          if actor.exist?
            @target_battlers.push(actor)
          end
        end
      when 3 # single enemy
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_troop.smooth_target_enemy(index))
      when 4 # troop
        for enemy in $game_troop.enemies
          if enemy.exist?
            @target_battlers.push(enemy)
          end
        end
      when 5 # single enemy (changed from single ally 0hp)
        index = @active_battler.current_action.target_index
        @target_battlers.push($game_troop.smooth_target_enemy(index))           
      end
    else
      # Call original method
      modded_scopes_change_targets(scope)
    end
  end
  #--------------------------------------------------------------------------
  # * Battle Ends
  #     result : results (0:win 1:lose 2:escape)
  #--------------------------------------------------------------------------
  alias reset_changed_scopes battle_end
  def battle_end(result)
    # Reset all the actors' changed_scope variable
    for actor in $game_party.actors
      actor.changed_scope = false
    end
    # Call alias
    reset_changed_scopes(result)
  end
end


#==============================================================================
# ** Arrow_Base
#------------------------------------------------------------------------------
#  This sprite is used as an arrow cursor for the battle screen. This class
#  is used as a superclass for the Arrow_Enemy and Arrow_Actor classes.
#==============================================================================

class Arrow_Base < Sprite
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor   :target_all                    # Cursor Targets All
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     viewport : viewport
  #--------------------------------------------------------------------------
  alias arrow_all_initialize initialize
  def initialize(viewport)
    # Call Original
    arrow_all_initialize(viewport)
    # New Variable
    @target_all = false
  end
end

#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Start All Selection
  #--------------------------------------------------------------------------
  def start_select_all(scope)
    # If Scope is All Enemies
    if scope == 2
      # Make enemy arrow
      @enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
      # Hide Arrow during Select All
      #@enemy_arrow.visible = false     
      # Cycle Arrow over each Enemy     
      @enemy_arrow.target_all = true
      # Associate help window
      @enemy_arrow.help_window = @help_window
      # Disable actor command window
      @actor_command_window.active = false
      @actor_command_window.visible = false 
    # IF Scope is All Allies
    elsif scope == 4
      # Make actor arrow
      @actor_arrow = Arrow_Actor.new(@spriteset.viewport_actor_arrow)
      # Hide Arrow during Select All
      #@actor_arrow.visible = false
      # Cycle Arrow over each Enemy
      @actor_arrow.target_all = true
      # Associate help window
      @actor_arrow.help_window = @help_window
      # Disable actor command window
      @actor_command_window.active = false
      @actor_command_window.visible = false
    end
  end 
end

# This flashes Index over each Battler in Group

#==============================================================================
# ** Arrow_Actor
#------------------------------------------------------------------------------
#  This arrow cursor is used to choose an actor. This class inherits from the
#  Arrow_Base class.
#==============================================================================

class Arrow_Actor < Arrow_Base
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If Entire Party
    if @target_all
      @index += 1
      @index %= $game_party.actors.size
      # Set sprite coordinates
      if self.actor != nil
        self.x = self.actor.screen_x
        self.y = self.actor.screen_y
      end
      # Prevent Input
      return
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      @index += 1
      @index %= $game_party.actors.size
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      @index += $game_party.actors.size - 1
      @index %= $game_party.actors.size
    end
    # Set sprite coordinates
    if self.actor != nil
      self.x = self.actor.screen_x
      self.y = self.actor.screen_y
    end
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    # If targetting All Allies
    if @target_all
      # Display Entire Party in Help Window, 1 = Center
      @help_window.set_text("All Allies", 1)
    else
      # Display actor status in help window
      @help_window.set_actor(self.actor)
    end
  end
end

#==============================================================================
# ** Arrow_Enemy
#------------------------------------------------------------------------------
#  This arrow cursor is used to choose enemies. This class inherits from the
#  Arrow_Base class.
#==============================================================================

class Arrow_Enemy < Arrow_Base
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If All Enemies
    if @target_all
      @index += 1
      @index %= $game_troop.enemies.size
      # Skip if indicating a nonexistant enemy
      $game_troop.enemies.size.times do
        break if self.enemy.exist?       
        @index += 1
        @index %= $game_troop.enemies.size
      end     
      # Set sprite coordinates
      if self.enemy != nil
        self.x = self.enemy.screen_x
        self.y = self.enemy.screen_y
      end
      # Prevent Input
      return
    end
   
    # Skip if indicating a nonexistant enemy
    $game_troop.enemies.size.times do
      break if self.enemy.exist?
      @index += 1
      @index %= $game_troop.enemies.size
    end
    # Cursor right
    if Input.repeat?(Input::RIGHT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index += 1
        @index %= $game_troop.enemies.size
        break if self.enemy.exist?
      end
    end
    # Cursor left
    if Input.repeat?(Input::LEFT)
      $game_system.se_play($data_system.cursor_se)
      $game_troop.enemies.size.times do
        @index += $game_troop.enemies.size - 1
        @index %= $game_troop.enemies.size
        break if self.enemy.exist?
      end
    end
    # Set sprite coordinates
    if self.enemy != nil
      self.x = self.enemy.screen_x
      self.y = self.enemy.screen_y
    end
  end
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    # If targetting All Enemies
    if @target_all
      # Display Entire Party in Help Window, 1 = Center
      @help_window.set_text("All Enemies", 1)
    else   
      # Display enemy name and state in the help window
      @help_window.set_enemy(self.enemy)
    end
  end
end



Credits and Thanks


  • KK20




Author's Notes

When you install this script and go to test it, be sure to START A NEW GAME.  If you don't, the data created on a New Game wont be available and will cause a Crash.  So be sure to start a New Game after installation and any other configurations.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

if you do it like this, the game won't crash even if you didn't start up from new game

Spoiler: ShowHide
Quote
class Game_System
=begin
  #----------------------------------------------------------------------------
  # * Public Instance Variables
  #----------------------------------------------------------------------------
  attr_reader :exclusion_elements       # Array of Element ID's for Excluding
  #----------------------------------------------------------------------------
  # * Object Initialization
  #----------------------------------------------------------------------------
  alias battler_elements_correct_initialize initialize
  def initialize
    # Call Original or any other Aliases
    battler_elements_correct_initialize
    # New Property - Elements to Exclude during calculation of Weakest
    @exclusion_elements = []
  end
=end # Not Necessary

  #----------------------------------------------------------------------------
  # * exclusion_elements 
  #----------------------------------------------------------------------------

  def exclusion_elements
    @exclusion_elements ||= []
  end
  #----------------------------------------------------------------------------
  # * Add Exclusion Elements - Allows Error Checking
  #----------------------------------------------------------------------------

  def add_exclusion_elements(element_id)
    # If ID already exists in the Array
    # if @exclusion_elements.include?(element_id)

    if exclusion_elements.include?(element_id) # delete the @
       ...
    end
  end
end


Heretic86

Riddle me this:

That script doesnt do anything if there are no other scripts that are dependant on it.  How would you suggest the other scripters handle it when their script needs an exclusion element?  Check it every time the array is checked?  Or insert the element id on init?  On init would require starting a new game for that to be called correctly.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

LiTTleDRAgo

I believe the instruction hasn't changed at all

Spoiler: ShowHide
  #----------------------------------------------------------------------------
 # * exclusion_elements
 #----------------------------------------------------------------------------
 def exclusion_elements
   # Everytime this method is accessed, if @exclusion_elements is nil or false,
   # change @exclusion_elements to empty array ([])
   @exclusion_elements ||= []
 end
 #----------------------------------------------------------------------------
 # * Add Exclusion Elements - Allows Error Checking
 #----------------------------------------------------------------------------
 def add_exclusion_elements(element_id)
   # If ID already exists in the Array
   if exclusion_elements.include?(element_id) # delete the @


that code above only create @exclusion_elements to [] if equal nil or false, else will return @exclusion_elements itself

in other words, you don't have to add @exclusion_elements = [] into Game_System#initialize, and when the script is called from old save game, @exclusion_elements will not return nil and the game won't crash

PS : sorry if my engrish is horrible, it's not my primary language



edit : forgot to notice it, of course if some dependant script is inserted in old save game, it needs to restarted from new game to take effect,
to fix that, just alias def exclusion_elements at that dependant script, like this :

Spoiler: ShowHide
class Game_System
 #----------------------------------------------------------------------------
 # * exclusion_elements
 #----------------------------------------------------------------------------
 alias_method :exclusion_elements_before_01, :exclusion_elements
 def exclusion_elements(*args)  
   # Call original method, just in case added *args if something unforeseen is occured
   exclusion_elements_before_01(*args)
   # Get Element ID from Data System
   id = $data_system.elements.index(TARGET_ANYONE_TAG)
   # Add element_id to @exclusion_elements if not exist
   add_exclusion_elements(id) if !id.nil? && !@exclusion_elements.include?(id)
   # Return @exclusion_elements to avoid error
   @exclusion_elements
 end
end


with that, script will work even though script is inserted in midway games

Heretic86

Quote from: LiTTleDRAgo on September 08, 2013, 09:40:39 am...

edit : forgot to notice it, of course if some dependant script is inserted in old save game, it needs to restarted from new game to take effect,

...


Exactly.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

orochii

Ummm, forgive me if I'm doing some sacrileges, but is this bad?
$exclusion_elements = []

class Game_Battler
 alias asdf_elements_correct elements_correct unless $@ #Edit: Forgot this, to fix the F12 issue.
 def elements_correct(element_set)
   #Forget about all exception elements! Moddaduke.
   element_set = element_set.clone
   for i in $exclusion_elements
     element_set.delete(i)
   end
   asdf_elements_correct(element_set)
 end
end


I'm learnin' so please don't castrate me,
Orochii Zouveleki

Heretic86

Youre learnin so its fine.  I still am too.

I put the variable inside $game_system because declaring it as a Global wont work with Save Games.  Globals all disappear once a game has been closed.  Globals like $game_system are saved when you save a game, but others like $foo wont be saved once the Game exits out, but will survive normal F12 resets.  Aliasing looks just fine by the way.  The original definition I had was modified in such a way that a redefinition was required, but your version on aliasing should work just fine as well, excluding the global.

If you have a script for an exclusion element, use $game_system.add_exclusion_element(element_id) as an Init somewhere for this particular script.  It does the same thing as Push cuz its just an array, but that definition adds some error checking in so that people who use our scripts together can have an easier time of things when there are elements they need to put into their database.
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)