Advertisement
Double_X

DoubleX RMVXA Targeting Hotkeys v1.00a

May 22nd, 2015 (edited)
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.77 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Targeting Hotkeys                                           |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Lets you set some hotkeys to speed up skill/item target selections        |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall keep this script's Script Info part's contents intact           |
  12. #    You shalln't claim that this script is written by anyone other than       |
  13. #    DoubleX or his aliases                                                    |
  14. #    None of the above applies to DoubleX or his aliases                       |
  15. #------------------------------------------------------------------------------|
  16. #  * Prerequisites                                                             |
  17. #    Abilities:                                                                |
  18. #    1. Little scripting proficiency to fully utilize this script              |
  19. #------------------------------------------------------------------------------|
  20. #  * Instructions                                                              |
  21. #    1. Open the script editor and put this script into an open slot between   |
  22. #       Materials and Main, save to take effect.                               |
  23. #------------------------------------------------------------------------------|
  24. #  * Links                                                                     |
  25. #    Script Usage 101:                                                         |
  26. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  27. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  28. #    This script:                                                              |
  29. #    1. http://pastebin.com/UuMjaC7k                                           |
  30. #    Mentioned Patreon Supporters:                                             |
  31. #    https://www.patreon.com/posts/71738797                                    |
  32. #------------------------------------------------------------------------------|
  33. #  * Authors                                                                   |
  34. #    DoubleX                                                                   |
  35. #------------------------------------------------------------------------------|
  36. #  * Changelog                                                                 |
  37. #    v1.00a(GMT 0200 23-5-2015):                                               |
  38. #    1. 1st version of this script finished                                    |
  39. #==============================================================================|
  40.  
  41. ($doublex_rmvxa ||= {})[:Targeting_Hotkeys] = "v1.00a"
  42.  
  43. #==============================================================================|
  44. #  ** Script Configurations                                                    |
  45. #     You only need to edit this part as it's about what this script does      |
  46. #------------------------------------------------------------------------------|
  47.  
  48. module DoubleX_RMVXA
  49.  
  50.   module Targeting_Hotkeys
  51.  
  52.       # Sets the hotkeys selecting a target that can be targeted in the target
  53.       # window
  54.       # The ith hotkey calls the ith target in the target window
  55.       # Nothing will happen if the ith hotkey's pressed and the ith target in
  56.       # the target window can't be targeted
  57.       # A custom keymap binding script may help setting the hotkeys
  58.       # Example: To disable this feature, set this as []
  59.       HOTKEYS = [
  60.         :KEY_1,
  61.         :KEY_2,
  62.         :KEY_3,
  63.         :KEY_4,
  64.         :KEY_5,
  65.         :KEY_6,
  66.         :KEY_7,
  67.         :KEY_8
  68.       ]
  69.  
  70. #==============================================================================|
  71. #  ** Script Implementations                                                   |
  72. #     You need not edit this part as it's about how this script works          |
  73. #------------------------------------------------------------------------------|
  74. #  * Script Support Info:                                                      |
  75. #    1. Prerequisites                                                          |
  76. #       - Decent RGSS3 scripting proficiency to fully comprehend this script   |
  77. #    2. Method documentation                                                   |
  78. #       - The 1st part informs whether the method's rewritten, aliased or new  |
  79. #       - The 2nd part describes what the method does for new methods only     |
  80. #       - The 3rd part describes what the arguments of the method are          |
  81. #       - The 4th part describes how this method works for new methods only,   |
  82. #         and describes the parts added or rewritten for rewritten or aliased  |
  83. #         methods only                                                         |
  84. #       Example:                                                               |
  85. # #----------------------------------------------------------------------------|
  86. # #  Rewrite/Alias/New method: def_name                                        |
  87. # #  - What this method does                                                   |
  88. # #----------------------------------------------------------------------------|
  89. # # *args: What these arguments are                                            |
  90. # def def_name(*args)                                                          |
  91. #   # How this method works                                                    |
  92. #   def_name_code                                                              |
  93. #   #                                                                          |
  94. # end # def_name                                                               |
  95. #------------------------------------------------------------------------------|
  96.  
  97.     PROCESS_HANDLING = %Q(
  98.  
  99.   alias initialize_target_hotkeys initialize
  100.   def initialize(info_viewport)
  101.     initialize_target_hotkeys(info_viewport)
  102.     init_targeting_hotkey_block
  103.   end
  104.  
  105.   alias process_handling_targeting_hotkeys process_handling
  106.   def process_handling
  107.     if open? && active
  108.       DoubleX_RMVXA::Targeting_Hotkeys::HOTKEYS.each(&@targeting_hotkey_block)
  109.     end
  110.     process_handling_targeting_hotkeys
  111.   end # process_handling
  112.  
  113.   def init_targeting_hotkey_block
  114.     @targeting_hotkey_block = -> hotkey {
  115.       return call_handler(hotkey) if Input.trigger?(hotkey)
  116.     }
  117.   end
  118.  
  119.     )
  120.  
  121.   end # Targeting_Hotkeys
  122.  
  123. end # DoubleX_RMVXA
  124.  
  125. #------------------------------------------------------------------------------|
  126. #  * Edit class: Window_BattleActor                                            |
  127. #------------------------------------------------------------------------------|
  128.  
  129. class Window_BattleActor < Window_BattleStatus
  130.  
  131.   #----------------------------------------------------------------------------|
  132.   #  Alias/New methods                                                         |
  133.   #----------------------------------------------------------------------------|
  134.   module_eval(DoubleX_RMVXA::Targeting_Hotkeys::PROCESS_HANDLING)
  135.  
  136. end # Window_BattleActor
  137.  
  138. #------------------------------------------------------------------------------|
  139. #  * Edit class: Window_BattleEnemy                                            |
  140. #------------------------------------------------------------------------------|
  141.  
  142. class Window_BattleEnemy < Window_Selectable
  143.  
  144.   #----------------------------------------------------------------------------|
  145.   #  Alias/New methods                                                         |
  146.   #----------------------------------------------------------------------------|
  147.   module_eval(DoubleX_RMVXA::Targeting_Hotkeys::PROCESS_HANDLING)
  148.  
  149. end # Window_BattleEnemy
  150.  
  151. #------------------------------------------------------------------------------|
  152. #  * Edit class: Scene_Battle                                                  |
  153. #------------------------------------------------------------------------------|
  154.  
  155. class Scene_Battle < Scene_Base
  156.  
  157.   #----------------------------------------------------------------------------|
  158.   #  Alias method: create_all_windows                                          |
  159.   #----------------------------------------------------------------------------|
  160.   alias create_all_windows_targeting_hotkeys create_all_windows
  161.   def create_all_windows
  162.     create_all_windows_targeting_hotkeys
  163.     # Added to set the target selection hotkeys in the target windows
  164.     set_targeting_hotkeys
  165.     #
  166.   end # create_all_windows
  167.  
  168.   #----------------------------------------------------------------------------|
  169.   #  New method: set_targeting_hotkeys                                         |
  170.   #  - Sets the target selection hotkeys in the target windows                 |
  171.   #----------------------------------------------------------------------------|
  172.   def set_targeting_hotkeys
  173.     # Creates and sets each hotkey handler for both the actor and enemy windows
  174.     hotkeys = DoubleX_RMVXA::Targeting_Hotkeys::HOTKEYS
  175.     create_targeting_hotkey_defs(hotkeys)
  176.     hotkeys.each_with_index { |hotkey, index|
  177.       @actor_window.set_handler(hotkey, method(
  178.       "targeting_hotkey_#{index.to_s}".to_sym))
  179.       @enemy_window.set_handler(hotkey, method(
  180.       "targeting_hotkey_#{index.to_s}".to_sym))
  181.     }
  182.     #
  183.   end # set_targeting_hotkeys
  184.  
  185.   #----------------------------------------------------------------------------|
  186.   #  New method: create_targeting_hotkey_defs                                  |
  187.   #  - Creates methods used by the target selection hotkey handlers            |
  188.   #----------------------------------------------------------------------------|
  189.   def create_targeting_hotkey_defs(hotkeys)
  190.     # Points the actor's skill/item's target index to the target window index
  191.     hotkeys.each_index { |index|
  192.       eval(%Q(
  193.     def targeting_hotkey_#{index.to_s}
  194.       return unless BattleManager.actor.input.item.for_one?
  195.       BattleManager.actor.input.target_index = #{index}
  196.       @actor_window.hide if @actor_window.active
  197.       @enemy_window.hide if @enemy_window.active
  198.       @skill_window.hide
  199.       @item_window.hide
  200.       next_command
  201.     end
  202.       ))
  203.     }
  204.     #
  205.   end # create_targeting_hotkey_defs
  206.  
  207. end # Scene_Battle
  208.  
  209. #------------------------------------------------------------------------------|
  210.  
  211. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement