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.

Battle : Command Memory

Battle : Command Memory
Version: 3.5
By: Kain Nobel

Introduction

With this, your input is memorized for commands and stuff selected during battle. This is a feature that is often found in games, such as the ever-popular Final Fantasy series, which allows you to set Battle Cursor to Default or Memory.

Features

  • Works with DerVVulfman's Grouping & Details system (*NEW*)
  • Actors memorize their last selected battle command
  • Actors memorize their last selected skill or item
  • Actors memorize their last selected actor or enemy targets
  • All actors memory is cleared when battle ends

Script

Code:
#===============================================================================

# ** Battle : Command Memory

#===============================================================================

 

#-------------------------------------------------------------------------------

# * SDK Log

#-------------------------------------------------------------------------------

if Object.const_defined?(:SDK) && SDK.method_defined?(:log)

  SDK.log('Battle.CommandMemory', 'Kain Nobel ©', 3.5, '2009.06.17')

end

 

#===============================================================================

# ** RGSS.Actor and Party Info (should be in next MACL update)

#===============================================================================

 

class Game_Actors

  #-----------------------------------------------------------------------------

  # * Name      : Each

  #   Info      : Adds an 'each' method to $game_actors

  #   Author    : Kain Nobel

  #   Call Info : Any normal way you'd use an 'each' method from an object

  #-----------------------------------------------------------------------------

  def each(&block)

    @data.each(&block)

  end

end

 

#===============================================================================

# ** Game_Actor

#===============================================================================

 

class Game_Actor

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_accessor :battle_memory_command

  attr_accessor :battle_memory_skill

  attr_accessor :battle_memory_item

  attr_accessor :battle_memory_actor

  attr_accessor :battle_memory_enemy

  #-----------------------------------------------------------------------------

  # * Clear Battle Memory

  #-----------------------------------------------------------------------------

  def clear_battle_memory

    @battle_memory_command = nil

    @battle_memory_skill   = nil

    @battle_memory_item    = nil

    @battle_memory_actor   = nil

    @battle_memory_enemy   = nil

  end

end

 

#===============================================================================

# ** Window_Command

#===============================================================================

 

class Window_Command < Window_Selectable

  #-----------------------------------------------------------------------------

  # * Command

  #-----------------------------------------------------------------------------

  def command(index = self.index)

    @commands[index]

  end unless self.method_defined?(:command)

  #-----------------------------------------------------------------------------

  # * Commands

  #-----------------------------------------------------------------------------

  def commands

    @commands

  end unless self.method_defined?(:commands)

  #-----------------------------------------------------------------------------

  # * Command = (command)

  #-----------------------------------------------------------------------------

  def command=(com)

    for i in 0..@commands.size

      if @commands[i] == com

        self.index = i

        break

      end

    end

  end

end

 

#===============================================================================

# ** Window_Skill

#===============================================================================

 

class Window_Skill < Window_Selectable

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_reader :data

end

 

#===============================================================================

# ** Window_Item

#===============================================================================

 

class Window_Item < Window_Selectable

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_reader :data

end

 

#===============================================================================

# ** Scene_Battle

#===============================================================================

 

class Scene_Battle

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :bcmem_snbattle_main,              :main

  alias_method :bcmem_snbattle_p3setupcomwindow,  :phase3_setup_command_window

  alias_method :bcmem_snbattle_p3updatebasiccom,  :update_phase3_basic_command

  alias_method :bcmem_snbattle_startactorselect,  :start_actor_select

  alias_method :bcmem_snbattle_startenemyselect,  :start_enemy_select

  alias_method :bcmem_snbattle_startsklselect,    :start_skill_select

  alias_method :bcmem_snbattle_startitmselect,    :start_item_select

  alias_method :bcmem_snbattle_endactorselect,    :end_actor_select

  alias_method :bcmem_snbattle_endenemyselect,    :end_enemy_select

  alias_method :bcmem_snbattle_endsklselect,      :end_skill_select

  alias_method :bcmem_snbattle_enditmselect,      :end_item_select

  alias_method :bcmem_snbattle_makeitmactresult,  :make_item_action_result

  #-----------------------------------------------------------------------------

  # * Main

  #-----------------------------------------------------------------------------

  def main

    bcmem_snbattle_main

    $game_actors.each do |a| 

      next unless a.is_a?(Game_Actor)

      a.clear_battle_memory

    end

  end

  #-----------------------------------------------------------------------------

  # * Phase 3 : Setup Command Window

  #-----------------------------------------------------------------------------

  def phase3_setup_command_window

    bcmem_snbattle_p3setupcomwindow

    return unless @active_battler

    command = @active_battler.battle_memory_command

    if @actor_command_window.commands.include?(command)

      @actor_command_window.command = command

    else

      @active_battler.battle_memory_command = nil

    end

  end

  #-----------------------------------------------------------------------------

  # * Phase 3 : Basic Command

  #-----------------------------------------------------------------------------

  def update_phase3_basic_command

    if Input.trigger?(Input::C)

      @active_battler.battle_memory_command = @actor_command_window.command

    end

    bcmem_snbattle_p3updatebasiccom

  end

  #-----------------------------------------------------------------------------

  # * Start Actor Select

  #-----------------------------------------------------------------------------

  def start_actor_select

    bcmem_snbattle_startactorselect

    unless @active_battler.battle_memory_actor.nil?

      actor = @active_battler.battle_memory_actor

      if $game_party.actors.include?(actor)

        @actor_arrow.index = actor.index

      else

        @active_battler.battle_memory_actor = nil

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * Start Enemy Select

  #-----------------------------------------------------------------------------

  def start_enemy_select

    bcmem_snbattle_startenemyselect

    unless @active_battler.battle_memory_enemy.nil?

      enemy = @active_battler.battle_memory_enemy

      if $game_troop.enemies.include?(enemy)

        @enemy_arrow.index = enemy.index

      else

        @active_battler.battle_memory_enemy = nil

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * Start Skill Select

  #-----------------------------------------------------------------------------

  def start_skill_select

    bcmem_snbattle_startsklselect

    unless @active_battler.battle_memory_skill.nil?

      for i in 0..@skill_window.data.size

        if @skill_window.data[i].id == @active_battler.battle_memory_skill

          @skill_window.index = i

          break

        end

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * Start Item Select

  #-----------------------------------------------------------------------------

  def start_item_select

    bcmem_snbattle_startitmselect

    unless @active_battler.battle_memory_item.nil?

      for i in 0..@item_window.data.size

        if @item_window.data[i].id == @active_battler.battle_memory_item

          @item_window.index = i

          break

        end

      end

    end

  end

  #-----------------------------------------------------------------------------

  # * End Actor Select

  #-----------------------------------------------------------------------------

  def end_actor_select

    actor = $game_party.actors[@actor_arrow.index]

    @active_battler.battle_memory_actor = actor

    bcmem_snbattle_endactorselect

  end

  #-----------------------------------------------------------------------------

  # * End Enemy Select

  #-----------------------------------------------------------------------------

  def end_enemy_select

    enemy = $game_troop.enemies[@enemy_arrow.index]

    @active_battler.battle_memory_enemy = enemy

    bcmem_snbattle_endenemyselect

  end

  #-----------------------------------------------------------------------------

  # * End Skill Select

  #-----------------------------------------------------------------------------

  def end_skill_select

    @active_battler.battle_memory_skill = @skill_window.skill.id

    bcmem_snbattle_endsklselect

  end

  #-----------------------------------------------------------------------------

  # * End Item Select

  #-----------------------------------------------------------------------------

  def end_item_select

    @active_battler.battle_memory_item  = @item_window.item.id

    bcmem_snbattle_enditmselect

  end

  #-----------------------------------------------------------------------------

  # * Make Item Action Results

  #-----------------------------------------------------------------------------

  def make_item_action_result

    bcmem_snbattle_makeitmactresult

    item_id = @active_battler.current_action.item_id

    unless $game_party.item_number(item_id) > 0

      @active_battler.battle_memory_item = nil

    end

  end

end

 

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#

 

#===============================================================================

# ** Battle : Command Memory (DerVVulfman's Grouping & Details Patch)

#===============================================================================

 

#-------------------------------------------------------------------------------

# * Grouping & Detail Test : Begin

#-------------------------------------------------------------------------------

 

if Object.const_defined?(:Window_ItemGroup) &&

   Object.const_defined?(:Window_SkillGroup)

 

#===============================================================================

# ** Game_Actor

#===============================================================================

 

class Game_Actor < Game_Battler

  #-----------------------------------------------------------------------------

  # * Public Instance Variables

  #-----------------------------------------------------------------------------

  attr_accessor :battle_memory_Gitem

  attr_accessor :battle_memory_Gskill

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :bcmemGNDpatch_gmactor_clearbattlememory, :clear_battle_memory

  #-----------------------------------------------------------------------------

  # * Clear Battle Memory

  #-----------------------------------------------------------------------------

  def clear_battle_memory

    bcmemGNDpatch_gmactor_clearbattlememory

    @battle_memory_Gitem  = nil

    @battle_memory_Gskill = nil

  end

end

 

#===============================================================================

# ** Scene_Battle

#===============================================================================

 

class Scene_Battle

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :bcmemGNDpatch_snbattle_startitmselect,  :start_item_select

  alias_method :bcmemGNDpatch_snbattle_enditmselect,    :end_item_select

  alias_method :bcmemGNDpatch_snbattle_startsklselect,  :start_skill_select

  alias_method :bcmemGNDpatch_snbattle_endsklselect,    :end_skill_select

  #-----------------------------------------------------------------------------

  # * Start Item Select

  #-----------------------------------------------------------------------------

  def start_item_select

    bcmemGNDpatch_snbattle_startitmselect

    return if @active_battler.battle_memory_Gitem.nil?

    return unless GROUP_ITEMS_ON

    if @item_group_window.active

      @item_group_window.index = @active_battler.battle_memory_Gitem

    end

  end

  #-----------------------------------------------------------------------------

  # * End Item Select

  #-----------------------------------------------------------------------------

  def end_item_select

    if GROUP_ITEMS_ON

      @active_battler.battle_memory_Gitem = @item_group_window.index

    end

    bcmemGNDpatch_snbattle_enditmselect

  end

  #-----------------------------------------------------------------------------

  # * Start Skill Select

  #-----------------------------------------------------------------------------

  def start_skill_select

    bcmemGNDpatch_snbattle_startsklselect

    return if @active_battler.battle_memory_Gskill.nil?

    return unless GROUP_SKILL_ON

    if @skill_group_window.active

      @skill_group_window.index = @active_battler.battle_memory_Gskill

    end

  end

  #-----------------------------------------------------------------------------

  # * End Skill Select

  #-----------------------------------------------------------------------------

  def end_skill_select

    if GROUP_SKILL_ON

      @active_battler.battle_memory_Gskill = @skill_group_window.index

    end

    bcmemGNDpatch_snbattle_endsklselect

  end

end

 

#-------------------------------------------------------------------------------

# * Grouping & Detail Test : End

#-------------------------------------------------------------------------------

end

Instructions

Place Below SDK (only if using) and Above Main! If using DerVVulfMan's Grouping & Details script, place below that system or it probably won't work correctly.

Credit and Thanks

SP27 : Requesting Patch for DerVVulfman's Grouping and Details

Compatibility

Works with or without the SDK. Now includes a patch for DerVVulfman's Grouping and Details script too!

Enjoy :thumb:

Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, but credit is required thanks!
 
Kain Nobel, my man, your scripts are more awesome than Knights of Round, Sephiroth, and Chuck Norris put together, but does it always have to require the SDK? When I see your scripts, I'm always like, "Hmm, this looks intersting...*clicks on thread*...WHOAH! Imma use this in my game! *Sees the word SDK*...awwwww!"

The SDK ruins a lot of crap in my game so that's why I can't use it.
But, what ev. What can ya do, right?

Awesome script, of course! Just...
 
AHA! I lied and I fooled you just to see what you'd say! Now you can use this with or without SDK just the same, it no longer is a requirement!!! You don't have to delete the SDK.log line or anything, it works as-is with or without...

Nah, I didn't lie on purpose its just I've been working with SDK for 2 years, and haven't seen default Scene_Battle coding in a long assed time, all I had to do is change one method between the versions and now it works both ways!

Go ahead, paste that baby in and see if it works without SDK now! If you encounter any problems, then feel free to come back but I think you should be just fine.
 

SP27

Sponsor

Ahhh too bad it doesn't work with "GROUPING & DETAILS" from DerVVulfman.

Other than that, awesome script you have made there, as always! :thumb:
 
Yeah, its not gonna work on its own with scripts like that, which group skills/items into their own sub-categorized menus 'n such, I already figured it wouldn't lol. Not a problem though, I'll take a look at it tomorrow and see if I can post an addon patch for the Item Grouping/Details script by DerVVulfman.

Also, if anybody else needs a patch for something let me know and I'll try and get on it right away!
 

NL124

Member

Looks great, just what I needed to get my game started off. Sadly doesn't seem to work with the SBS Tankentai XP sscript though. Looks good either way. Nice work.
 
Found a buggy:

When right before the command window in the battle screen appears, the game gets an error regarding line 113. I'm not using the SDK, but that wouldn't be the problem because it would shut down automatically if it required it.
 

SP27

Sponsor

Kain Nobel":3qs79j7b said:
Not a problem though, I'll take a look at it tomorrow and see if I can post an addon patch for the Item Grouping/Details script by DerVVulfman.

That would be awesome! :grin:
 
Theres a couple NoMethodError errors that occur without SDK that I've fixed, so with or without SDK this should work just fine because those methods are redefined if SDK isn't present. Also, thanks SP27 for requesting a patch for DerVVulfman's Grouping & Details system, which is now in the new version.

Anybody who had problems with the last version, replace it with the new version. Also, you can find the Grouping and Details patch starting around line 240 included in the script. This is imediately active if Window_ItemGroup and Window_SkillGroup are defined (native to the G&D system).

If anybody encounters any problems, please PM me because I'll be too busy to watch the forums the next few weeks.
 

SP27

Sponsor

:shock: Say whaaat?
I'm in the credits, hehe now that's a first! :biggrin:

Kudos on the patch Kain! :thumb:
If I find any errors or "glitches" I'll be sure to alert you!
 
SP27":12w2ckha said:
Awww, that's too bad, I have to report a bug to you. :sad:

Untitled.png


This error pops up right after the end of battle when you saw the EXP/gold window and you closed it.

Oh yeah, and one more little thing, it works great in-battle, but it doesn't remember the skill you chose. Which would be awesome if it could be done. :smile:

Hope that was enough info. :wink:

Thank you for PMing me this bug, it would've took me longer to notice it if you didn't =P

Okay, the first one you could consider as a typo and use $game_party.actors.each but I had actually did it directly on $game_actors on purpose, incase party changes during battle. Instead of changing that line, just leave it as is and paste this above it, it was a method I forgot to include with the script but its something I threw in for the MACL

Code:
#===============================================================================

# ** RGSS.Actor and Party Info (should be in next MACL update)

#===============================================================================

 

class Game_Actors

  #-----------------------------------------------------------------------------

  # * Name      : Each

  #   Info      : Adds an 'each' method to $game_actors

  #   Author    : Kain Nobel

  #   Call Info : Any normal way you'd use an 'each' method from an object

  #-----------------------------------------------------------------------------

  def each(&block)

    @data.each(&block)

  end

end

As far as the skill not memorizing bug, I've tested it both with and without Grouping and Details system and I'm not getting any issues like that. Perhaps you're using a script or event that, for any reason, adds and removes skills in the middle of battle? Since it memorizes skill by ID (and not the index of the window) it could be that you use skill #67 and some event/script removes it, then you go to the skill screen again and it should default to the very first index if the skill (with the ID) isn't found. I'm just throwing out a likely cause, because I can't think of what else would be causing the problem since it works fine with what I've tested.

You might wanna share what scripts you're using, I'll check them out and see if any could be causing this one not to work correctly. Best bet would be just PM me a demo if you can, so I can see myself whats going on.

Again, thanks for the bug reports much appreciated :thumb:

BTW, I've fixed a couple bugs thus far in the script and updated the post above, one is related to checking if Window_Command commands should be defined based on if SDK is present, I changed it to check instead if self.method_defined? for the methods in question which might be causing NoMethodError errors.
 

SP27

Sponsor

No I'm not using any scripts that change skill ID's at all. :grin:

I'll test this update you have and I'll let you know if it works or not. :biggrin:
 

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