Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Don't remove this header!
- #-------------------------------------------------------------------------------
- # Enemy Custom Damage Popup + Enemy HP Bar
- # by Black Mage (https://burningwizard.wordpress.com/)
- # fix by Trihan
- #
- # Version : 1.7
- #
- # This script is commisioned by Batworks Software.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Version History
- #-------------------------------------------------------------------------------
- # 1.7 - Added state icons on enemies. (Trihan)
- #
- # 1.6 - Fixed memory leak with HP icons. (Trihan)
- #
- # 1.5 - Fix a bug where dead enemies still do regen check.
- # - Add option for buff debuff popup.
- #
- # 1.4 - Remove buff/debuff popup.
- #
- # 1.3 - Bugfix for Heal Over Time doesn't show the correct animation.
- # - Add setting for resisted and super effective popup.
- #
- # 1.2 - Add compatibility fix for Mog's Enemy Animation script where the sprite
- # position is changed in the background by the script.
- #
- # 1.1 - Add limit for the lowest Y coordinate position for enemy's HP icon to
- # ensure that the icon is always visible.
- #
- # 1.0 - Initial design.
- #-------------------------------------------------------------------------------
- #==============================================================================
- # This script requires Yanfly Damage Popup - Helladen Version. The script can
- # be found at the following link:
- #
- # https://forums.rpgmakerweb.com/index.php?threads/yanfly-damage-popup-1-0-4.12151/page-2#post-882832
- #==============================================================================
- #-------------------------------------------------------------------------------
- # Settings for damage popup.
- #-------------------------------------------------------------------------------
- module BLACK_DMG_POPUP
- DMG = { # animation id font size RGB
- 'normal' => [207, 24, [186,109,109]],
- 'critical' => [208, 40, [175,109,186]],
- #damage over time
- 'dot' => [209, 24, [186,185,109]],
- #damage recovered over time
- 'drecovot' => [212, 24, [118,187,228]],
- #damage recovered
- 'drecov' => [212, 24, [80,80,80]],
- #damage rate in range (0,1)
- 'resisted' => [210, 20, [186,109,109]],
- #damage rate > 1
- 'super_effective' => [211, 30, [186,109,109]],
- #buff
- 'buff' => [206, 24, [255,127,39]],
- #debuff
- 'debuff' => [206, 24, [128,0,128]]
- }
- end
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Settings for enemy HP icon.
- #-------------------------------------------------------------------------------
- module BLACK
- # This is the list of picture that will be used as enemy HP icon. The files
- # are located on Graphics\System. You can use any ammount of picture and the
- # script will adjust accordingly. The pictures must be ordered from the least
- # HP to the most HP.
- HP_IMAGES = ["skullb4", "skullb3", "skullb2", "skullb1"]
- # This is the number of icon that will show up on the screen when the enemy\
- # HP is full.
- HP_SECTIONS = 5
- # This is the width for each HP icon.
- HP_IMG_WIDTH = 16
- # This is the offset setting for the enemy HP icon.
- # x, y
- HP_OFFSET = [0, 0]
- # The y coordinate of the HP bar will never go below this value. Note that 0
- # is located at the top of the window. For this purposes, this value
- # overrides the offset setting in case there's conflict.
- Y_POS_LIMIT = 100
- STATE_SECTIONS = 5
- end
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # * Beyond this is the sacred land of code. You need programming qualification
- # to dwelve deeper, or it'll cause many unnecessary problems. Proceed on your
- # own risk.
- #-------------------------------------------------------------------------------
- #==============================================================================
- # Rewrite Damage_Popup constant to make the damage popup static.
- #==============================================================================
- class Sprite_Popup < Sprite_Base
- def update
- super
- #---
- if @flags.include?("critical") && YEA::BATTLE::FLASH_CRITICAL
- @hue_duration = 2 if @hue_duration == nil || @hue_duration == 0
- @hue_duration -= 1
- self.bitmap.hue_change(15) if @hue_duration <= 0
- end
- #---
- if @zoom_direction == "up"
- self.zoom_x = [self.zoom_x + 0.075, @target_zoom].min
- self.zoom_y = [self.zoom_y + 0.075, @target_zoom].min
- else
- self.zoom_x = [self.zoom_x - 0.075, @target_zoom].max
- self.zoom_y = [self.zoom_y - 0.075, @target_zoom].max
- end
- #---
- @full -= 1
- return if @full > 0
- self.opacity -= @fade
- end
- end
- #==============================================================================
- #==============================================================================
- # Compatibility fix for Enemy Animations Script.
- #==============================================================================
- class Game_Actor < Game_Battler
- # Redefine screen_x, screen_y to avoid endless loop inside Enemy Animations
- # script upon attacking enemy.
- undef screen_x; undef screen_y
- def b_screen_x; -50; end; def b_screen_y; -50; end
- end
- class Sprite_Popup < Sprite_Base
- # Redefine create_popup_bitmap to use the new method b_screen_x and
- # b_screen_y instead.
- def create_popup_bitmap
- b_settings = $game_temp.b_popup_settings
- rules_array = YEA::BATTLE::POPUP_RULES[@rules]
- bw = Graphics.width
- bw += 48 if @flags.include?("state")
- bh = Font.default_size * 3
- bitmap = Bitmap.new(bw, bh)
- bitmap.font.name = rules_array[8]
- size = @flags.include?("critical") ? rules_array[2] * 1.2 : rules_array[2]
- f_sz = b_settings[1]
- f_sz = 6 if f_sz < 6
- bitmap.font.size = f_sz
- bitmap.font.bold = rules_array[3]
- bitmap.font.italic = rules_array[4]
- if flags.include?("critical")
- crit = YEA::BATTLE::POPUP_RULES["CRITICAL"]
- bitmap.font.out_color.set(crit[5], crit[6], crit[7], 255)
- else
- bitmap.font.out_color.set(0, 0, 0, 255)
- end
- dx = 0; dy = 0; dw = 0
- dx += 24 if @flags.include?("state")
- dw += 24 if @flags.include?("state")
- if @flags.include?("state") || @flags.include?("buff")
- c_width = bitmap.text_size(@value).width
- icon_bitmap = $game_temp.iconset
- icon_index = flag_state_icon
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- bitmap.blt(dx+(bw-c_width)/2-36, (bh - 24)/2, icon_bitmap, rect, 255)
- end
- b_color = b_settings[2]
- bitmap.font.color.set(b_color[0],b_color[1],b_color[2])
- bitmap.draw_text(dx, dy, bw-dw, bh, @value, 1)
- self.bitmap = bitmap
- if @battler.class.name == 'Game_Enemy'
- self.x = @battler.screen_x
- else
- self.x = @battler.b_screen_x
- end
- self.x += rand(4) - rand(4) if @battler.sprite.popups.size >= 1
- self.x -= SceneManager.scene.spriteset.viewport1.ox
- if @battler.class.name == 'Game_Enemy'
- self.y = @battler.screen_y - @battler.sprite.oy/2
- else
- self.y = @battler.b_screen_y - @battler.sprite.oy/2
- end
- self.y -= @battler.sprite.oy/2 if @battler.actor?
- self.y -= SceneManager.scene.spriteset.viewport1.oy
- self.ox = bw/2; self.oy = bh/2
- self.zoom_x = self.zoom_y = rules_array[0]
- if @flags.include?("no zoom")
- self.zoom_x = self.zoom_y = rules_array[1]
- end
- @target_zoom = rules_array[1]
- @zoom_direction = (self.zoom_x > @target_zoom) ? "down" : "up"
- self.z = 500
- end
- end
- #==============================================================================
- #==============================================================================
- # Play animation when damage is shown.
- #==============================================================================
- class Game_Temp
- attr_accessor :b_popup_settings
- attr_accessor :on_regen
- alias b_ppp_init initialize
- def initialize
- b_ppp_init
- # trigger animation font size RGB DoT/HoT
- @b_popup_settings = [1, 24, [186,109,109], false]
- @on_regen = false
- end
- end
- class Game_BattlerBase
- include BLACK_DMG_POPUP
- def make_damage_popups(user)
- if @result.hp_drain != 0
- text = YEA::BATTLE::POPUP_SETTINGS[:drained]
- rules = "DRAIN"
- user.create_popup(text, rules)
- setting = :hp_dmg if @result.hp_drain < 0
- setting = :hp_heal if @result.hp_drain > 0
- rules = "HP_DMG" if @result.hp_drain < 0
- rules = "HP_HEAL" if @result.hp_drain > 0
- value = @result.hp_drain.abs
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
- user.create_popup(text, rules)
- end
- if @result.mp_drain != 0
- text = YEA::BATTLE::POPUP_SETTINGS[:drained]
- rules = "DRAIN"
- user.create_popup(text, rules)
- setting = :mp_dmg if @result.mp_drain < 0
- setting = :mp_heal if @result.mp_drain > 0
- rules = "HP_DMG" if @result.mp_drain < 0
- rules = "HP_HEAL" if @result.mp_drain > 0
- value = @result.mp_drain.abs
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
- user.create_popup(text, rules)
- end
- #---
- flags = []
- flags.push("critical") if @result.critical
- if @result.hp_damage != 0
- setting = :hp_dmg if @result.hp_damage > 0
- setting = :hp_heal if @result.hp_damage < 0
- rules = "HP_DMG" if @result.hp_damage > 0
- rules = "HP_HEAL" if @result.hp_damage < 0
- value = @result.hp_damage.abs
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
- create_popup(text, rules, flags)
- if self.class.name == 'Game_Enemy'
- type = 'normal'
- if setting == :hp_dmg
- type = 'critical' if @result.critical
- type = 'dot' if $game_temp.on_regen
- else
- type = 'drecov'
- type = 'drecovot' if $game_temp.on_regen
- end
- if type == 'normal'
- type = 'super_effective' if @result.get_popups[0].include?('WEAK_ELE')
- type = 'resisted' if @result.get_popups[0].include?('REST_ELE')
- end
- $game_temp.b_popup_settings = DMG[type]
- $game_temp.popup_anim_start = [true, self.screen_x, self.screen_y]
- SceneManager.scene.black_show_animation([self],DMG[type][0])
- end
- end
- if @result.mp_damage != 0
- setting = :mp_dmg if @result.mp_damage > 0
- setting = :mp_heal if @result.mp_damage < 0
- rules = "MP_DMG" if @result.mp_damage > 0
- rules = "MP_HEAL" if @result.mp_damage < 0
- value = @result.mp_damage.abs
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
- create_popup(text, rules, flags)
- end
- if @result.tp_damage != 0
- setting = :tp_dmg if @result.tp_damage > 0
- setting = :tp_heal if @result.tp_damage < 0
- rules = "TP_DMG" if @result.tp_damage > 0
- rules = "TP_HEAL" if @result.tp_damage < 0
- value = @result.tp_damage.abs
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[setting], value.group)
- create_popup(text, rules)
- end
- $game_temp.on_regen = false
- @result.store_damage
- @result.clear_damage_values
- end
- end
- class Game_ActionResult; def get_popups; @battler.popups; end; end
- class Game_Battler < Game_BattlerBase
- alias b_regen_all regenerate_all
- def regenerate_all; $game_temp.on_regen = true if alive?; b_regen_all; end
- end # Game_Battler
- class Scene_Battle < Scene_Base
- # Define an alternative of show_animation method to show enemy HP icon upon
- # popup triggered.
- def black_show_animation(targets, animation_id)
- targets[0].show_hp_icon
- if animation_id < 0; show_attack_animation(targets)
- else; show_normal_animation(targets, animation_id)
- end
- @log_window.wait; wait_for_animation; targets[0].hide_hp_icon
- end
- end
- # Define flag for when the popup animation is played.
- class Game_Temp
- attr_accessor :popup_anim_start
- alias init_b_ppp_anim initialize
- def initialize; init_b_ppp_anim; @popup_anim_start = [false, 0, 0]; end
- end
- # Reset animation origin when the animation is flagged as popup animation.
- class Sprite_Base < Sprite
- alias b_ppp_s_a_o set_animation_origin
- def set_animation_origin
- if @animation.position != 3 && $game_temp.popup_anim_start[0]
- b_set_animation_origin
- else
- b_ppp_s_a_o
- end
- end
- def b_set_animation_origin
- old_x = x; old_y = y
- x = $game_temp.popup_anim_start[1]
- y = $game_temp.popup_anim_start[2]
- @ani_ox = x - ox + width / 2
- @ani_oy = y - oy + height / 2
- if @animation.position == 0
- @ani_oy -= height / 2
- elsif @animation.position == 2
- @ani_oy += height / 2
- end
- x = old_x; y = old_y; $game_temp.popup_anim_start = [false, 0, 0]
- end
- end
- #==============================================================================
- #==============================================================================
- # Make state popup doesn't show.
- # Make miss, evade, and weakpoint popup doesn't show.
- #==============================================================================
- class Game_Battler < Game_BattlerBase
- def make_miss_popups(user, item); end
- end
- class Sprite_Battler < Sprite_Base
- alias b_c_n_ppp create_new_popup
- def create_new_popup(value, rules, flags)
- return if rules == "WEAK_ELE"
- return if rules == "IMMU_ELE"
- return if rules == "ABSB_ELE"
- return if rules == "REST_ELE"
- b_c_n_ppp(value, rules, flags)
- end
- end
- #==============================================================================
- #==============================================================================
- # Create and show Enemy HP Icon.
- #==============================================================================
- class Sprite_Battler < Sprite_Base
- include BLACK
- attr_accessor :enemy_hp_icon
- alias b_init_hp_icon initialize
- def initialize(viewport, battler = nil)
- b_init_hp_icon(viewport, battler)
- if @battler.class.name == 'Game_Enemy'
- @enemy_hp_icon = []
- HP_SECTIONS.times do |i|
- @enemy_hp_icon.push(Sprite.new)
- end
- enemy_hp_icon_update
- @enemy_state_icon = []
- STATE_SECTIONS.times do |i|
- @enemy_state_icon.push(Sprite.new)
- end
- enemy_state_icon_update
- end
- end
- def enemy_hp_icon_update
- percentage = @battler.hp.to_f*100.to_f/@battler.mhp.to_f
- treshold = (100.to_f/HP_SECTIONS.to_f)
- b_height = Cache.battler(@battler.battler_name, @battler.battler_hue).height
- ic_width = @enemy_hp_icon.size * HP_IMG_WIDTH
- @enemy_hp_icon.size.times do |i|
- opa = @battler.hp_icon ? 255 : 0; @enemy_hp_icon[i].opacity = opa
- if [i*treshold, 100.to_f].min <= percentage && (percentage - i*treshold)/treshold >= 1
- pic = HP_IMAGES.size - 1
- elsif (percentage - i*treshold)/treshold > 0
- pic = (((percentage - i*treshold)/treshold) * HP_IMAGES.size).ceil - 1
- else
- pic = -1
- end
- bmp = (pic == -1) ? nil : Cache.system(HP_IMAGES[pic])
- @enemy_hp_icon[i].bitmap = bmp
- @enemy_hp_icon[i].x = @battler.screen_x + (i*HP_IMG_WIDTH) - (ic_width/2) + HP_OFFSET[0]
- @enemy_hp_icon[i].y = [@battler.screen_y - b_height + HP_OFFSET[1],Y_POS_LIMIT].max
- end
- end
- def enemy_state_icon_update
- b_height = Cache.battler(@battler.battler_name, @battler.battler_hue).height
- ic_width = [@enemy_state_icon.size, @battler.state_icons.size].min * 24
- @enemy_state_icon.size.times do |i|
- opa = @battler.hp_icon ? 255 : 0; @enemy_state_icon[i].opacity = opa
- if @battler.state_icons[i] != nil
- @enemy_state_icon[i].bitmap = Bitmap.new(24, 24)
- icon_index = @battler.state_icons[i]
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- @enemy_state_icon[i].bitmap.blt(0, 0, bitmap, rect, 255)
- @enemy_state_icon[i].x = @battler.screen_x + (i*24) - (ic_width/2) + HP_OFFSET[0]
- @enemy_state_icon[i].y = @enemy_hp_icon[0].y + 40
- else
- @enemy_state_icon[i].bitmap = nil
- end
- end
- end
- alias b_hp_icon_updt update
- def update
- b_hp_icon_updt
- if @battler.class.name == 'Game_Enemy'
- enemy_hp_icon_update
- enemy_state_icon_update
- end
- end
- alias b_hp_icon_dispose dispose
- def dispose
- @enemy_hp_icon.each {|icon| icon.dispose} if @enemy_hp_icon
- @enemy_state_icon.each {|icon| icon.dispose} if @enemy_state_icon
- b_hp_icon_dispose
- end
- end
- class Game_Enemy < Game_Battler
- def show_hp_icon; @show_hp = true; end
- def hide_hp_icon; @show_hp = false; end
- def hp_icon; @show_hp; end
- end
- class Sprite_Battler
- alias b_hp_icon_upd_fx update_effect
- def update_effect(*args)
- if @battler.class.name == 'Game_Enemy'
- @battler.show_hp_icon if @effect_type == :select_white
- end
- b_hp_icon_upd_fx(*args)
- end
- alias b_hp_icon_revert revert_to_normal
- def revert_to_normal
- b_hp_icon_revert
- @battler.hide_hp_icon if @battler.class.name == 'Game_Enemy'
- end
- end
- #==============================================================================
- #==============================================================================
- # Version 1.5 Fix
- #==============================================================================
- # Removing popup that happened when a buff or debuff applied.
- class Game_BattlerBase
- #def make_buff_popup(param_id, positive = true); return; end
- def make_buff_popup(param_id, positive = true)
- return unless SceneManager.scene_is?(Scene_Battle)
- return unless alive?
- name = Vocab::param(param_id)
- if positive
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:add_buff], name)
- rules = "BUFF"
- type = "buff"
- buff_level = 1
- else
- text = sprintf(YEA::BATTLE::POPUP_SETTINGS[:add_debuff], name)
- rules = "DEBUFF"
- type = "debuff"
- buff_level = -1
- end
- icon = buff_icon_index(buff_level, param_id)
- flags = ["buff", icon]
- return if @popups.include?([text, rules, flags])
- $game_temp.b_popup_settings = DMG[type]
- create_popup(text, rules, flags)
- end
- end
- #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment