LiTTleDRAgo

[RGSS] Blizz ABS Hit & Damage Sprite

Mar 26th, 2015
335
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Blizz ABS Damage Sprite
  3. # Version: 2.00
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  6. #
  7. # Explanation :
  8. #
  9. # This script will change your character graphic while get damaged / healed
  10. #
  11. # Graphic required :
  12. # {Actor.name}_hit (ex : Aluxes_hit)
  13. # {Actor.name}_heal (ex : Aluxes_heal)
  14. #
  15. # Set any to nil if you don't want it
  16. #
  17. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  18.  
  19. class Map_Battler
  20.  
  21.   ANIDamage = 14                 # ID of the animation when character damaged
  22.   ANIHeal   = 22                 # ID of the animation when character healed
  23.   SPRDamage = '_hit'             # Sprite when character damaged
  24.   SPRHeal   = '_heal'            # Sprite when character healed
  25.  
  26.   alias sprite_animation_setup_hit_sprite sprite_animation_setup
  27.   def sprite_animation_setup(*args)
  28.     if @battler && (dif = @battler.hp - (@old_hp_ny ||= @battler.hp)) != 0
  29.       ani = dif > 0 ? ANIHeal : dif < 0 ? ANIDamage : nil
  30.       spr = dif > 0 ? SPRHeal : dif < 0 ? SPRDamage : nil
  31.       ani && @animation_id = ani
  32.       spr && setup_sprites_ex(spr, [6,6,6,6])  
  33.       return @old_hp_ny = @battler.hp
  34.     elsif @character_name_org != '' &&
  35.       (@current_sprite == SPRHeal || @current_sprite == SPRDamage)
  36.       @sframes[@sindex] -= 1
  37.       @sindex += 1 if @sframes[@sindex] <= 0
  38.       if @sindex >= @sframes.size
  39.         (@sindex = 0) && reset_sprites
  40.       else
  41.         @character_name = @character_name_org + @current_sprite
  42.       end
  43.       return
  44.     end
  45.     sprite_animation_setup_hit_sprite(*args)
  46.   end
  47.  
  48.   def setup_sprites_ex(type, frames = BlizzABS::Cache::FramesDefault)
  49.     return if check_char_exist(@character_name_org + type) == 'false'
  50.     @character_name = @character_name_org + (@current_sprite = type)
  51.     setup_frames(frames.clone)
  52.   end
  53.  
  54.   def check_char_exist(n)
  55.     return (@sprexist||={})[n] ||= RPG::Cache.character(n,0).to_s rescue 'false'
  56.   end
  57. end
RAW Paste Data