Advertisement
Double_X

DoubleX RMVXA Basic ATB Bar v1.00b

Aug 22nd, 2015 (edited)
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.95 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Basic ATB Bar                                               |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Aids other scripters to learn how to solve atb system addon dependencies  |
  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. #    Scripts:                                                                  |
  18. #    1. DoubleX RMVXA Basic ATB                                                |
  19. #    Abilities:                                                                |
  20. #    1. Little RGSS3 scripting proficiency to fully utilize this script        |
  21. #------------------------------------------------------------------------------|
  22. #  * Instructions                                                              |
  23. #    1. Open the script editor and put this script into an open slot between   |
  24. #       DoubleX RMVXA Basic ATB and Main, save to take effect.                 |
  25. #------------------------------------------------------------------------------|
  26. #  * Links                                                                     |
  27. #    Script Usage 101:                                                         |
  28. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  29. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  30. #    How to write an atb system script:                                        |
  31. #    1. http://rpgmaker.net/articles/1127/                                     |
  32. #    This script:                                                              |
  33. #    1. http://pastebin.com/Lg0NCYU5                                           |
  34. #    Video:                                                                    |
  35. #    1. https://www.youtube.com/watch?v=_mRU0o9Q3Ac                            |
  36. #    Mentioned Patreon Supporters:                                             |
  37. #    https://www.patreon.com/posts/71738797                                    |
  38. #------------------------------------------------------------------------------|
  39. #  * Authors                                                                   |
  40. #    DoubleX                                                                   |
  41. #------------------------------------------------------------------------------|
  42. #  * Changelog                                                                 |
  43. #    v1.00b(GMT 0900 9-9-2015):                                                |
  44. #    1. Fixed drawing the actor sprite atb bars and window atb bars together   |
  45. #    2. Fixed not updating the atb bar positions when their offsets changes    |
  46. #    3. Little RGSS3 scripting proficiency's needed to fully utilize the script|
  47. #    v1.00a(GMT 0900 22-8-2015):                                               |
  48. #    1. 1st version of this script finished                                    |
  49. #==============================================================================|
  50.  
  51. #==============================================================================|
  52. #  ** (v1.00b+)Script Call Info                                                |
  53. #------------------------------------------------------------------------------|
  54. #  * Battle manipulations                                                      |
  55. #    1. batb_offset_change = true                                              |
  56. #       - Notifies that the atb bars' x or y offsets are changed               |
  57. #==============================================================================|
  58.  
  59. ($doublex_rmvxa ||= {})[:BATB_Bar] = "v1.00b"
  60.  
  61. #==============================================================================|
  62. #  ** Script Configurations                                                    |
  63. #     You only need to edit this part as it's about what this script does      |
  64. #------------------------------------------------------------------------------|
  65.  
  66. module DoubleX_RMVXA
  67.  
  68.   module BATB_Bar
  69.  
  70.     # Sets the actor atb bars to be shown at their sprites instead of the
  71.     # status window if ATB_BAR_ACTOR returns true
  72.     # It should only return true if the actor sprites are already created
  73.     # If ATB_BAR_WIDTH_SWITCH_ID is a natural number, the state of switch with
  74.     # id ATB_BAR_WIDTH_SWITCH_ID will be used instead of using ATB_BAR_ACTOR
  75.     # The state of switch with id ATB_BAR_WIDTH_SWITCH_ID should remain the same
  76.     # during the same battle to ensure proper atb bar displays
  77.     ATB_BAR_ACTOR = false
  78.     ATB_BAR_ACTOR_SWITCH_ID = 0
  79.  
  80.     # Sets the maximum atb bar width as ATB_BAR_W
  81.     # If ATB_BAR_W_VAR_ID is a natural number, the value of variable with id
  82.     # ATB_BAR_W_VAR_ID will be used instead of using ATB_BAR_W
  83.     # The value of variable with id ATB_BAR_W_VAR_ID should remain the same
  84.     # during the same battle to ensure proper atb bar displays
  85.     ATB_BAR_W = 48
  86.     ATB_BAR_W_VAR_ID = 0
  87.  
  88.     # Sets the atb bar height as ATB_BAR_H
  89.     # If ATB_BAR_H_VAR_ID is a natural number, the value of variable with id
  90.     # ATB_BAR_H_VAR_ID will be used instead of using ATB_BAR_H
  91.     # The value of variable with id ATB_BAR_H_VAR_ID should remain the same
  92.     # during the same battle to ensure proper atb bar displays
  93.     ATB_BAR_H = 12
  94.     ATB_BAR_H_VAR_ID = 0
  95.  
  96.     # Sets the atb bar x offset from the battler sprite as ATB_BAR_X
  97.     # If ATB_BAR_X_VAR_ID is a natural number, the value of variable with id
  98.     # ATB_BAR_X_VAR_ID will be used instead of using ATB_BAR_X
  99.     # The value of variable with id ATB_BAR_X_VAR_ID should remain the same
  100.     # during the same battle to ensure proper atb bar displays
  101.     ATB_BAR_X = -12
  102.     ATB_BAR_X_VAR_ID = 0
  103.  
  104.     # Sets the atb bar y offset from the battler sprite as ATB_BAR_Y
  105.     # If ATB_BAR_Y_VAR_ID is a natural number, the value of variable with id
  106.     # ATB_BAR_Y_VAR_ID will be used instead of using ATB_BAR_Y
  107.     # The value of variable with id ATB_BAR_Y_VAR_ID should remain the same
  108.     # during the same battle to ensure proper atb bar displays
  109.     ATB_BAR_Y = -8
  110.     ATB_BAR_Y_VAR_ID = 0
  111.  
  112.     # Sets the atb bar z position as ATB_BAR_Z
  113.     # If ATB_BAR_Z_VAR_ID is a natural number, the value of variable with id
  114.     # ATB_BAR_Z_VAR_ID will be used instead of using ATB_BAR_Z
  115.     # The value of variable with id ATB_BAR_Z_VAR_ID should remain the same
  116.     # during the same battle to ensure proper atb bar displays
  117.     ATB_BAR_Z = 125
  118.     ATB_BAR_Z_VAR_ID = 0
  119.  
  120.     # Sets the atb back bar color 1 as ATB_BACK_COLOR1
  121.     # If ATB_BACK_COLOR1_VAR_ID is a natural number, the value of variable with
  122.     # id ATB_BACK_COLOR1_VAR_ID will be used instead of using ATB_BACK_COLOR1
  123.     # The value of variable with id ATB_BACK_COLOR1_VAR_ID should remain the
  124.     # same during the same battle to ensure proper atb back bar color displays
  125.     ATB_BACK_COLOR1 = 15
  126.     ATB_BACK_COLOR1_VAR_ID = 0
  127.  
  128.     # Sets the atb back bar color 2 as ATB_BACK_COLOR2
  129.     # If ATB_BACK_COLOR2_VAR_ID is a natural number, the value of variable with
  130.     # id ATB_BACK_COLOR2_VAR_ID will be used instead of using ATB_BACK_COLOR2
  131.     # The value of variable with id ATB_BACK_COLOR2_VAR_ID should remain the
  132.     # same during the same battle to ensure proper atb back bar color displays
  133.     ATB_BACK_COLOR2 = 15
  134.     ATB_BACK_COLOR2_VAR_ID = 0
  135.  
  136. #==============================================================================|
  137. #  ** Script Implementations                                                   |
  138. #     You need not edit this part as it's about how this script works          |
  139. #------------------------------------------------------------------------------|
  140. #  * Script Support Info:                                                      |
  141. #    1. Prerequisites                                                          |
  142. #       - Basic atb concept and default RMVXA battle system knowledge          |
  143. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  144. #    2. Method documentation                                                   |
  145. #       - The 1st part describes why this method's rewritten/aliased for       |
  146. #         rewritten/aliased methods or what the method does for new methods    |
  147. #       - The 2nd part describes what the arguments of the method are          |
  148. #       - The 3rd part informs which version rewritten, aliased or created this|
  149. #         method                                                               |
  150. #       - The 4th part informs whether the method's rewritten or new           |
  151. #       - The 5th part describes how this method works for new methods only,   |
  152. #         and describes the parts added, removed or rewritten for rewritten or |
  153. #         aliased methods only                                                 |
  154. #       Example:                                                               |
  155. # #--------------------------------------------------------------------------| |
  156. # #  Why rewrite/alias/What this method does                                 | |
  157. # #--------------------------------------------------------------------------| |
  158. # # *argv: What these variables are                                            |
  159. # # &argb: What this block is                                                  |
  160. # def def_name(*argv, &argb) # Version X+; Rewrite/New                         |
  161. #   # Added/Removed/Rewritten to do something/How this method works            |
  162. #   def_name_code                                                              |
  163. #   #                                                                          |
  164. # end # def_name                                                               |
  165. #------------------------------------------------------------------------------|
  166.  
  167.     #--------------------------------------------------------------------------|
  168.     #  Helper methods simplifying the uses of the configuration values         |
  169.     #--------------------------------------------------------------------------|
  170.  
  171.     def self.atb_bar_actor
  172.       return ATB_BAR_ACTOR if ATB_BAR_ACTOR_SWITCH_ID <= 0
  173.       $game_switches[ATB_BAR_ACTOR_SWITCH_ID]
  174.     end # atb_bar_actor
  175.  
  176.     def self.atb_bar_w
  177.       ATB_BAR_W_VAR_ID > 0 ? $game_variables[ATB_BAR_W_VAR_ID] : ATB_BAR_W
  178.     end # atb_bar_w
  179.  
  180.     def self.atb_bar_h
  181.       ATB_BAR_H_VAR_ID > 0 ? $game_variables[ATB_BAR_H_VAR_ID] : ATB_BAR_H
  182.     end # atb_bar_h
  183.  
  184.     def self.atb_bar_x
  185.       ATB_BAR_X_VAR_ID > 0 ? $game_variables[ATB_BAR_X_VAR_ID] : ATB_BAR_X
  186.     end # atb_bar_x
  187.  
  188.     def self.atb_bar_y
  189.       ATB_BAR_Y_VAR_ID > 0 ? $game_variables[ATB_BAR_Y_VAR_ID] : ATB_BAR_Y
  190.     end # atb_bar_y
  191.  
  192.     def self.atb_bar_z
  193.       ATB_BAR_Z_VAR_ID > 0 ? $game_variables[ATB_BAR_Z_VAR_ID] : ATB_BAR_Z
  194.     end # atb_bar_z
  195.  
  196.     def self.atb_back_color1
  197.       return ATB_BACK_COLOR1 if ATB_BACK_COLOR1_VAR_ID <= 0
  198.       $game_variables[ATB_BACK_COLOR1_VAR_ID]
  199.     end # atb_back_color1
  200.  
  201.     def self.atb_back_color2
  202.       return ATB_BACK_COLOR2 if ATB_BACK_COLOR2_VAR_ID <= 0
  203.       $game_variables[ATB_BACK_COLOR2_VAR_ID]
  204.     end # atb_back_color2
  205.  
  206.   end # BATB_Bar
  207.  
  208. end # DoubleX_RMVXA
  209.  
  210. if $doublex_rmvxa[:BATB]
  211.  
  212. class << BattleManager # v1.00b+; Edit
  213.  
  214.   #----------------------------------------------------------------------------|
  215.   #  New public instance variable                                              |
  216.   #----------------------------------------------------------------------------|
  217.   attr_accessor :batb_offset_change # The atb bar x/y offset changes notifier
  218.  
  219. end # BattleManager
  220.  
  221. #------------------------------------------------------------------------------|
  222. #  * Hosts battler sprite atb bars                                             |
  223. #------------------------------------------------------------------------------|
  224. class Sprite_Battler < Sprite_Base # Edit
  225.  
  226.   #----------------------------------------------------------------------------|
  227.   #  New private instance variable                                             |
  228.   #----------------------------------------------------------------------------|
  229.   # @batb_bars: The battler's atb bars
  230.  
  231.   alias initialize_batb initialize
  232.   def initialize(viewport, battler = nil)
  233.     initialize_batb(viewport, battler)
  234.     # Added
  235.     return unless @battler
  236.     return unless @battler.enemy? || DoubleX_RMVXA::BATB_Bar.atb_bar_actor
  237.     create_batb_bars
  238.     #
  239.   end # initialize
  240.  
  241.   alias dispose_batb dispose
  242.   def dispose
  243.     dispose_batb
  244.     @batb_bars.each_value { |bar| bar.dispose } if @batb_bars # Added
  245.   end # dispose
  246.  
  247.   alias update_batb update
  248.   def update
  249.     update_batb
  250.     @batb_bars.each_value { |bar| bar.update } if @batb_bars # Added
  251.   end # update
  252.  
  253.   def create_batb_bars # New
  254.     @batb_bars = {
  255.       back: BATB_Bar.new(@battler, :back),
  256.       atb: BATB_Bar.new(@battler, :atb)
  257.     }
  258.   end # create_batb_bars
  259.  
  260. end # Sprite_Battler
  261.  
  262. #------------------------------------------------------------------------------|
  263. #  * Handles the battler's sprite atb bars                                     |
  264. #------------------------------------------------------------------------------|
  265. class BATB_Bar < Viewport # New
  266.  
  267.   #----------------------------------------------------------------------------|
  268.   #  Private instance variables                                                |
  269.   #----------------------------------------------------------------------------|
  270.   # @battler: The battler using the atb bar
  271.   # @last_x: The last atb bar x position
  272.   # @last_y: The last atb bar y position
  273.   # @plane: The plane with the bitmap drawing the atb bar
  274.   # @type: The atb bar type
  275.  
  276.   # type: The atb bar type
  277.   def initialize(battler, type)
  278.     @battler = battler
  279.     @type = type
  280.     bar = DoubleX_RMVXA::BATB_Bar
  281.     super(Rect.new(bar.atb_bar_x, bar.atb_bar_y, bar.atb_bar_w, bar.atb_bar_h))
  282.     @plane = Plane.new(self)
  283.     @plane.bitmap = Bitmap.new(rect.width, rect.height)
  284.     self.z = bar.atb_bar_z
  285.     update
  286.     draw_bars
  287.   end # initialize
  288.  
  289.   def dispose
  290.     return if @plane.disposed?
  291.     @plane.bitmap.dispose if @plane.bitmap
  292.     @plane.dispose
  293.     super
  294.   end # dispose
  295.  
  296.   def update_pos # v1.00b+
  297.     pos_change = @last_x != @battler.screen_x || @last_y != @battler.screen_y
  298.     return unless BattleManager.batb_offset_change || pos_change
  299.     @last_x = @battler.screen_x
  300.     @last_y = @battler.screen_y
  301.     rect.x = @last_x + DoubleX_RMVXA::BATB_Bar.atb_bar_x
  302.     rect.y = @last_y + DoubleX_RMVXA::BATB_Bar.atb_bar_y
  303.     BattleManager.batb_offset_change = false
  304.   end # update_pos
  305.  
  306.   if $doublex_rmvxa[:BATB_Delay]
  307.  
  308.   def update
  309.     super
  310.     self.visible = @battler.alive?
  311.     return unless visible
  312.     update_pos
  313.     return unless @type == :atb && @battler.batb_val_change
  314.     max = DoubleX_RMVXA::BATB_Delay.max_atb_val
  315.     batb_val = @battler.batb_val > max ? max : @battler.batb_val
  316.     rect.width = DoubleX_RMVXA::BATB_Bar.atb_bar_w * batb_val * 1.0 / max
  317.   end # update
  318.  
  319.   def draw_bars
  320.     dw = rect.width
  321.     dh = rect.height
  322.     colors = set_bar_colors
  323.     @plane.bitmap.gradient_fill_rect(0, 0, dw, dh, colors[0], colors[1])
  324.   end # draw_bars
  325.  
  326.   def set_bar_colors
  327.     if @type == :back
  328.       bar = DoubleX_RMVXA::BATB_Bar
  329.       return [bar_color(bar.atb_back_color1), bar_color(bar.atb_back_color2)]
  330.     end
  331.     if @battler.batb_val <= DoubleX_RMVXA::BATB_Delay.max_atb_val
  332.       batb = DoubleX_RMVXA::BATB
  333.       return [bar_color(batb.atb_bar_color1), bar_color(batb.atb_bar_color2)]
  334.     end
  335.     delay = DoubleX_RMVXA::BATB_Delay
  336.     [bar_color(delay.atb_overlay_color1), bar_color(delay.atb_overlay_color2)]
  337.   end # set_bar_colors
  338.  
  339.   else
  340.  
  341.   def update
  342.     super
  343.     self.visible = @battler.alive?
  344.     return unless visible
  345.     update_pos
  346.     return unless @type == :atb && @battler.batb_val_change
  347.     rect.width = DoubleX_RMVXA::BATB_Bar.atb_bar_w * @battler.batb_val / 100.0
  348.   end # update
  349.  
  350.   def draw_bars
  351.     dw = rect.width
  352.     dh = rect.height
  353.     if @type == :atb
  354.       color1 = bar_color(DoubleX_RMVXA::BATB.atb_bar_color1)
  355.       color2 = bar_color(DoubleX_RMVXA::BATB.atb_bar_color2)
  356.     else
  357.       color1 = bar_color(DoubleX_RMVXA::BATB_Bar.atb_back_color1)
  358.       color2 = bar_color(DoubleX_RMVXA::BATB_Bar.atb_back_color2)
  359.     end
  360.     @plane.bitmap.gradient_fill_rect(0, 0, dw, dh, color1, color2)
  361.   end # draw_bars
  362.  
  363.   end # if $doublex_rmvxa[:BATB_Delay]
  364.  
  365.   #----------------------------------------------------------------------------|
  366.   #  Helper method simplifying the uses of the bar colors                      |
  367.   #----------------------------------------------------------------------------|
  368.   # color: The text color code
  369.   def bar_color(color)
  370.     Cache.system("Window").get_pixel(64 + (color % 8) * 8, 96 + (color / 8) * 8)
  371.   end # bar_color
  372.  
  373. end # BATB_Bar
  374.  
  375. class Window_BattleStatus < Window_Selectable # v1.00b+; Edit
  376.  
  377.   #----------------------------------------------------------------------------|
  378.   #  Uses the defaults if the atb bars are drawn on the actors' sprites instead|
  379.   #----------------------------------------------------------------------------|
  380.   def draw_gauge_area_with_tp(rect, actor) # Rewrite
  381.     # Rewritten
  382.     if DoubleX_RMVXA::BATB_Bar.atb_bar_actor
  383.       draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  384.       draw_actor_mp(actor, rect.x + 82, rect.y, 64)
  385.       return draw_actor_tp(actor, rect.x + 156, rect.y, 64)
  386.     end
  387.     draw_actor_hp(actor, rect.x + 0, rect.y, 60)
  388.     draw_actor_mp(actor, rect.x + 64, rect.y, 60)
  389.     draw_actor_tp(actor, rect.x + 128, rect.y, 52)
  390.     draw_batb_bar(rect, actor, true) if actor
  391.     #
  392.   end # draw_gauge_area_with_tp
  393.  
  394.   #----------------------------------------------------------------------------|
  395.   #  Uses the defaults if the atb bars are drawn on the actors' sprites instead|
  396.   #----------------------------------------------------------------------------|
  397.   def draw_gauge_area_without_tp(rect, actor) # Rewrite
  398.     # Rewritten
  399.     if DoubleX_RMVXA::BATB_Bar.atb_bar_actor
  400.       draw_actor_hp(actor, rect.x + 0, rect.y, 134)
  401.       return draw_actor_mp(actor, rect.x + 144,  rect.y, 76)
  402.     end
  403.     draw_actor_hp(actor, rect.x + 0, rect.y, 72)
  404.     draw_actor_mp(actor, rect.x + 80,  rect.y, 72)
  405.     draw_batb_bar(rect, actor, false) if actor
  406.     #
  407.   end # draw_gauge_area_without_tp
  408.  
  409. end # Window_BattleStatus
  410.  
  411. class Scene_Battle < Scene_Base # v1.00b+; Edit
  412.  
  413.   def batb_update # Rewrite
  414.     batb_update_turn(0)
  415.     BattleManager.batb_update
  416.     list = BattleManager.action_battlers.select { |b| b.actor? && b.inputable? }
  417.     list.collect! { |battler| battler.index }
  418.     batb_update_windows(list) unless list.include?(@status_window.index)
  419.     return if DoubleX_RMVXA::BATB_Bar.atb_bar_actor # Added
  420.     @status_window.refresh_batb_bars
  421.   end # batb_update
  422.  
  423. end # Scene_Battle
  424.  
  425. #------------------------------------------------------------------------------|
  426.  
  427. else
  428.  
  429.   # Informs users that they didn't place BATB above this script
  430.   msgbox("To use DoubleX RMVXA Basic ATB Delay, put it below:\n" +
  431.          "DoubleX RMVXA Basic ATB\nbut above Main")
  432.  
  433. end
  434.  
  435. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement