[XP] Damage Images

Started by G_G, January 16, 2011, 04:52:42 pm

Previous topic - Next topic

G_G

January 16, 2011, 04:52:42 pm Last Edit: January 19, 2011, 02:59:31 pm by game_guy
Damage Images
Authors: game_guy
Version: 1.4
Type: Damage Display
Key Term: Battle Add-on



Introduction

Want to spice up the way your damage looks? Tired of plain old text? Well now you can use images as a replacement for the text! Have different images for healing, dealing damage, miss and critical!


Features


  • Image for Normal Damage
  • Image for Healing Damage
  • Image for Miss
  • Image for Critical
  • Image for Defend (Blizz-ABS Only)
  • Image for Level Up (Blizz-ABS Only)
  • Basically Plug & Play



Screenshots

Spoiler: ShowHide



Demo

Self Extracting Archive (1.4)
Zip Archive (1.4)


Script

There are images you can use from the demo.
Spoiler: ShowHide

#===============================================================================
# Damage Images
# Author game_guy
# Version 1.4
#-------------------------------------------------------------------------------
# Intro:
# Want to spice up the way your damage looks? Tired of plain old text? Well
# now you can use images as a replacement for the text! Have different images
# for healing, dealing damage, miss and critical!
#
# Features:
# Image for Normal Damage
# Image for Healing Damage
# Image for Miss
# Image for Critical
# Basically Plug & Play
#
# Instructions:
# Go down to the config below and set all file names to the appropriate type
# of damage.
# -Setting up Images:
#  Creating the images for this to work is quite easy. The easiest ones to
#  create are the ones for Miss and Critical. For those two you just need an
#  image that says "Miss" and "Critical". The numbers take a little bit more
#  effort to setup but its still pretty simple.

#  You need 10x1 cells. Each cell goes horizontally across with the same width
#  and same height. You place numbers 0-9 in each of the cells in numeric order.
#  Then import it into pictures folder and you should be done.
#  e.g.
#  +---------------------------------------+
#  ¦ 0 ¦ 1 ¦ 2 ¦ 3 ¦ 4 ¦ 5 ¦ 6 ¦ 7 ¦ 8 ¦ 9 ¦
#  +---------------------------------------+
#
# Compatibility:
# Not tested with SDK.
# Won't work for any other damage appearance mods.
#
# Version History:
# v1.0
# -Initial release
# v1.1
# -Added support for Blizz-ABS
# v1.2beta
# -Fixed Damage numbers when Healing for Blizz-ABS
#  Possibly unstable. Overwrites method in BlizzABS::Utility class.
#  Not sure if it can or will cause any bugs.
# v1.2
# -Removed overwrite of Utility method
# v1.3
# -Added level up image for Blizz-ABS Only
# -Added defend image for Blizz-ABS Only
# v1.4
# -Fixed healing bug...again. ._.
#
# Credits:
# game_guy ~ For creating the script.
# Blizzard ~ LoL's damage appearance gave me the idea.
#===============================================================================
module GG_DamageImages
  NORMAL_FILE    = "dmg_normal"
  HEAL_FILE      = "dmg_heal"
  MISS_FILE      = "dmg_miss"
  CRITICAL_FILE  = "dmg_critical"
  LEVEL_UP_FILE  = "dmg_level"   # FOR BLIZZ-ABS ONLY!
  DEFEND_FILE    = "dmg_defend"  # FOR BLIZZ-ABS ONLY!
end
module RPG
#==============================================================================
# ** RPG::Sprite
#------------------------------------------------------------------------------
#  Processes effects applied to sprites.
#==============================================================================
  class Sprite < ::Sprite
    # Include Config Module
    include GG_DamageImages
    #--------------------------------------------------------------------------
    # * Damage
    #--------------------------------------------------------------------------
    def damage(value, critical)
      # dispose old damage
      dispose_damage
      # set heal and miss variables
      heal = false
      miss = false
      # if value is a number
      if value.is_a?(Numeric)
        # set damage_string to value
        damage_string = value.abs.to_s
        # set heal to true if value less then zero
        heal = value < 0 ? true : false
      else
        # set damage_string to value
        damage_string = value.to_s
        # set miss to true
        miss = true
      end
      # if miss
      if miss
        # load miss
        damage = MISS_FILE
      elsif heal
        # load heal
        damage = HEAL_FILE
      else
        # load normal
        damage = NORMAL_FILE
      end
      if critical
        # load critical
        crit = RPG::Cache.picture(CRITICAL_FILE)
      end
      # load image
      image = RPG::Cache.picture(damage)
      # set cell width
      cwidth = image.width / 10
      # set cell height
      cheight = image.height
      # set image height taking variables into accordance
      height = critical == true ? image.height + crit.height : image.height
      # set width according to amount of damage
      width = damage_string.size * cwidth
      # set x and y offset
      yy = 0
      xx = 0
      # if critical
      if critical
        # if damage width is less then critical's image width
        if width < crit.width
          # set x offset
          xx = crit.width / 2 - width / 2
          # set new width
          width = crit.width
          # set y offset
          yy = crit.height
        end
      end
      # create bitmap from width and height
      bitmap = Bitmap.new(width, height)
      # if value is a number
      if value.is_a?(Numeric)
        # iterate through damage_string
        for i in 0...damage_string.size
          # grab actual number from damage_string
          int = damage_string[i, 1].to_i
          # create rectangle according to int
          rect = Rect.new(int * cwidth, 0, cwidth, cheight)
          # draw number
          bitmap.blt(xx + i * cwidth, yy, image, rect)
        end
      else
        # set rectangle
        rect = Rect.new(0, 0, image.width, image.height)
        # set new bitmap
        bitmap = Bitmap.new(image.width, image.height)
        # draw miss image
        bitmap.blt(0, 0, image, rect)
      end
      # if critical
      if critical
        # create rectangle
        rect = Rect.new(0, 0, crit.width, crit.height)
        # draw critical image
        bitmap.blt(0, 0, crit, rect)
      end
      @_damage_sprite = ::Sprite.new(self.viewport)
      @_damage_sprite.bitmap = bitmap
      @_damage_sprite.ox = bitmap.width / 2
      @_damage_sprite.oy = 20
      @_damage_sprite.x = self.x
      @_damage_sprite.y = self.y - self.oy / 2
      @_damage_sprite.z = 3000
      @_damage_duration = 40
    end
  end
end
if $BlizzABS
class Sprite_Damage < Sprite
  include GG_DamageImages
  include BlizzABS
  def draw_damage(request)
    heal = false
    miss = false
    level = false
    defend = false
    real_damage = false
    case request.color
    when Cache::DMGColors['HP+A'], Cache::DMGColors['HP+E']
      heal = true
      real_damage = true
    when Cache::DMGColors['SP+A'], Cache::DMGColors['SP+E']
      heal = true
      real_damage = true
    when Cache::DMGColors[Cache::TXTDefend]
      defend = true
    when Cache::DMGColors[Cache::TXTMiss]
      miss = true
    when Cache::DMGColors[Cache::TXTLvlUp]
      level = true
    else
      real_damage = true
    end
    if real_damage
      value = request.damage.to_i.abs
      damage_string = value.to_s
    else
      value = request.damage
      damge_string = value.to_s
    end
    damage_string = value.to_s if damage_string == nil
    critical = request.critical
    if miss
      damage = MISS_FILE
    elsif level
      damage = LEVEL_UP_FILE
    elsif defend
      damage = DEFEND_FILE
    elsif heal
      damage = HEAL_FILE
    else
      damage = NORMAL_FILE
    end
    if critical
      crit = RPG::Cache.picture(CRITICAL_FILE)
    end
    image = RPG::Cache.picture(damage)
    cwidth = image.width / 10
    cheight = image.height
    height = critical == true ? image.height + crit.height : image.height
    width = damage_string.size * cwidth
    yy = 0
    xx = 0
    if critical
      if width < crit.width
        xx = crit.width / 2 - width / 2
        width = crit.width
        yy = crit.height
      end
    end
    bitmap = Bitmap.new(width, height)
    if value.is_a?(Numeric)
      for i in 0...damage_string.size
        int = damage_string[i, 1].to_i
        rect = Rect.new(int * cwidth, 0, cwidth, cheight)
        bitmap.blt(xx + i * cwidth, yy, image, rect)
      end
    else
      rect = Rect.new(0, 0, image.width, image.height)
      bitmap = Bitmap.new(image.width, image.height)
      bitmap.blt(0, 0, image, rect)
    end
    if critical
      rect = Rect.new(0, 0, crit.width, crit.height)
      bitmap.blt(0, 0, crit, rect)
    end
    self.bitmap = bitmap
    @critical = request.critical
  end
end
end



Instructions

In the script.


Compatibility

Not tested with SDK.
Most likely will not work with any other battle damage display mods.
Works with Blizz-ABS. Place below Blizz-ABS


Credits and Thanks


  • game_guy ~ For creating it.
  • Blizzard ~ For having a fancy visual damage display in LoL. (which inspired me)
  • winkio ~ Help with more efficient method for Blizz-ABS add-on



Author's Notes

Enjoy!

LiTTleDRAgo

is this can be used with blizz abs?

G_G

Possibly. Not tested. Could you test it out for me? I'm not sure if Blizz-ABS uses the same method name for drawing sprite damage. If you do test it out, place the script below Blizz-ABS.

LiTTleDRAgo

I tested it with blizz abs 2.8.0 and didn't have any effect

G_G

Alright. I'll try and make a plug-in for it then.

Blizzard

This should be easy enough. You have the SpriteDamage class (or a similar name) that you just need to adjust so it works fine.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

G_G

Updated to work with Blizz-ABS. Tested myself.

Storm

Whoa, worked with RPG and ABS (Blizz's one). Awesome game_guy. :D
I was working on the game called The Orion.
It would be nice if you can join our small community by sharing a little by little scripts/ideas at The Orion Forum

I am: RPG Maker XP Scripter
Project Working On: The Orion MMORPG Game, visit The Orion Forum for more information!
Visit my: Deviantart

LEVEL ME UP OR ELSE LEVEL ME DOWN, IT'S EASY! XD


LiTTleDRAgo

when I heal my character it shows damage sprite (dmg_normal.png) instead of healing sprite (dmg_heal.png)


G_G

Updated to 1.2beta

Its possible that it could be unstable. I rewrote a method in the Utility class in order for heal damage to work correctly. Now I won't know if I need to redo something or go about it a different way until someone runs into a bug or if winkio or blizzard takes a look at it.

All I did was remove all the times .abs were called from it. But it still may cause errors or bugs later on down the road.

Storm

Quote from: game_guy on January 17, 2011, 09:32:20 pm
Updated to 1.2beta

Its possible that it could be unstable. I rewrote a method in the Utility class in order for heal damage to work correctly. Now I won't know if I need to redo something or go about it a different way until someone runs into a bug or if winkio or blizzard takes a look at it.

All I did was remove all the times .abs were called from it. But it still may cause errors or bugs later on down the road.


How did you manage to read all the code in Blizz-ABS?? :wacko:
You are awesome!!! :haha:
I will use this if I make ABS games....
I was working on the game called The Orion.
It would be nice if you can join our small community by sharing a little by little scripts/ideas at The Orion Forum

I am: RPG Maker XP Scripter
Project Working On: The Orion MMORPG Game, visit The Orion Forum for more information!
Visit my: Deviantart

LEVEL ME UP OR ELSE LEVEL ME DOWN, IT'S EASY! XD


Ryex

Quote from: Storm on January 17, 2011, 09:49:46 pm
Quote from: game_guy on January 17, 2011, 09:32:20 pm
Updated to 1.2beta

Its possible that it could be unstable. I rewrote a method in the Utility class in order for heal damage to work correctly. Now I won't know if I need to redo something or go about it a different way until someone runs into a bug or if winkio or blizzard takes a look at it.

All I did was remove all the times .abs were called from it. But it still may cause errors or bugs later on down the road.


How did you manage to read all the code in Blizz-ABS?? :wacko:
You are awesome!!! :haha:
I will use this if I make ABS games....


simple answer, you don't. the few times I've extended Babs I only looked at the methods I needed to and I only retained the information long enough to write the script. I only know enough about the way Babs works to know where to look if I need to modify or extend something.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Storm

Quote from: Ryex on January 17, 2011, 10:42:18 pm
Quote from: Storm on January 17, 2011, 09:49:46 pm
Quote from: game_guy on January 17, 2011, 09:32:20 pm
Updated to 1.2beta

Its possible that it could be unstable. I rewrote a method in the Utility class in order for heal damage to work correctly. Now I won't know if I need to redo something or go about it a different way until someone runs into a bug or if winkio or blizzard takes a look at it.

All I did was remove all the times .abs were called from it. But it still may cause errors or bugs later on down the road.


How did you manage to read all the code in Blizz-ABS?? :wacko:
You are awesome!!! :haha:
I will use this if I make ABS games....


simple answer, you don't. the few times I've extended Babs I only looked at the methods I needed to and I only retained the information long enough to write the script. I only know enough about the way Babs works to know where to look if I need to modify or extend something.


Are you saying I'm walking on the difficult road while you are walking on the easy road? :???:
I will learn this script and Blizz-ABS then. Thanks for suggestions.
I was working on the game called The Orion.
It would be nice if you can join our small community by sharing a little by little scripts/ideas at The Orion Forum

I am: RPG Maker XP Scripter
Project Working On: The Orion MMORPG Game, visit The Orion Forum for more information!
Visit my: Deviantart

LEVEL ME UP OR ELSE LEVEL ME DOWN, IT'S EASY! XD


winkio

Quote from: game_guy on January 17, 2011, 09:32:20 pm
Updated to 1.2beta

Its possible that it could be unstable. I rewrote a method in the Utility class in order for heal damage to work correctly. Now I won't know if I need to redo something or go about it a different way until someone runs into a bug or if winkio or blizzard takes a look at it.

All I did was remove all the times .abs were called from it. But it still may cause errors or bugs later on down the road.


Wait, why would removing abs fix it?  Anyways, for a solution, I'd just alias it, and only do your processing if certain conditions are met (like healing, or whatever).

G_G

Because the .abs made the negative damage (the healing damage) into a positive damage. My script checks to see if the value is less then 0 that way it knows if its healing or not.  I wasn't sure if removing those would cause anything but when I did remove it I was pretty positive it wouldn't conflict with anything. But I wouldn't know. Blizz-ABS is very very complex to me. :S

Anyways I'm going to alias the method and do a few things to try and make it non conflicting.

winkio

oh, that's easy, you don't even need to do anything with the Blizz-ABS methods.  Just in your Damage_Sprite modifications, branch based on request.color

G_G

Updated to 1.3.

Added images for Defend and Level Up for the Blizz-ABS add-on. Removed method overwrite. Works like a charm now ;)

ShadowSaber

January 18, 2011, 09:47:40 pm #17 Last Edit: January 18, 2011, 09:49:01 pm by ShadowSaber
I get an error with this script, what should i do?




---edit : sorry I realized I placed the script wrong

Wizered67

Post the error message so someone can help.

ShadowSaber

Quote from: Wizered67 on January 18, 2011, 09:48:59 pm
Post the error message so someone can help.


nevermind, I placed the script above BABS that's why i got an error  :shy: