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.

Auto-Fight Party Command

Another question for the board: Aside from the standard "Fight/Run" commands for the initial battle, I would like to input an additional "Auto-Fight" command somehow. Is this something I will need to script, and if so, does anyone know if such a pre-made script exists? The command isn't necessary, but I would like to have a command where everyone just uses the regular "Fight" command (nothing special), so battles go by quickly without much effort.

Any help, as always, is appreciated. Thanks very much! :)
 
I wrote this a long time ago, but it sounds like it's pretty close to what you're looking for.

[rgss]#--------------------------------------------------------------------------
# * Auto Command
# A simple script that adds an auto command to the Party Command bar
# in the default battle system
# Created by Racheal of Dragonfly 02/22/07
#--------------------------------------------------------------------------
 
class Window_PartyCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 160
    @commands = ["Fight", "Auto", "Escape"]
    @item_max = 3
    @column_max = 3
    draw_item(0, normal_color)
    draw_item(1, normal_color)
    draw_item(2, $game_temp.battle_can_escape ? normal_color : disabled_color)
    self.active = false
    self.visible = false
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #  index : item number
  #  color : text character color
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(80 + index * 160 + 4, 0, 128 - 10, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], 1)
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    self.cursor_rect.set(80 + index * 160, 0, 128, 32)
  end
end
 
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Frame Update (party command phase)
  #--------------------------------------------------------------------------
  def update_phase2
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by party command window cursor position
      case @party_command_window.index
      when 0  # fight
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Start actor command phase
        start_phase3
      when 1  # auto
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Auto processing
        update_phase2_auto
      when 2  # escape
        # If it's not possible to escape
        if $game_temp.battle_can_escape == false
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Escape processing
        update_phase2_escape
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (party command phase: auto)
  #--------------------------------------------------------------------------
  def update_phase2_auto
    # Clear all party member actions
    $game_party.clear_actions
    for actor in $game_party.actors
      if actor.inputable?
        # Set action
        actor.current_action.kind = 0
        actor.current_action.basic = 0
        actor.current_action.decide_random_target_for_actor
      end
    end
    # Start main phase
    start_phase4
  end
end
[/rgss]
 
racheal this looks like what i need! :) i pasted it into the party command script, but when you select auto, it escapes from battle, and when you select escape, it doesnt do anything and the menu remains up. do you have any suggestions? thanks for your help so far :) good to know someone can help.

take care!
 
Did you paste it above or below Scene_Battle? It needs to go under Scene_Battle to work right. If that doesn't work, then it's most likely a script conflict. I'm pretty sure it's not compatible with SDK for example.
 
It turned out that I had the whole thing pasted in party_command, didnt realize it was two separate entries....then i had to remove the 'end' and the 'class_scene battle' to accomodate the pasting. It works great now :) Automates the party for one turn, just like I wanted!

I guess my only concern now is this: Is there a line of syntax that can allow the auto battle to continuously loop until a victory is achieved (or death), and is there a way to cancel the auto once it is put into effect? This isnt really necessary, but it would for allow for more control by the player.

THanks again for your help so far :) best wishes!
 
Not as extensively tested as I normally do, but here you go

[rgss]#--------------------------------------------------------------------------
# * Auto Command
# A simple script that adds an auto command to the Party Command bar
# in the default battle system
# Created by Racheal of Dragonfly 02/22/07
# Editted 05/14/09 to include continuous auto
#--------------------------------------------------------------------------
 
#--------------------------------------------------------------------------
# * Game Temp edit
#--------------------------------------------------------------------------
class Game_Temp
  alias old_initialize initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :auto_battle                  # flag for auto battle
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    old_initialize
    @auto_battle = false
  end
end
 
#--------------------------------------------------------------------------
# * Battle Spriteset edit
# * Change @auto.x and @auto.y to change the position of the auto icon
#--------------------------------------------------------------------------
class Spriteset_Battle
  alias old_initialize initialize
  alias old_update update
  alias old_dispose dispose
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @auto = Sprite.new
    @auto.bitmap = RPG::Cache.icon("auto")
    #Change the two lines below to change the position
    @auto.x = 5
    @auto.y = 5
    @auto.z = 400
    @auto.visible = $game_temp.auto_battle
    old_initialize
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  def dispose
    @auto.dispose
    old_dispose
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    @auto.visible = $game_temp.auto_battle
    old_update
  end
end
 
#--------------------------------------------------------------------------
# * Party Command Window edit
#--------------------------------------------------------------------------
class Window_PartyCommand < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.back_opacity = 160
    @commands = ["Fight", "Auto", "Escape"]
    @item_max = 3
    @column_max = 3
    draw_item(0, normal_color)
    draw_item(1, normal_color)
    draw_item(2, $game_temp.battle_can_escape ? normal_color : disabled_color)
    self.active = false
    self.visible = false
    self.index = 0
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #  index : item number
  #  color : text character color
  #--------------------------------------------------------------------------
  def draw_item(index, color)
    self.contents.font.color = color
    rect = Rect.new(80 + index * 160 + 4, 0, 128 - 10, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    self.contents.draw_text(rect, @commands[index], 1)
  end
  #--------------------------------------------------------------------------
  # * Cursor Rectangle Update
  #--------------------------------------------------------------------------
  def update_cursor_rect
    self.cursor_rect.set(80 + index * 160, 0, 128, 32)
  end
end
 
#--------------------------------------------------------------------------
# * Scene Battle edit
#--------------------------------------------------------------------------
class Scene_Battle
  alias old_end battle_end
  alias old_update update
  alias old_start2 start_phase2
  #--------------------------------------------------------------------------
  # * Battle Ends
  #     result : results (0:win 1:lose 2:escape)
  #--------------------------------------------------------------------------
  def battle_end(result)
    # Cancels auto after battle is complete
    $game_temp.auto_battle = false
    old_end(result)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Cancel auto with the cancel button
    if Input.trigger?(Input::B)
      $game_temp.auto_battle = false
    end
    old_update
  end
  #--------------------------------------------------------------------------
  # * Start Party Command Phase
  #--------------------------------------------------------------------------
  def start_phase2
    old_start2
    # Auto process if auto in effect
    if $game_temp.auto_battle
      update_phase2_auto
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (party command phase)
  #--------------------------------------------------------------------------
  def update_phase2
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Branch by party command window cursor position
      case @party_command_window.index
      when 0  # fight
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Start actor command phase
        start_phase3
      when 1  # auto
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Auto processing
        $game_temp.auto_battle = true
        update_phase2_auto
      when 2  # escape
        # If it's not possible to escape
        if $game_temp.battle_can_escape == false
          # Play buzzer SE
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        # Play decision SE
        $game_system.se_play($data_system.decision_se)
        # Escape processing
        update_phase2_escape
      end
      return
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (party command phase: auto)
  #--------------------------------------------------------------------------
  def update_phase2_auto
    # Clear all party member actions
    $game_party.clear_actions
    for actor in $game_party.actors
      if actor.inputable?
        # Set action
        actor.current_action.kind = 0
        actor.current_action.basic = 0
        actor.current_action.decide_random_target_for_actor
      end
    end
    # Start main phase
    start_phase4
  end
end
[/rgss]

Insert all of this into a new script below Scene_Battle. You'll need an icon called 'auto' in the icons folder.
auto.png

Here's one I did up quickly for testing purposes. You can edit it's position in the Spriteset_Battle section of the script where marked. If for some reason you don't want an icon indicating whether auto is activated or not, simply remove the Spriteset_Battle section of the script completely.
 

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