Advertisement
modern_algebra

Damage Popup 1.0b

Jun 19th, 2011
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.38 KB | None | 0 0
  1. #==============================================================================
  2. #    Damage Popup
  3. #    Version: 1.0b
  4. #    Author: modern algebra (rmrk.net)
  5. #    Date: September 8, 2009
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. #  Description:
  8. #    
  9. #    This script allows damage to popup on top of the battler, rather than
  10. #   being shown in the message box.
  11. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. #  Instructions:
  13. #
  14. #    Place this script above Main and below other custom scripts. Please see
  15. #   the editable region beginning at line 35 for configuration options.
  16. #
  17. #    To change the text shown when a critical hit is landed, or the target is
  18. #   missed or the target evades, you will need to go up to the Vocab module
  19. #   (the very first script in the editor) and change the values of the
  20. #   following constants:
  21. #        
  22. #      CriticalToActor
  23. #      CriticalToEnemy
  24. #      ActorNoHit
  25. #      ActorEvasion
  26. #      EnemyNoHit
  27. #      EnemyEvasion
  28. #==============================================================================
  29.  
  30. #================================================================================
  31. # *** Module ModernAlgebra
  32. #================================================================================
  33.  
  34. module ModernAlgebra
  35.   #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
  36.   #  EDITABLE REGION
  37.   #````````````````````````````````````````````````````````````````````````````
  38.   #  Please read the comments above each constant to learn what it controls.
  39.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  40.   #  DP_VANISH_SPEED controls the number of frames a damage pop sprite remains
  41.   # visible. There are 60 frames in a second.
  42.   DP_VANISH_SPEED = 60
  43.   #  DP_PLUS_X and DP_PLUS_Y control the position of the damage pop sprites,
  44.   # with reference to the centre bottom of the damaged battler. Keep in mind
  45.   # that the damage pop is centred on a 200 pixel bitmap, so a DP_PLUS_X of
  46.   # -100 would have the text centred on the battler.
  47.   DP_PLUS_X = -100
  48.   DP_PLUS_Y = -50
  49.   #  DP_FONT is the font used for displaying the damage popup. When it is an
  50.   # array, that is the priority in which fonts are checked. So, for instance:
  51.   # ["Verdana", "Arial", "Courier New"] would mean that the font would be
  52.   # Verdana by default. If the player doesn't have Verdana installed, it would
  53.   # be Arial, and if the player doesn't have Arial installed, it would be
  54.   # Courier New.
  55.   DP_FONT = ["Verdana", "Arial", "Courier New"]
  56.   #  DP_SIZE is the size of the damage popup text.
  57.   DP_SIZE = 28
  58.   #  The _COLOR constants below control the colour of the damage popup in their
  59.   # respective situations and are arrays holding the [red, green, blue] values
  60.   # of the colour.
  61.   # HPDAMAGE is the colour for when the target's HP is decreased
  62.   DP_HPDAMAGE_COLOR = [255, 0, 0]
  63.   # MPDAMAGE is the colour for when the target's MP is decreased
  64.   DP_MPDAMAGE_COLOR = [255, 20, 180]
  65.   # HPHEAL is the colour for when the target's HP is increased
  66.   DP_HPHEAL_COLOR = [0, 255, 0]
  67.   # MPHEAL is the colour for when the target's MP is increased
  68.   DP_MPHEAL_COLOR = [0, 0, 255]
  69.   # CRIT is the colour for when the target receives a critical hit
  70.   DP_CRIT_COLOR = [255, 0, 0]
  71.   #  MISS is the colour for when the target evades or is otherwise missed
  72.   DP_MISS_COLOR = [255, 255, 255]
  73.   #  If you still want damage to show up in the message box as well, change
  74.   # this value to true. false means the damage won't show up in the message
  75.   # box and only show up as a popup.
  76.   DP_SHOW_DAMAGE_IN_MESSAGE = false
  77.   #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  78.   #  END EDITABLE REGION
  79.   #////////////////////////////////////////////////////////////////////////////
  80. end
  81.  
  82. #==============================================================================
  83. # ** Game Battler
  84. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  85. #  Summary of Changes:
  86. #    new instance variables - dp_hp_damage_pop, dp_mp_damage_pop, dp_crit_pop,
  87. #      dp_miss_pop
  88. #    aliased method - execute_damage
  89. #==============================================================================
  90.  
  91. class Game_Battler
  92.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93.   # * Public Instance Variables
  94.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95.   attr_accessor :dp_hp_damage_pop
  96.   attr_accessor :dp_mp_damage_pop
  97.   attr_accessor :dp_crit_pop
  98.   attr_accessor :dp_miss_pop
  99.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100.   # * Damage Reflection
  101.   #     user : User of skill or item
  102.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103.   alias mdrnal_joy_exctdmge_dmgpop_1sd3 execute_damage
  104.   def execute_damage (user, *args)
  105.     @dp_crit_pop = actor? ? Vocab::CriticalToActor : Vocab::CriticalToEnemy if @critical
  106.     @dp_hp_damage_pop = @hp_damage if @hp_damage != 0
  107.     @dp_mp_damage_pop = @mp_damage if @mp_damage != 0
  108.     if @absorbed
  109.       user.dp_hp_damage_pop = (-1*@hp_damage) if @hp_damage != 0
  110.       user.dp_mp_damage_pop = (-1*@mp_damage) if @mp_damage != 0
  111.     end
  112.     mdrnal_joy_exctdmge_dmgpop_1sd3 (user, *args)
  113.   end
  114. end
  115.  
  116. #==============================================================================
  117. # ** Sprite Battler
  118. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  119. #  Summary of Changes:
  120. #    aliased method - initialize, update
  121. #    new methods - dp_start_damage_pop, dp_update_damage_pop
  122. #==============================================================================
  123.  
  124. class Sprite_Battler
  125.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126.   # * Object Initialization
  127.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128.   alias modalg_joy_init_dmgpop_7df5 initialize
  129.   def initialize (*args)
  130.     @damage_pop_sprites = []
  131.     @damage_pop_frames = []
  132.     modalg_joy_init_dmgpop_7df5 (*args) # Run Original Method
  133.   end
  134.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135.   # * Frame Update
  136.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137.   alias mdrnalg_jy_lufiaii_dmgpop_upd_1bd3 update
  138.   def update (*args)
  139.     mdrnalg_jy_lufiaii_dmgpop_upd_1bd3 (*args) # Run Original Method
  140.     dp_update_damage_pop unless @battler.nil?
  141.   end
  142.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143.   # * Start Damage Pop
  144.   #    type   : Whether HP, MP Damage
  145.   #    damage : The amount to display
  146.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147.   def dp_start_damage_pop (damage, type = 0)
  148.     # Create Damage Sprite
  149.     sprite = Sprite_Base.new
  150.     sprite.bitmap = Bitmap.new (200, ModernAlgebra::DP_SIZE)
  151.     # Get color of damage
  152.     sprite.bitmap.font = Font.new (ModernAlgebra::DP_FONT, ModernAlgebra::DP_SIZE)
  153.     sprite.bitmap.font.size -= 4 if type > 1
  154.     sprite.bitmap.font.color = case type
  155.     when 0 then damage > 0 ? Color.new (*ModernAlgebra::DP_HPDAMAGE_COLOR) : Color.new (*ModernAlgebra::DP_HPHEAL_COLOR)
  156.     when 1 then damage > 0 ? Color.new (*ModernAlgebra::DP_MPDAMAGE_COLOR) : Color.new (*ModernAlgebra::DP_MPHEAL_COLOR)
  157.     when 2 then Color.new (*ModernAlgebra::DP_MISS_COLOR)
  158.     when 3 then Color.new (*ModernAlgebra::DP_CRIT_COLOR)
  159.     end
  160.     damage_string = damage.is_a? (String) ? damage : damage.abs.to_s
  161.     sprite.bitmap.draw_text (0, 0, 200, ModernAlgebra::DP_SIZE, damage_string, 1)
  162.     sprite.x = self.x + ModernAlgebra::DP_PLUS_X
  163.     sprite.y = @damage_pop_sprites.empty? ? self.y + ModernAlgebra::DP_PLUS_Y : @damage_pop_sprites[-1].y + 24
  164.     sprite.z = self.z + 20
  165.     @damage_pop_sprites.push (sprite)
  166.     @damage_pop_frames.push (0)
  167.   end
  168.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169.   # * Update Damage Pop
  170.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171.   def dp_update_damage_pop
  172.     # Start New Damage Pops
  173.     dp_start_damage_pop (@battler.dp_miss_pop, 2) if @battler.dp_miss_pop != nil
  174.     dp_start_damage_pop (@battler.dp_crit_pop, 3) if @battler.dp_crit_pop != nil
  175.     dp_start_damage_pop (@battler.dp_hp_damage_pop) if @battler.dp_hp_damage_pop != nil
  176.     dp_start_damage_pop (@battler.dp_mp_damage_pop, 1) if @battler.dp_mp_damage_pop != nil
  177.     @battler.dp_hp_damage_pop = nil
  178.     @battler.dp_mp_damage_pop = nil
  179.     @battler.dp_miss_pop = nil
  180.     @battler.dp_crit_pop = nil
  181.     # Store sprites to dispose
  182.     dispose_indices = []
  183.     opac_minus = 255 / ModernAlgebra::DP_VANISH_SPEED
  184.     @damage_pop_sprites.each_index { |i|
  185.       if @damage_pop_frames[i] == ModernAlgebra::DP_VANISH_SPEED
  186.         dispose_indices.push (i)
  187.         next
  188.       end
  189.       sprite = @damage_pop_sprites[i]
  190.       sprite.update
  191.       sprite.y -= 1 if @damage_pop_frames[i] % 2 == 0
  192.       sprite.opacity -= opac_minus
  193.       @damage_pop_frames[i] += 1
  194.     }
  195.     # Dispose finished damage sprites
  196.     dispose_indices.reverse.each { |i|
  197.       @damage_pop_sprites[i].dispose
  198.       @damage_pop_sprites.delete_at (i)
  199.       @damage_pop_frames.delete_at (i)
  200.     }
  201.   end
  202. end
  203.  
  204. #==============================================================================
  205. # ** Window Battle Message
  206. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  207. #  Summary of Changes:
  208. #    aliased method - initialize, add_instant_text
  209. #==============================================================================
  210.  
  211. class Window_BattleMessage
  212.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  213.   # * Public Instance Variables
  214.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  215.   attr_accessor :dp_ignore_instant_text
  216.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217.   # * Object Initialization
  218.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  219.   alias algbra_popdamge_joy_initz_2fb5 initialize
  220.   def initialize (*args)
  221.     @dp_ignore_instant_text = false
  222.     # Run Original Method
  223.     algbra_popdamge_joy_initz_2fb5 (*args)
  224.   end
  225.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226.   # * Add Text
  227.   #     text : Text to be added
  228.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229.   alias mdrnalg_damagepopper_oyj_adintxt_4jk2 add_instant_text
  230.   def add_instant_text (*args)
  231.     return if @dp_ignore_instant_text
  232.     # Run Original Method
  233.     mdrnalg_damagepopper_oyj_adintxt_4jk2 (*args)
  234.   end
  235. end
  236.  
  237. #==============================================================================
  238. # ** Scene Battle
  239. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  240. #  Summary of Changes:
  241. #    aliased methods - display_action_effects, display_state_changes
  242. #==============================================================================
  243.  
  244. class Scene_Battle
  245.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  246.   # * Display Action Effects
  247.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  248.   alias mdnalbra_jy_dispactefct_dmgpop_9jv2 display_action_effects
  249.   def display_action_effects (target, *args)
  250.     if target.missed
  251.       target.dp_miss_pop = target.actor? ? sprintf(Vocab::ActorNoHit, target.name) : sprintf(Vocab::EnemyNoHit, target.name)
  252.     elsif target.evaded
  253.       target.dp_miss_pop = target.actor? ? sprintf(Vocab::ActorEvasion, target.name) : sprintf(Vocab::EnemyEvasion, target.name)
  254.     end
  255.     @message_window.dp_ignore_instant_text = true unless ModernAlgebra::DP_SHOW_DAMAGE_IN_MESSAGE || target.actor?
  256.     mdnalbra_jy_dispactefct_dmgpop_9jv2 (target, *args) # Run Original Method
  257.     @message_window.dp_ignore_instant_text = false
  258.   end
  259.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  260.   # * Display State Changes
  261.   #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  262.   alias mdrnag_joy_dspsttchng_dmpp_8jh3 display_state_changes
  263.   def display_state_changes (*args)
  264.     # Save value of ignore text
  265.     old_ignore_val = @message_window.dp_ignore_instant_text
  266.     @message_window.dp_ignore_instant_text = false
  267.     mdrnag_joy_dspsttchng_dmpp_8jh3 (*args) # RUn Original Method
  268.     @message_window.dp_ignore_instant_text = old_ignore_val
  269.   end
  270. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement