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

Battle : Command Memory Spoiler
  1. #===============================================================================
  2. # ** Battle : Command Memory
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. if Object.const_defined?(:SDK) && SDK.method_defined?(:log)
  9.   SDK.log('Battle.CommandMemory', 'Kain Nobel ©', 3.5, '2009.06.17')
  10. end
  11.  
  12. #===============================================================================
  13. # ** RGSS.Actor and Party Info (should be in next MACL update)
  14. #===============================================================================
  15.  
  16. class Game_Actors
  17.   #-----------------------------------------------------------------------------
  18.   # * Name      : Each
  19.   #   Info      : Adds an 'each' method to $game_actors
  20.   #   Author    : Kain Nobel
  21.   #   Call Info : Any normal way you'd use an 'each' method from an object
  22.   #-----------------------------------------------------------------------------
  23.   def each(&block)
  24.     @data.each(&block)
  25.   end
  26. end
  27.  
  28. #===============================================================================
  29. # ** Game_Actor
  30. #===============================================================================
  31.  
  32. class Game_Actor
  33.   #-----------------------------------------------------------------------------
  34.   # * Public Instance Variables
  35.   #-----------------------------------------------------------------------------
  36.   attr_accessor :battle_memory_command
  37.   attr_accessor :battle_memory_skill
  38.   attr_accessor :battle_memory_item
  39.   attr_accessor :battle_memory_actor
  40.   attr_accessor :battle_memory_enemy
  41.   #-----------------------------------------------------------------------------
  42.   # * Clear Battle Memory
  43.   #-----------------------------------------------------------------------------
  44.   def clear_battle_memory
  45.     @battle_memory_command = nil
  46.     @battle_memory_skill   = nil
  47.     @battle_memory_item    = nil
  48.     @battle_memory_actor   = nil
  49.     @battle_memory_enemy   = nil
  50.   end
  51. end
  52.  
  53. #===============================================================================
  54. # ** Window_Command
  55. #===============================================================================
  56.  
  57. class Window_Command < Window_Selectable
  58.   #-----------------------------------------------------------------------------
  59.   # * Command
  60.   #-----------------------------------------------------------------------------
  61.   def command(index = self.index)
  62.     @commands[index]
  63.   end unless self.method_defined?(:command)
  64.   #-----------------------------------------------------------------------------
  65.   # * Commands
  66.   #-----------------------------------------------------------------------------
  67.   def commands
  68.     @commands
  69.   end unless self.method_defined?(:commands)
  70.   #-----------------------------------------------------------------------------
  71.   # * Command = (command)
  72.   #-----------------------------------------------------------------------------
  73.   def command=(com)
  74.     for i in 0..@commands.size
  75.       if @commands[i] == com
  76.         self.index = i
  77.         break
  78.       end
  79.     end
  80.   end
  81. end
  82.  
  83. #===============================================================================
  84. # ** Window_Skill
  85. #===============================================================================
  86.  
  87. class Window_Skill < Window_Selectable
  88.   #-----------------------------------------------------------------------------
  89.   # * Public Instance Variables
  90.   #-----------------------------------------------------------------------------
  91.   attr_reader :data
  92. end
  93.  
  94. #===============================================================================
  95. # ** Window_Item
  96. #===============================================================================
  97.  
  98. class Window_Item < Window_Selectable
  99.   #-----------------------------------------------------------------------------
  100.   # * Public Instance Variables
  101.   #-----------------------------------------------------------------------------
  102.   attr_reader :data
  103. end
  104.  
  105. #===============================================================================
  106. # ** Scene_Battle
  107. #===============================================================================
  108.  
  109. class Scene_Battle
  110.   #-----------------------------------------------------------------------------
  111.   # * Alias Listings
  112.   #-----------------------------------------------------------------------------
  113.   alias_method :bcmem_snbattle_main,              :main
  114.   alias_method :bcmem_snbattle_p3setupcomwindow,  :phase3_setup_command_window
  115.   alias_method :bcmem_snbattle_p3updatebasiccom,  :update_phase3_basic_command
  116.   alias_method :bcmem_snbattle_startactorselect,  :start_actor_select
  117.   alias_method :bcmem_snbattle_startenemyselect,  :start_enemy_select
  118.   alias_method :bcmem_snbattle_startsklselect,    :start_skill_select
  119.   alias_method :bcmem_snbattle_startitmselect,    :start_item_select
  120.   alias_method :bcmem_snbattle_endactorselect,    :end_actor_select
  121.   alias_method :bcmem_snbattle_endenemyselect,    :end_enemy_select
  122.   alias_method :bcmem_snbattle_endsklselect,      :end_skill_select
  123.   alias_method :bcmem_snbattle_enditmselect,      :end_item_select
  124.   alias_method :bcmem_snbattle_makeitmactresult,  :make_item_action_result
  125.   #-----------------------------------------------------------------------------
  126.   # * Main
  127.   #-----------------------------------------------------------------------------
  128.   def main
  129.     bcmem_snbattle_main
  130.     $game_actors.each do |a|
  131.       next unless a.is_a?(Game_Actor)
  132.       a.clear_battle_memory
  133.     end
  134.   end
  135.   #-----------------------------------------------------------------------------
  136.   # * Phase 3 : Setup Command Window
  137.   #-----------------------------------------------------------------------------
  138.   def phase3_setup_command_window
  139.     bcmem_snbattle_p3setupcomwindow
  140.     return unless @active_battler
  141.     command = @active_battler.battle_memory_command
  142.     if @actor_command_window.commands.include?(command)
  143.       @actor_command_window.command = command
  144.     else
  145.       @active_battler.battle_memory_command = nil
  146.     end
  147.   end
  148.   #-----------------------------------------------------------------------------
  149.   # * Phase 3 : Basic Command
  150.   #-----------------------------------------------------------------------------
  151.   def update_phase3_basic_command
  152.     if Input.trigger?(Input::C)
  153.       @active_battler.battle_memory_command = @actor_command_window.command
  154.     end
  155.     bcmem_snbattle_p3updatebasiccom
  156.   end
  157.   #-----------------------------------------------------------------------------
  158.   # * Start Actor Select
  159.   #-----------------------------------------------------------------------------
  160.   def start_actor_select
  161.     bcmem_snbattle_startactorselect
  162.     unless @active_battler.battle_memory_actor.nil?
  163.       actor = @active_battler.battle_memory_actor
  164.       if $game_party.actors.include?(actor)
  165.         @actor_arrow.index = actor.index
  166.       else
  167.         @active_battler.battle_memory_actor = nil
  168.       end
  169.     end
  170.   end
  171.   #-----------------------------------------------------------------------------
  172.   # * Start Enemy Select
  173.   #-----------------------------------------------------------------------------
  174.   def start_enemy_select
  175.     bcmem_snbattle_startenemyselect
  176.     unless @active_battler.battle_memory_enemy.nil?
  177.       enemy = @active_battler.battle_memory_enemy
  178.       if $game_troop.enemies.include?(enemy)
  179.         @enemy_arrow.index = enemy.index
  180.       else
  181.         @active_battler.battle_memory_enemy = nil
  182.       end
  183.     end
  184.   end
  185.   #-----------------------------------------------------------------------------
  186.   # * Start Skill Select
  187.   #-----------------------------------------------------------------------------
  188.   def start_skill_select
  189.     bcmem_snbattle_startsklselect
  190.     unless @active_battler.battle_memory_skill.nil?
  191.       for i in 0..@skill_window.data.size
  192.         if @skill_window.data[i].id == @active_battler.battle_memory_skill
  193.           @skill_window.index = i
  194.           break
  195.         end
  196.       end
  197.     end
  198.   end
  199.   #-----------------------------------------------------------------------------
  200.   # * Start Item Select
  201.   #-----------------------------------------------------------------------------
  202.   def start_item_select
  203.     bcmem_snbattle_startitmselect
  204.     unless @active_battler.battle_memory_item.nil?
  205.       for i in 0..@item_window.data.size
  206.         if @item_window.data[i].id == @active_battler.battle_memory_item
  207.           @item_window.index = i
  208.           break
  209.         end
  210.       end
  211.     end
  212.   end
  213.   #-----------------------------------------------------------------------------
  214.   # * End Actor Select
  215.   #-----------------------------------------------------------------------------
  216.   def end_actor_select
  217.     actor = $game_party.actors[@actor_arrow.index]
  218.     @active_battler.battle_memory_actor = actor
  219.     bcmem_snbattle_endactorselect
  220.   end
  221.   #-----------------------------------------------------------------------------
  222.   # * End Enemy Select
  223.   #-----------------------------------------------------------------------------
  224.   def end_enemy_select
  225.     enemy = $game_troop.enemies[@enemy_arrow.index]
  226.     @active_battler.battle_memory_enemy = enemy
  227.     bcmem_snbattle_endenemyselect
  228.   end
  229.   #-----------------------------------------------------------------------------
  230.   # * End Skill Select
  231.   #-----------------------------------------------------------------------------
  232.   def end_skill_select
  233.     @active_battler.battle_memory_skill = @skill_window.skill.id
  234.     bcmem_snbattle_endsklselect
  235.   end
  236.   #-----------------------------------------------------------------------------
  237.   # * End Item Select
  238.   #-----------------------------------------------------------------------------
  239.   def end_item_select
  240.     @active_battler.battle_memory_item  = @item_window.item.id
  241.     bcmem_snbattle_enditmselect
  242.   end
  243.   #-----------------------------------------------------------------------------
  244.   # * Make Item Action Results
  245.   #-----------------------------------------------------------------------------
  246.   def make_item_action_result
  247.     bcmem_snbattle_makeitmactresult
  248.     item_id = @active_battler.current_action.item_id
  249.     unless $game_party.item_number(item_id) > 0
  250.       @active_battler.battle_memory_item = nil
  251.     end
  252.   end
  253. end
  254.  
  255. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
  256.  
  257. #===============================================================================
  258. # ** Battle : Command Memory (DerVVulfman's Grouping & Details Patch)
  259. #===============================================================================
  260.  
  261. #-------------------------------------------------------------------------------
  262. # * Grouping & Detail Test : Begin
  263. #-------------------------------------------------------------------------------
  264.  
  265. if Object.const_defined?(:Window_ItemGroup) &&
  266.    Object.const_defined?(:Window_SkillGroup)
  267.  
  268. #===============================================================================
  269. # ** Game_Actor
  270. #===============================================================================
  271.  
  272. class Game_Actor < Game_Battler
  273.   #-----------------------------------------------------------------------------
  274.   # * Public Instance Variables
  275.   #-----------------------------------------------------------------------------
  276.   attr_accessor :battle_memory_Gitem
  277.   attr_accessor :battle_memory_Gskill
  278.   #-----------------------------------------------------------------------------
  279.   # * Alias Listings
  280.   #-----------------------------------------------------------------------------
  281.   alias_method :bcmemGNDpatch_gmactor_clearbattlememory, :clear_battle_memory
  282.   #-----------------------------------------------------------------------------
  283.   # * Clear Battle Memory
  284.   #-----------------------------------------------------------------------------
  285.   def clear_battle_memory
  286.     bcmemGNDpatch_gmactor_clearbattlememory
  287.     @battle_memory_Gitem  = nil
  288.     @battle_memory_Gskill = nil
  289.   end
  290. end
  291.  
  292. #===============================================================================
  293. # ** Scene_Battle
  294. #===============================================================================
  295.  
  296. class Scene_Battle
  297.   #-----------------------------------------------------------------------------
  298.   # * Alias Listings
  299.   #-----------------------------------------------------------------------------
  300.   alias_method :bcmemGNDpatch_snbattle_startitmselect,  :start_item_select
  301.   alias_method :bcmemGNDpatch_snbattle_enditmselect,    :end_item_select
  302.   alias_method :bcmemGNDpatch_snbattle_startsklselect,  :start_skill_select
  303.   alias_method :bcmemGNDpatch_snbattle_endsklselect,    :end_skill_select
  304.   #-----------------------------------------------------------------------------
  305.   # * Start Item Select
  306.   #-----------------------------------------------------------------------------
  307.   def start_item_select
  308.     bcmemGNDpatch_snbattle_startitmselect
  309.     return if @active_battler.battle_memory_Gitem.nil?
  310.     return unless GROUP_ITEMS_ON
  311.     if @item_group_window.active
  312.       @item_group_window.index = @active_battler.battle_memory_Gitem
  313.     end
  314.   end
  315.   #-----------------------------------------------------------------------------
  316.   # * End Item Select
  317.   #-----------------------------------------------------------------------------
  318.   def end_item_select
  319.     if GROUP_ITEMS_ON
  320.       @active_battler.battle_memory_Gitem = @item_group_window.index
  321.     end
  322.     bcmemGNDpatch_snbattle_enditmselect
  323.   end
  324.   #-----------------------------------------------------------------------------
  325.   # * Start Skill Select
  326.   #-----------------------------------------------------------------------------
  327.   def start_skill_select
  328.     bcmemGNDpatch_snbattle_startsklselect
  329.     return if @active_battler.battle_memory_Gskill.nil?
  330.     return unless GROUP_SKILL_ON
  331.     if @skill_group_window.active
  332.       @skill_group_window.index = @active_battler.battle_memory_Gskill
  333.     end
  334.   end
  335.   #-----------------------------------------------------------------------------
  336.   # * End Skill Select
  337.   #-----------------------------------------------------------------------------
  338.   def end_skill_select
  339.     if GROUP_SKILL_ON
  340.       @active_battler.battle_memory_Gskill = @skill_group_window.index
  341.     end
  342.     bcmemGNDpatch_snbattle_endsklselect
  343.   end
  344. end
  345.  
  346. #-------------------------------------------------------------------------------
  347. # * Grouping & Detail Test : End
  348. #-------------------------------------------------------------------------------
  349. end
Expand to see the code.


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.
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!
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.
Kain Nobel wrote:
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.
:shock: Say whaaat?
I'm in the credits, hehe now that's a first! 😀

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

Image

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. 🙂

Hope that was enough info. 😉


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

  1. #===============================================================================
  2. # ** RGSS.Actor and Party Info (should be in next MACL update)
  3. #===============================================================================
  4.  
  5. class Game_Actors
  6.   #-----------------------------------------------------------------------------
  7.   # * Name      : Each
  8.   #   Info      : Adds an 'each' method to $game_actors
  9.   #   Author    : Kain Nobel
  10.   #   Call Info : Any normal way you'd use an 'each' method from an object
  11.   #-----------------------------------------------------------------------------
  12.   def each(&block)
  13.     @data.each(&block)
  14.   end
  15. end
Expand to see the code.


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.
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. 😀

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=65990