Main Menu
  • Welcome to The RPG Maker Resource Kit.

Damage Popup 1.0

Started by modern algebra, August 14, 2009, 03:41:01 AM

0 Members and 2 Guests are viewing this topic.

modern algebra

Damage Popup
Version: 1.0b
Author: modern algebra
Date: September 8, 2009

Version History




  • <Version 1.0b> 09.08.2009 - Fixed bug that occured with less than four members in the party
  • <Version 1.0> 08.14.2009 - Original Release

Description



This script allows damage to popup on top of the battler, rather than being shown in the message box.

Features


  • A simple rise & fade effect for the damage popup
  • Lots of configuration options, including position, colors based on damage type, size, font, vanish speed and more

Screenshots



Instructions


 Place this script above Main and below other custom scripts. Please see the editable region beginning at line 35 for configuration options.

 To change the text shown when a critical hit is landed, or the target is missed or the target evades, you will need to go up to the Vocab module (the very first script in the editor) and change the values of the following constants:


  • CriticalToActor
  • CriticalToEnemy
  • ActorNoHit
  • ActorEvasion
  • EnemyNoHit
  • EnemyEvasion

Script




#==============================================================================
#    Damage Popup
#    Version: 1.0b
#    Author: modern algebra (rmrk.net)
#    Date: September 8, 2009
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#    
#    This script allows damage to popup on top of the battler, rather than
#   being shown in the message box.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#
#    Place this script above Main and below other custom scripts. Please see
#   the editable region beginning at line 35 for configuration options.
#
#    To change the text shown when a critical hit is landed, or the target is
#   missed or the target evades, you will need to go up to the Vocab module
#   (the very first script in the editor) and change the values of the
#   following constants:
#      
#      CriticalToActor
#      CriticalToEnemy
#      ActorNoHit
#      ActorEvasion
#      EnemyNoHit
#      EnemyEvasion
#==============================================================================

#================================================================================
# *** Module ModernAlgebra
#================================================================================

module ModernAlgebra
 #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 #  EDITABLE REGION
 #````````````````````````````````````````````````````````````````````````````
 #  Please read the comments above each constant to learn what it controls.
 #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 #  DP_VANISH_SPEED controls the number of frames a damage pop sprite remains
 # visible. There are 60 frames in a second.
 DP_VANISH_SPEED = 60
 #  DP_PLUS_X and DP_PLUS_Y control the position of the damage pop sprites,
 # with reference to the centre bottom of the damaged battler. Keep in mind
 # that the damage pop is centred on a 200 pixel bitmap, so a DP_PLUS_X of
 # -100 would have the text centred on the battler.
 DP_PLUS_X = -100
 DP_PLUS_Y = -50
 #  DP_FONT is the font used for displaying the damage popup. When it is an
 # array, that is the priority in which fonts are checked. So, for instance:
 # ["Verdana", "Arial", "Courier New"] would mean that the font would be
 # Verdana by default. If the player doesn't have Verdana installed, it would
 # be Arial, and if the player doesn't have Arial installed, it would be
 # Courier New.
 DP_FONT = ["Verdana", "Arial", "Courier New"]
 #  DP_SIZE is the size of the damage popup text.
 DP_SIZE = 28
 #  The _COLOR constants below control the colour of the damage popup in their
 # respective situations and are arrays holding the [red, green, blue] values
 # of the colour.
 # HPDAMAGE is the colour for when the target's HP is decreased
 DP_HPDAMAGE_COLOR = [255, 0, 0]
 # MPDAMAGE is the colour for when the target's MP is decreased
 DP_MPDAMAGE_COLOR = [255, 20, 180]
 # HPHEAL is the colour for when the target's HP is increased
 DP_HPHEAL_COLOR = [0, 255, 0]
 # MPHEAL is the colour for when the target's MP is increased
 DP_MPHEAL_COLOR = [0, 0, 255]
 # CRIT is the colour for when the target receives a critical hit
 DP_CRIT_COLOR = [255, 0, 0]
 #  MISS is the colour for when the target evades or is otherwise missed
 DP_MISS_COLOR = [255, 255, 255]
 #  If you still want damage to show up in the message box as well, change
 # this value to true. false means the damage won't show up in the message
 # box and only show up as a popup.
 DP_SHOW_DAMAGE_IN_MESSAGE = false
 #||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 #  END EDITABLE REGION
 #////////////////////////////////////////////////////////////////////////////
end

#==============================================================================
# ** Game Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new instance variables - dp_hp_damage_pop, dp_mp_damage_pop, dp_crit_pop,
#      dp_miss_pop
#    aliased method - execute_damage
#==============================================================================

class Game_Battler
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Public Instance Variables
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 attr_accessor :dp_hp_damage_pop
 attr_accessor :dp_mp_damage_pop
 attr_accessor :dp_crit_pop
 attr_accessor :dp_miss_pop
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Damage Reflection
 #     user : User of skill or item
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdrnal_joy_exctdmge_dmgpop_1sd3 execute_damage
 def execute_damage (user, *args)
   @dp_crit_pop = actor? ? Vocab::CriticalToActor : Vocab::CriticalToEnemy if @critical
   @dp_hp_damage_pop = @hp_damage if @hp_damage != 0
   @dp_mp_damage_pop = @mp_damage if @mp_damage != 0
   if @absorbed
     user.dp_hp_damage_pop = (-1*@hp_damage) if @hp_damage != 0
     user.dp_mp_damage_pop = (-1*@mp_damage) if @mp_damage != 0
   end
   mdrnal_joy_exctdmge_dmgpop_1sd3 (user, *args)
 end
end

#==============================================================================
# ** Sprite Battler
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - initialize, update
#    new methods - dp_start_damage_pop, dp_update_damage_pop
#==============================================================================

class Sprite_Battler
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Object Initialization
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias modalg_joy_init_dmgpop_7df5 initialize
 def initialize (*args)
   @damage_pop_sprites = []
   @damage_pop_frames = []
   modalg_joy_init_dmgpop_7df5 (*args) # Run Original Method
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Frame Update
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdrnalg_jy_lufiaii_dmgpop_upd_1bd3 update
 def update (*args)
   mdrnalg_jy_lufiaii_dmgpop_upd_1bd3 (*args) # Run Original Method
   dp_update_damage_pop unless @battler.nil?
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Start Damage Pop
 #    type   : Whether HP, MP Damage
 #    damage : The amount to display
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def dp_start_damage_pop (damage, type = 0)
   # Create Damage Sprite
   sprite = Sprite_Base.new
   sprite.bitmap = Bitmap.new (200, ModernAlgebra::DP_SIZE)
   # Get color of damage
   sprite.bitmap.font = Font.new (ModernAlgebra::DP_FONT, ModernAlgebra::DP_SIZE)
   sprite.bitmap.font.size -= 4 if type > 1
   sprite.bitmap.font.color = case type
   when 0 then damage > 0 ? Color.new (*ModernAlgebra::DP_HPDAMAGE_COLOR) : Color.new (*ModernAlgebra::DP_HPHEAL_COLOR)
   when 1 then damage > 0 ? Color.new (*ModernAlgebra::DP_MPDAMAGE_COLOR) : Color.new (*ModernAlgebra::DP_MPHEAL_COLOR)
   when 2 then Color.new (*ModernAlgebra::DP_MISS_COLOR)
   when 3 then Color.new (*ModernAlgebra::DP_CRIT_COLOR)
   end
   damage_string = damage.is_a? (String) ? damage : damage.abs.to_s
   sprite.bitmap.draw_text (0, 0, 200, ModernAlgebra::DP_SIZE, damage_string, 1)
   sprite.x = self.x + ModernAlgebra::DP_PLUS_X
   sprite.y = @damage_pop_sprites.empty? ? self.y + ModernAlgebra::DP_PLUS_Y : @damage_pop_sprites[-1].y + 24
   sprite.z = self.z + 20
   @damage_pop_sprites.push (sprite)
   @damage_pop_frames.push (0)
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Update Damage Pop
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 def dp_update_damage_pop
   # Start New Damage Pops
   dp_start_damage_pop (@battler.dp_miss_pop, 2) if @battler.dp_miss_pop != nil
   dp_start_damage_pop (@battler.dp_crit_pop, 3) if @battler.dp_crit_pop != nil
   dp_start_damage_pop (@battler.dp_hp_damage_pop) if @battler.dp_hp_damage_pop != nil
   dp_start_damage_pop (@battler.dp_mp_damage_pop, 1) if @battler.dp_mp_damage_pop != nil
   @battler.dp_hp_damage_pop = nil
   @battler.dp_mp_damage_pop = nil
   @battler.dp_miss_pop = nil
   @battler.dp_crit_pop = nil
   # Store sprites to dispose
   dispose_indices = []
   opac_minus = 255 / ModernAlgebra::DP_VANISH_SPEED
   @damage_pop_sprites.each_index { |i|
     if @damage_pop_frames[i] == ModernAlgebra::DP_VANISH_SPEED
       dispose_indices.push (i)
       next
     end
     sprite = @damage_pop_sprites[i]
     sprite.update
     sprite.y -= 1 if @damage_pop_frames[i] % 2 == 0
     sprite.opacity -= opac_minus
     @damage_pop_frames[i] += 1
   }
   # Dispose finished damage sprites
   dispose_indices.reverse.each { |i|
     @damage_pop_sprites[i].dispose
     @damage_pop_sprites.delete_at (i)
     @damage_pop_frames.delete_at (i)
   }
 end
end

#==============================================================================
# ** Window Battle Message
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - initialize, add_instant_text
#==============================================================================

class Window_BattleMessage
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Public Instance Variables
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 attr_accessor :dp_ignore_instant_text
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Object Initialization
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias algbra_popdamge_joy_initz_2fb5 initialize
 def initialize (*args)
   @dp_ignore_instant_text = false
   # Run Original Method
   algbra_popdamge_joy_initz_2fb5 (*args)
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Add Text
 #     text : Text to be added
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdrnalg_damagepopper_oyj_adintxt_4jk2 add_instant_text
 def add_instant_text (*args)
   return if @dp_ignore_instant_text
   # Run Original Method
   mdrnalg_damagepopper_oyj_adintxt_4jk2 (*args)
 end
end

#==============================================================================
# ** Scene Battle
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased methods - display_action_effects, display_state_changes
#==============================================================================

class Scene_Battle
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Display Action Effects
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdnalbra_jy_dispactefct_dmgpop_9jv2 display_action_effects
 def display_action_effects (target, *args)
   if target.missed
     target.dp_miss_pop = target.actor? ? sprintf(Vocab::ActorNoHit, target.name) : sprintf(Vocab::EnemyNoHit, target.name)
   elsif target.evaded
     target.dp_miss_pop = target.actor? ? sprintf(Vocab::ActorEvasion, target.name) : sprintf(Vocab::EnemyEvasion, target.name)
   end
   @message_window.dp_ignore_instant_text = true unless ModernAlgebra::DP_SHOW_DAMAGE_IN_MESSAGE || target.actor?
   mdnalbra_jy_dispactefct_dmgpop_9jv2 (target, *args) # Run Original Method
   @message_window.dp_ignore_instant_text = false
 end
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # * Display State Changes
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 alias mdrnag_joy_dspsttchng_dmpp_8jh3 display_state_changes
 def display_state_changes (*args)
   # Save value of ignore text
   old_ignore_val = @message_window.dp_ignore_instant_text
   @message_window.dp_ignore_instant_text = false
   mdrnag_joy_dspsttchng_dmpp_8jh3 (*args) # RUn Original Method
   @message_window.dp_ignore_instant_text = old_ignore_val
 end
end


Credit




  • modern algebra

Thanks


  • joy, for the initial request
  • Euphony, whose request inspired me to finish this script
  • the chromeninja, for reporting a bug in 1.0

Support



Please post in this topic at rmrk.net for support.

Known Compatibility Issues

It likely will not work with exotic CBSes. It also won't have any effect with sprites not subclasses of Sprite_Battler




modern algebra

Updated to 1.0b due to a bug found by thechromeninja

maximusmaxy

Hey, is there anyway that this code can be applied to the Character sets in the overworld. I'm making an RPG style action game and i want the numbers to pop up on the character sets not in battle mode.

modern algebra

The way I wrote it, not really. It would be easy to make a script that could, though.

maximusmaxy

Quote from: modern algebra on December 30, 2009, 02:49:10 PM
The way I wrote it, not really. It would be easy to make a script that could, though.

Do you know of any?

Mushu

I tried pasting this directly, pasting it from wordpad and notepad and none worked :P is there a download for it?

modern algebra


Mushu

Oh btw! I had my comp set to Japanese locale to play the 3D script and changing it back to American let me paste scripts normally, because after I changed the locale it pasted all the scripts wrong. Just an interesting tidbit xD

abitsicamica

Hey Modern Algebra, this is a very simple yet cool way of aesthetically improving one's overall gaming project. I would like to suggest color-coding the damage pop-ups depending on damage. For example, color white should be attributed to damages ranging from 0 - 300, yellow from 301 - 1500, orange from 1501 - 4500 and red from 4501 - 9999+. Just a suggestion! Very cool script though!

Mushu

Is there a version of this for ace or should I post a script request? :D