Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Mod to Seph's Battle Switch

I'm not quite sure how difficult this would be but I was wondering if someone could make some modifications to Seph's In Battle Party Switch:

Code:
#==============================================================================
# ** Battle Switching
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2
# 2007-02-14
# SDK : Version 2.0, Parts 1, 3 & 4
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (??????????)
#   Version 2 ---------------------------------------------------- (2007-02-14)
#    - Update : Rescripted Entire System.
#------------------------------------------------------------------------------
# * Requirements :
#
#   Party Switcher
#   Method & Class Library 2.0 +
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to allow your party to be able to switch actors
#   in the middle of battle. Switching takes place with the rest of the actions
#   in phase 4 of the battle.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To customize Battle Switcher options, refer to customization.
#   To see a list of possible switchable options, refer to syntax.
#------------------------------------------------------------------------------
# * Customization :
#
#   Disable Switches : When Switches are on (true) the actors cannot use
#   the switch command
#    - DisableSwitch = { actor_id => [switch_id, ...], ... }
#
#   Disable Switches Default (When these switches are on (true), all non-
#   defined actors will use this array
#    - DisableSwitch.default = [switch_id, ...]
#
#   Actors That Can Use the Switch Command By Default
#    - Actors_That_Can_Switch_BD = [actor_id, ...] (0 for all actors)
#
#   Actors That Can By Switched By Default
#    - Actors_That_Can_Be_Switched_BD = [actor_id, ...] (0 for all actors)
#
#   Show Picture Type (0 : None, 1 : Battler, 2 : Non-Animated Sprite, 
#                      3 : Animated Sprite, 4 : Face)
#    - Show_Picture_Type = 0 - 4
#
#   Switch Out Animation
#    - Switch_Out_Animation_ID = { actor_id => id }
#
#   Default Switch Out Animation
#    - Switch_Out_Animation_ID.default = id
#   
#   Switch In Animation
#    - Switch_Out_Animation_ID = { actor_id => id }
#
#   Default Switch In Animation
#    - Switch_Out_Animation_ID.default = id
#   
#   Switch Commands By Actor
#    - ::SDK ... ::Switch = { actor_id => 'Switch Word', ... }
#
#   Switch Command By Actor (Default for all non-defined)
#    - ::SDK ... ::Switch.default = 'Switch Word'
#------------------------------------------------------------------------------
# * Syntax :
#
#   Change Ability to Use Switch Command in Battle
#    - <game_actor>.can_switch_in_battle
#
#   Change Ability to Be Switched in Battle
#    - <game_actor>.can_be_switched_in_battle
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Battle Switching', 'SephirothSpawn', 2, '2007-02-14')
SDK.check_requirements(2, [1, 3, 4], 
  {'Method & Class Library' => 2, 'Party Switcher +' => 1.2})

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Battle Switching')
  
#==============================================================================
# ** BattleSwitcher
#==============================================================================

module BattleSwitcher
  #--------------------------------------------------------------------------
  # * Options
  #
  #   Disable Switches : When Switches are on (true) the actors cannot use
  #   the switch command
  #    - DisableSwitch = { actor_id => [switch_id, ...], ... }
  #
  #   Disable Switches Default (When these switches are on (true), all non-
  #   defined actors will use this array
  #    - DisableSwitch.default = [switch_id, ...]
  #
  #   Actors That Can Use the Switch Command By Default
  #    - Actors_That_Can_Switch_BD = [actor_id, ...] (0 for all actors)
  #
  #   Actors That Can By Switched By Default
  #    - Actors_That_Can_Be_Switched_BD = [actor_id, ...] (0 for all actors)
  #
  #   Show Picture Type (0 : None, 1 : Battler, 2 : Non-Animated Sprite, 
  #                      3 : Animated Sprite, 4 : Face)
  #    - Show_Picture_Type = 0 - 4
  #
  #   Switch Out Animation
  #    - Switch_Out_Animation_ID = { actor_id => id }
  #
  #   Default Switch Out Animation
  #    - Switch_Out_Animation_ID.default = id
  #   
  #   Switch In Animation
  #    - Switch_Out_Animation_ID = { actor_id => id }
  #
  #   Default Switch In Animation
  #    - Switch_Out_Animation_ID.default = id
  #   
  #   Switch Commands By Actor
  #    - ::SDK ... ::Switch = { actor_id => 'Switch Word', ... }
  #
  #   Switch Command By Actor (Default for all non-defined)
  #    - ::SDK ... ::Switch.default = 'Switch Word'
  #--------------------------------------------------------------------------
  DisableSwitch                     = {}
  DisableSwitch.default             = []
  Actors_That_Can_Switch_BD         = [1, 2, 3, 7]
  Actors_That_Can_Be_Switched_BD    = [0]
  Show_Picture_Type                 = 3
  Switch_Out_Animation_ID           = {}
  Switch_Out_Animation_ID.default   = 0
  Switch_In_Animation_ID            = {}
  Switch_In_Animation_ID.default    = 23
  ::SDK::Scene_Commands::Scene_Battle::Switch         = {2 => 'Exchange'}
  ::SDK::Scene_Commands::Scene_Battle::Switch.default = 'Switch'
end

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :can_switch_in_battle
  attr_accessor :can_be_switched_in_battle
  attr_accessor :being_switched_in_battle
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_battleswitching_gmactr_setup, :setup
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(actor_id)
    # Original Setup
    seph_battleswitching_gmactr_setup(actor_id)
    # Setup Battle Switching Variables
    can_switch    = BattleSwitcher::Actors_That_Can_Switch_BD
    can_be_switch = BattleSwitcher::Actors_That_Can_Be_Switched_BD
    @can_switch_in_battle      = can_switch.include?(actor_id) || 
                                 can_switch.include?(0)
    @can_be_switched_in_battle = can_be_switch.include?(actor_id) ||
                                 can_be_switch.include?(0)
    @being_switched_in_battle  = false
  end
  #--------------------------------------------------------------------------
  # * Can Use Switch Command?
  #--------------------------------------------------------------------------
  def can_switch_use_switch_in_battle?
    BattleSwitcher::DisableSwitch.each do |switch_id|
      return false if $game_switches[switch_id]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Switch Command Word
  #--------------------------------------------------------------------------
  def switch_command_word
    return SDK::Scene_Commands::Scene_Battle::Switch[@actor_id]
  end
end 

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Actors That Can Be Switched In Battle
  #--------------------------------------------------------------------------
  def actors_that_can_switch_in_battle
    actors = []
    for actor in @reserve_actors + @@global_reserve_actors
      if actor.can_be_switched_in_battle
        actors << actor unless actor.being_switched_in_battle
      end
    end
    return actors
  end
end

#==============================================================================
# ** Window_BattleSwitch
#==============================================================================

class Window_BattleSwitch < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Gets Reserve Actor Information
    @actors = $game_party.actors_that_can_switch_in_battle
    # Creates Window & Contents
    super(32, 96, 576, [32 + @actors.size * self.oh, 160].min)
    self.contents = Bitmap.new(width - 32, @actors.size * self.oh)
    @item_max = @actors.size
    self.opacity = 160
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return BattleSwitcher::Show_Picture_Type == 0 ? 32 : 64
  end
  #--------------------------------------------------------------------------
  # * Actor
  #--------------------------------------------------------------------------
  def actor(index = self.index)
    return @actors[index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    # Gets Actor Information
    actor = @actors[index]
    # Get Show Picture Type
    picture_type = BattleSwitcher::Show_Picture_Type
    # If None
    if picture_type == 0
      # Draw Actor Name, State, HP & SP
      draw_actor_name(actor, 4, index * oh)
      # Draw Actor Status
      draw_actor_state(actor, 128, index * oh)
      # Draw Actor HP
      draw_actor_hp(actor, 252, index * oh)
      # Draw Actor SP
      draw_actor_sp(actor, 400, index * oh)
    # If Draw Picture
    else
      # Branch By Graphic Type
      case picture_type
      when 1 # Battler
        dest_rect = Rect.new(0, index * 64 + 4, 56, 56)
        bitmap    = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
        self.contents.scale_blt(dest_rect, bitmap)
      when 2 # Non-Animated Sprite
        self.contents.draw_sprite(o, index * 64 + 4, 56, 56, 
          actor.character_name, actor.character_hue)
      when 3 # Animated Sprite
        self.contents.draw_anim_sprite(0, index * 64 + 4, 56, 56, 
          actor.character_name, actor.character_hue)
      end
      # Draw Actor Name, State, Level, Exp, HP & SP
      draw_actor_name(actor, 60, index * oh)
      draw_actor_state(actor, 60, index * oh + 32)
      draw_actor_level(actor, 184, index * oh)
      draw_actor_exp(actor, 184, index * oh + 32)
      draw_actor_hp(actor, 400, index * oh)
      draw_actor_sp(actor, 400, index * oh + 32)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If Animated Sprite
    if BattleSwitcher::Show_Picture_Type == 3
      # If Frame Reset
      if Graphics.frame_count % Bitmap::Anim_Sprite_Reset_Frames == 0
        # Draw Animated Sprite
        for i in 0...@actors.size
          actor = @actors[i]
          self.contents.draw_anim_sprite(0, i * 64 + 4, 56, 56, 
            actor.character_name, actor.character_hue)
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_btlswitch_scnbtl_p3scw,  :phase3_setup_command_window
  alias_method :seph_btlswitch_scnbtl_p3bci,  :phase3_basic_command_input
  alias_method :seph_btlswitch_scnbtl_up3,    :update_phase3
  alias_method :seph_btlswitch_scnbtl_p3bcd?, :phase3_basic_command_disabled?
  alias_method :seph_btlswitch_scnbtl_up4s2,  :update_phase4_step2
  alias_method :seph_btlswitch_scnbtl_up4s4,  :update_phase4_step4
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  def phase3_setup_command_window
    # Original Command Window Setup
    seph_btlswitch_scnbtl_p3scw
    # Gets Actor Information
    actor = $game_party.actors[@actor_index]
    # If Actor Can Switch
    if actor.can_switch_in_battle
      # If Switch Command Doesn't Exist
      if @seph_switch_command_is_set.nil?
        # Set Switch Command True
        @seph_switch_command_is_set = true
        # Set Switch Command Word
        @seph_switch_command_word = actor.switch_command_word
        # Get Window Commands
        commands = @actor_command_window.commands.dup
        # Insert Switch Command After Item
        index = commands.index(SDK::Scene_Commands::Scene_Battle::Item) + 1
        commands.insert(index, actor.switch_command_word)
        # Reset Command Window Commands
        @actor_command_window.commands = commands
      # If Switch Command Exist
      else
        # If Switch Word Is Changing
        unless @seph_switch_command_word == actor.switch_command_word
          # Get Window Commands
          commands = @actor_command_window.commands.dup
          # Replaces Existing Command Word
          index = commands.index(@seph_switch_command_word)
          commands[index] = actor.switch_command_word
          # Reset Command Window Commands
          @actor_command_window.commands = commands
          # Set Switch Command Word
          @seph_switch_command_word = actor.switch_command_word
        end
      end
    # If Actor Cannot Swith
    else
      # If Switch Command Does Exist
      unless @seph_switch_command_is_set.nil?
        # Get Window Commands
        commands = @actor_command_window.commands.dup
        # Delete Switch Command
        commands.delete(@seph_switch_command_word)
        # Reset Command Window Commands
        @actor_command_window.commands = commands
        # Erase Switch Command Flag
        @seph_switch_command_is_set = nil
        # Erase Switch Command Word
        @seph_switch_command_word = nil
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Phase 3
  #--------------------------------------------------------------------------
  def update_phase3
    # If Switch Window Exist
    unless @switch_window.nil?
      # Update Switch Select
      update_switch_select
      return
    end
    # Original Update Phase 3
    seph_btlswitch_scnbtl_up3
  end
  #--------------------------------------------------------------------------
  # * Phase 3 - Basic : Command Disabled? Test
  #--------------------------------------------------------------------------
  def phase3_basic_command_disabled?
    # If Command is Switch
    if @actor_command_window.command == @seph_switch_command_word
      # If Switch Disabled
      unless @active_battler.can_switch_use_switch_in_battle?
        # Return True
        return true
      end
      # If No Actors Selectable
      if $game_party.actors_that_can_switch_in_battle.size == 0
        return true
      end
    end
    # Return Previous Test
    return seph_btlswitch_scnbtl_p3bcd?
  end
  #--------------------------------------------------------------------------
  # * Phase 3 Basic : Command Input
  #--------------------------------------------------------------------------
  def phase3_basic_command_input
    # Original Command Input
    seph_btlswitch_scnbtl_p3bci
    # If Command is Switch
    if @actor_command_window.command == @seph_switch_command_word
      # Command Switch
      phase3_command_switch
    end
  end
  #--------------------------------------------------------------------------
  # * Phase 3 Basic : Command - Switch
  #--------------------------------------------------------------------------
  def phase3_command_switch
    # Set action
    @active_battler.current_action.kind = 'switching'
    # Start Switch Select
    start_switch_select
  end
  #--------------------------------------------------------------------------
  # * Update Switch Select
  #--------------------------------------------------------------------------
  def update_switch_select
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End Switch Select
      end_switch_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Gets Target
      actor = @switch_window.actor
      # Set Actor Switched Flag
      actor.being_switched_in_battle = true
      # Set Active Battler Action
      @active_battler.current_action.basic = actor.id
      # End switch selection
      end_switch_select
      # Go to command input for next actor
      phase3_next_actor
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Start Switch Select
  #--------------------------------------------------------------------------
  def start_switch_select
    # Turn Off Actor Command Window
    @actor_command_window.visible = false
    @actor_command_window.active  = false
    # Create Switch Window
    @switch_window = Window_BattleSwitch.new
  end
  #--------------------------------------------------------------------------
  # * End Switch Select
  #--------------------------------------------------------------------------
  def end_switch_select
    # Dispose Switch Window
    @switch_window.dispose
    @switch_window = nil
    # Turn On Actor Command Window
    @actor_command_window.visible = true
    @actor_command_window.active  = true
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 2 : start action)
  #--------------------------------------------------------------------------
  def update_phase4_step2
    # Original Phase 4 Setp 2
    seph_btlswitch_scnbtl_up4s2
    # Return if Step 1
    return if @phase4_step == 1
    # If Action is Switch
    if @active_battler.current_action.kind == 'switching'
      # Make Switch Action Result
      make_switch_action_result
    end
  end
  #--------------------------------------------------------------------------
  # * Make Switch Action Results
  #--------------------------------------------------------------------------
  def make_switch_action_result
    # Set Target
    actor = $game_actors[@active_battler.current_action.basic]
    @target_battlers = [actor]
    # Set Help Text
    text = "#{@active_battler.name} Switching For #{actor.name}..."
    @help_window.set_text(text, 1)
    # Set Animation IDS
    bs = BattleSwitcher
    @animation1_id = bs::Switch_Out_Animation_ID[@active_battler.id]
    @animation2_id = bs::Switch_In_Animation_ID[actor.id]
  end
  #--------------------------------------------------------------------------
  # * Frame Update Phase 4 Step 4
  #--------------------------------------------------------------------------
  def update_phase4_step4
    # If Action is Switch
    if @active_battler.current_action.kind == 'switching'
      # Switch Actors
      out = @active_battler
      inn = $game_actors[@active_battler.current_action.basic]
      $game_party.swap_actors(inn.id, out.id)
      @active_battler  = inn
      @target_battlers = [@active_battler]
      inn.being_switched_in_battle = false
    end
    # Original Phase 4 Step 4
    seph_btlswitch_scnbtl_up4s4
  end
end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

My issue with it is the way the exp is distributed. Right now as it stands it only gives exp to memeber's that finish the battle. So let's say you have Basil in the battle the entire time and then switch him out and defeat the boss, Basil gets 0 exp. (unless you have a party script that gives half to reserve members).

So I was wondering if someone could make it so that if a character performs a command in battle they earn exp. So even if they are switched out later they get the full amount like the ending party. Makes scence? And if this is amazingly hard (I'm not quite sure the dificulty of something like this) could someone let me know? Thanks so very much for any help at all.
 
Well, I am working on an Actions Exp system, where actions give you exp depending on the action itself (in case you would be interested in that).

But I can make something that can give a certain percent to any user that was in the battle, but not at the end.

* Adds of list of things to do *
 
Major necropost, but I did finally update your request.

Code:
#==============================================================================
# ** Battle Switching
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2.1
# 2007-07-29
# SDK : Version 2.0+, Parts I, III 7 IV
#------------------------------------------------------------------------------
# * Version History :
#
#   Version 1 ---------------------------------------------------- (??????????)
#   Version 2 ---------------------------------------------------- (2007-02-14)
#    - Update : Rescripted Entire System.
#    Version 2.1 ------------------------------------------------- (2007-07-29)
#     - Update : Added exp given to anyone who acts in battle
#------------------------------------------------------------------------------
# * Requirements :
#
#   Party Switcher
#   Method & Class Library (2.1+)
#------------------------------------------------------------------------------
# * Description :
#
#   This script was designed to allow your party to be able to switch actors
#   in the middle of battle. Switching takes place with the rest of the actions
#   in phase 4 of the battle.
#------------------------------------------------------------------------------
# * Instructions :
#
#   Place The Script Below the SDK and Above Main.
#   To customize Battle Switcher options, refer to customization.
#   To see a list of possible switchable options, refer to syntax.
#------------------------------------------------------------------------------
# * Customization :
#
#   Disable Switches : When Switches are on (true) the actors cannot use
#   the switch command
#    - DisableSwitch = { actor_id => [switch_id, ...], ... }
#
#   Disable Switches Default (When these switches are on (true), all non-
#   defined actors will use this array
#    - DisableSwitch.default = [switch_id, ...]
#
#   Actors That Can Use the Switch Command By Default
#    - Actors_That_Can_Switch_BD = [actor_id, ...] (0 for all actors)
#
#   Actors That Can By Switched By Default
#    - Actors_That_Can_Be_Switched_BD = [actor_id, ...] (0 for all actors)
#
#   Show Picture Type (0 : None, 1 : Battler, 2 : Non-Animated Sprite, 
#                      3 : Animated Sprite, 4 : Face)
#    - Show_Picture_Type = 0 - 4
#
#   Switch Out Animation
#    - Switch_Out_Animation_ID = { actor_id => id }
#
#   Default Switch Out Animation
#    - Switch_Out_Animation_ID.default = id
#   
#   Switch In Animation
#    - Switch_Out_Animation_ID = { actor_id => id }
#
#   Default Switch In Animation
#    - Switch_Out_Animation_ID.default = id
#   
#   Switch Commands By Actor
#    - ::SDK ... ::Switch = { actor_id => 'Switch Word', ... }
#
#   Switch Command By Actor (Default for all non-defined)
#    - ::SDK ... ::Switch.default = 'Switch Word'
#------------------------------------------------------------------------------
# * Syntax :
#
#   Change Ability to Use Switch Command in Battle
#    - <game_actor>.can_switch_in_battle
#
#   Change Ability to Be Switched in Battle
#    - <game_actor>.can_be_switched_in_battle
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Battle Switching', 'SephirothSpawn', 2.1, '2007-07-29')
SDK.check_requirements(2.0, [3, 4], 
  {'Method & Class Library' => 2.1, 'Party Switcher +' => 1.2})

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Battle Switching')
  
#==============================================================================
# ** BattleSwitcher
#==============================================================================

module BattleSwitcher
  #--------------------------------------------------------------------------
  # * Options
  #
  #   Disable Switches : When Switches are on (true) the actors cannot use
  #   the switch command
  #    - DisableSwitch = { actor_id => [switch_id, ...], ... }
  #
  #   Disable Switches Default (When these switches are on (true), all non-
  #   defined actors will use this array
  #    - DisableSwitch.default = [switch_id, ...]
  #
  #   Actors That Can Use the Switch Command By Default
  #    - Actors_That_Can_Switch_BD = [actor_id, ...] (0 for all actors)
  #
  #   Actors That Can By Switched By Default
  #    - Actors_That_Can_Be_Switched_BD = [actor_id, ...] (0 for all actors)
  #
  #   Show Picture Type (0 : None, 1 : Battler, 2 : Non-Animated Sprite, 
  #                      3 : Animated Sprite, 4 : Face)
  #    - Show_Picture_Type = 0 - 4
  #
  #   Switch Out Animation
  #    - Switch_Out_Animation_ID = { actor_id => id }
  #
  #   Default Switch Out Animation
  #    - Switch_Out_Animation_ID.default = id
  #   
  #   Switch In Animation
  #    - Switch_Out_Animation_ID = { actor_id => id }
  #
  #   Default Switch In Animation
  #    - Switch_Out_Animation_ID.default = id
  #   
  #   Switch Commands By Actor
  #    - ::SDK ... ::Switch = { actor_id => 'Switch Word', ... }
  #
  #   Switch Command By Actor (Default for all non-defined)
  #    - ::SDK ... ::Switch.default = 'Switch Word'
  #--------------------------------------------------------------------------
  DisableSwitch                     = {}
  DisableSwitch.default             = []
  Actors_That_Can_Switch_BD         = [1, 2, 3, 7]
  Actors_That_Can_Be_Switched_BD    = [0]
  Show_Picture_Type                 = 3
  Switch_Out_Animation_ID           = {}
  Switch_Out_Animation_ID.default   = 0
  Switch_In_Animation_ID            = {}
  Switch_In_Animation_ID.default    = 23
  ::SDK::Scene_Commands::Scene_Battle::Switch         = {2 => 'Exchange'}
  ::SDK::Scene_Commands::Scene_Battle::Switch.default = 'Switch'
end

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :can_switch_in_battle
  attr_accessor :can_be_switched_in_battle
  attr_accessor :being_switched_in_battle
  attr_accessor :acted_in_battle
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_battleswitching_gmactr_setup, :setup
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(actor_id)
    # Original Setup
    seph_battleswitching_gmactr_setup(actor_id)
    # Setup Battle Switching Variables
    can_switch    = BattleSwitcher::Actors_That_Can_Switch_BD
    can_be_switch = BattleSwitcher::Actors_That_Can_Be_Switched_BD
    @can_switch_in_battle      = can_switch.include?(actor_id) || 
                                 can_switch.include?(0)
    @can_be_switched_in_battle = can_be_switch.include?(actor_id) ||
                                 can_be_switch.include?(0)
    @being_switched_in_battle  = false
    @acted_in_battle           = false
  end
  #--------------------------------------------------------------------------
  # * Can Use Switch Command?
  #--------------------------------------------------------------------------
  def can_switch_use_switch_in_battle?
    BattleSwitcher::DisableSwitch.each do |switch_id|
      return false if $game_switches[switch_id]
    end
    return true
  end
  #--------------------------------------------------------------------------
  # * Switch Command Word
  #--------------------------------------------------------------------------
  def switch_command_word
    return SDK::Scene_Commands::Scene_Battle::Switch[@actor_id]
  end
end 

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Actors That Can Be Switched In Battle
  #--------------------------------------------------------------------------
  def actors_that_can_switch_in_battle
    actors = []
    for actor in @reserve_actors + @@global_reserve_actors
      if actor.can_be_switched_in_battle
        actors << actor unless actor.being_switched_in_battle
      end
    end
    return actors
  end
end

#==============================================================================
# ** Window_BattleResult
#==============================================================================

class Window_BattleResult < Window_Base
  attr_reader :exp
end

#==============================================================================
# ** Window_BattleSwitch
#==============================================================================

class Window_BattleSwitch < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    # Gets Reserve Actor Information
    @actors = $game_party.actors_that_can_switch_in_battle
    # Creates Window & Contents
    super(32, 96, 576, [32 + @actors.size * self.oh, 160].min)
    self.contents = Bitmap.new(width - 32, @actors.size * self.oh)
    @item_max = @actors.size
    self.opacity = 160
    self.index = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Oh
  #--------------------------------------------------------------------------
  def oh
    return BattleSwitcher::Show_Picture_Type == 0 ? 32 : 64
  end
  #--------------------------------------------------------------------------
  # * Actor
  #--------------------------------------------------------------------------
  def actor(index = self.index)
    return @actors[index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    for i in 0...@item_max
      draw_item(i)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    # Gets Actor Information
    actor = @actors[index]
    # Get Show Picture Type
    picture_type = BattleSwitcher::Show_Picture_Type
    # If None
    if picture_type == 0
      # Draw Actor Name, State, HP & SP
      draw_actor_name(actor, 4, index * oh)
      # Draw Actor Status
      draw_actor_state(actor, 128, index * oh)
      # Draw Actor HP
      draw_actor_hp(actor, 252, index * oh)
      # Draw Actor SP
      draw_actor_sp(actor, 400, index * oh)
    # If Draw Picture
    else
      # Branch By Graphic Type
      case picture_type
      when 1 # Battler
        dest_rect = Rect.new(0, index * 64 + 4, 56, 56)
        bitmap    = RPG::Cache.battler(actor.battler_name, actor.battler_hue)
        self.contents.scale_blt(dest_rect, bitmap)
      when 2 # Non-Animated Sprite
        self.contents.draw_sprite(o, index * 64 + 4, 56, 56, 
          actor.character_name, actor.character_hue)
      when 3 # Animated Sprite
        self.contents.draw_anim_sprite(0, index * 64 + 4, 56, 56, 
          actor.character_name, actor.character_hue)
      end
      # Draw Actor Name, State, Level, Exp, HP & SP
      draw_actor_name(actor, 60, index * oh)
      draw_actor_state(actor, 60, index * oh + 32)
      draw_actor_level(actor, 184, index * oh)
      draw_actor_exp(actor, 184, index * oh + 32)
      draw_actor_hp(actor, 400, index * oh)
      draw_actor_sp(actor, 400, index * oh + 32)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If Animated Sprite
    if BattleSwitcher::Show_Picture_Type == 3
      # If Frame Reset
      if Graphics.frame_count % Bitmap::Anim_Sprite_Reset_Frames == 0
        # Draw Animated Sprite
        for i in 0...@actors.size
          actor = @actors[i]
          self.contents.draw_anim_sprite(0, i * 64 + 4, 56, 56, 
            actor.character_name, actor.character_hue)
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias_method :seph_btlswitch_scnbtl_mv,     :main_variable
  alias_method :seph_btlswitch_scnbtl_p3scw,  :phase3_setup_command_window
  alias_method :seph_btlswitch_scnbtl_p3bci,  :phase3_basic_command_input
  alias_method :seph_btlswitch_scnbtl_up3,    :update_phase3
  alias_method :seph_btlswitch_scnbtl_p3bcd?, :phase3_basic_command_disabled?
  alias_method :seph_btlswitch_scnbtl_up4s2,  :update_phase4_step2
  alias_method :seph_btlswitch_scnbtl_up4s4,  :update_phase4_step4
  #--------------------------------------------------------------------------
  # * Main Processing : Variable Initialization
  #--------------------------------------------------------------------------
  def main_variable
    # Pass Through Actors
    for actor in $game_party.actors
      # Set Acted in battle true
      actor.acted_in_battle = true
    end
    # Pass Through Reserve Actors
    for actor in $game_party.reserve_actors
      # Set Acted in battle false
      actor.acted_in_battle = false
    end
    # Original Main Variable
    seph_btlswitch_scnbtl_mv
  end
  #--------------------------------------------------------------------------
  # * Actor Command Window Setup
  #--------------------------------------------------------------------------
  def phase3_setup_command_window
    # Original Command Window Setup
    seph_btlswitch_scnbtl_p3scw
    # Gets Actor Information
    actor = $game_party.actors[@actor_index]
    # If Actor Can Switch
    if actor.can_switch_in_battle
      # If Switch Command Doesn't Exist
      if @seph_switch_command_is_set.nil?
        # Set Switch Command True
        @seph_switch_command_is_set = true
        # Set Switch Command Word
        @seph_switch_command_word = actor.switch_command_word
        # Get Window Commands
        commands = @actor_command_window.commands.dup
        # Insert Switch Command After Item
        index = commands.index(SDK::Scene_Commands::Scene_Battle::Item) + 1
        commands.insert(index, actor.switch_command_word)
        # Reset Command Window Commands
        @actor_command_window.commands = commands
      # If Switch Command Exist
      else
        # If Switch Word Is Changing
        unless @seph_switch_command_word == actor.switch_command_word
          # Get Window Commands
          commands = @actor_command_window.commands.dup
          # Replaces Existing Command Word
          index = commands.index(@seph_switch_command_word)
          commands[index] = actor.switch_command_word
          # Reset Command Window Commands
          @actor_command_window.commands = commands
          # Set Switch Command Word
          @seph_switch_command_word = actor.switch_command_word
        end
      end
    # If Actor Cannot Swith
    else
      # If Switch Command Does Exist
      unless @seph_switch_command_is_set.nil?
        # Get Window Commands
        commands = @actor_command_window.commands.dup
        # Delete Switch Command
        commands.delete(@seph_switch_command_word)
        # Reset Command Window Commands
        @actor_command_window.commands = commands
        # Erase Switch Command Flag
        @seph_switch_command_is_set = nil
        # Erase Switch Command Word
        @seph_switch_command_word = nil
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update : Phase 3
  #--------------------------------------------------------------------------
  def update_phase3
    # If Switch Window Exist
    unless @switch_window.nil?
      # Update Switch Select
      update_switch_select
      return
    end
    # Original Update Phase 3
    seph_btlswitch_scnbtl_up3
  end
  #--------------------------------------------------------------------------
  # * Phase 3 - Basic : Command Disabled? Test
  #--------------------------------------------------------------------------
  def phase3_basic_command_disabled?
    # If Command is Switch
    if @actor_command_window.command == @seph_switch_command_word
      # If Switch Disabled
      unless @active_battler.can_switch_use_switch_in_battle?
        # Return True
        return true
      end
      # If No Actors Selectable
      if $game_party.actors_that_can_switch_in_battle.size == 0
        return true
      end
    end
    # Return Previous Test
    return seph_btlswitch_scnbtl_p3bcd?
  end
  #--------------------------------------------------------------------------
  # * Phase 3 Basic : Command Input
  #--------------------------------------------------------------------------
  def phase3_basic_command_input
    # Original Command Input
    seph_btlswitch_scnbtl_p3bci
    # If Command is Switch
    if @actor_command_window.command == @seph_switch_command_word
      # Command Switch
      phase3_command_switch
    end
  end
  #--------------------------------------------------------------------------
  # * Phase 3 Basic : Command - Switch
  #--------------------------------------------------------------------------
  def phase3_command_switch
    # Set action
    @active_battler.current_action.kind = 'switching'
    # Start Switch Select
    start_switch_select
  end
  #--------------------------------------------------------------------------
  # * Update Switch Select
  #--------------------------------------------------------------------------
  def update_switch_select
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # End Switch Select
      end_switch_select
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # Gets Target
      actor = @switch_window.actor
      # Set Actor Switched Flag
      actor.being_switched_in_battle = true
      # Set Active Battler Action
      @active_battler.current_action.basic = actor.id
      # End switch selection
      end_switch_select
      # Go to command input for next actor
      phase3_next_actor
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Start Switch Select
  #--------------------------------------------------------------------------
  def start_switch_select
    # Turn Off Actor Command Window
    @actor_command_window.visible = false
    @actor_command_window.active  = false
    # Create Switch Window
    @switch_window = Window_BattleSwitch.new
  end
  #--------------------------------------------------------------------------
  # * End Switch Select
  #--------------------------------------------------------------------------
  def end_switch_select
    # Dispose Switch Window
    @switch_window.dispose
    @switch_window = nil
    # Turn On Actor Command Window
    @actor_command_window.visible = true
    @actor_command_window.active  = true
  end
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 2 : start action)
  #--------------------------------------------------------------------------
  def update_phase4_step2
    # Original Phase 4 Setp 2
    seph_btlswitch_scnbtl_up4s2
    # Return if Step 1
    return if @phase4_step == 1
    # If Action is Switch
    if @active_battler.current_action.kind == 'switching'
      # Make Switch Action Result
      make_switch_action_result
    end
  end
  #--------------------------------------------------------------------------
  # * Make Switch Action Results
  #--------------------------------------------------------------------------
  def make_switch_action_result
    # Set Target
    actor = $game_actors[@active_battler.current_action.basic]
    @target_battlers = [actor]
    # Set Help Text
    text = "#{@active_battler.name} Switching For #{actor.name}..."
    @help_window.set_text(text, 1)
    # Set Animation IDS
    bs = BattleSwitcher
    @animation1_id = bs::Switch_Out_Animation_ID[@active_battler.id]
    @animation2_id = bs::Switch_In_Animation_ID[actor.id]
  end
  #--------------------------------------------------------------------------
  # * Frame Update Phase 4 Step 4
  #--------------------------------------------------------------------------
  def update_phase4_step4
    # If Action is Switch
    if @active_battler.current_action.kind == 'switching'
      # Switch Actors
      out = @active_battler
      inn = $game_actors[@active_battler.current_action.basic]
      $game_party.swap_actors(inn.id, out.id)
      @active_battler  = inn
      # Turn Acted in flag on
      @active_battler.acted_in_battle = true
      @target_battlers = [@active_battler]
      inn.being_switched_in_battle = false
    end
    # Original Phase 4 Step 4
    seph_btlswitch_scnbtl_up4s4
  end
  #--------------------------------------------------------------------------
  # * Start After Battle Phase
  #--------------------------------------------------------------------------
  def start_phase5
    # Original Start Phase 5
    seph_btlswitch_scnbtl_sp5
    # Pass Through Reserve Actors
    for actor in $game_party.reserve_actors
      # Gain Exp if Acted in battle
      if actor.acted_in_battle
        # Gain Exp
        @result_window.exp
      end
    end
  end
end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top