Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Simon Greedwell on February 05, 2014, 08:21:43 pm

Title: SP damage display
Post by: Simon Greedwell on February 05, 2014, 08:21:43 pm
I edited a HP draining script to drain SP. I'd like a way to differentiate between SP drain and normal, round-of-the-mill HP drain i.e different colored damage numbers or something like that.

This is the HP draining script
# HP Absorbption Skills 
# by RPG Advocate


# Sample code used for an 'absorb' common event:
#
#   absorb = $game_temp.damage_hook * -1
#   $scene.active_battler.damage = absorb
#   $scene.active_battler.damage_pop=true
#   $scene.active_battler.hp -= absorb


#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
#  This class handles temporary data that is not included with save data.
#  Refer to "$game_temp" for the instance of this class.
#==============================================================================

class Game_Temp
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :damage_hook              # damage hook
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias has_initialize initialize
  def initialize
    # Original call
    has_initialize
    # Initialize damage hook
    @damage_hook = 0
  end
end



#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
#  This class deals with battlers. It's used as a superclass for the Game_Actor
#  and Game_Enemy classes.
#==============================================================================

class Game_Battler
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
  alias has_skill_effect skill_effect
  def skill_effect(user, skill, dilute = 1)
    # Original call
    effective = has_skill_effect(user, skill)
    # Set hook to damage
    if self.damage.is_a?(Numeric)
      $game_temp.damage_hook += self.damage
    end
    # End Method
    return effective   
  end
end 
 

 
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
#  This class performs battle screen processing.
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :active_battler
  #--------------------------------------------------------------------------
  # * Frame Update (main phase step 1 : action preparation)
  #--------------------------------------------------------------------------
  alias has_up4s1 update_phase4_step1
  def update_phase4_step1
    # Reset damage hook
    $game_temp.damage_hook = 0
    # Original call
    has_up4s1
  end
end


And this is the edited SP draining common event call:

absorb = $game_temp.damage_hook * -1
$scene.active_battler.damage = absorb
$scene.active_battler.damage_pop=true
$scene.active_battler.sp -= absorb
Title: Re: SP damage display
Post by: KK20 on February 06, 2014, 05:01:32 pm
This is the method that draws the damage text

class RPG::Sprite < Sprite
  def damage(value, critical)
    dispose_damage
    if value.is_a?(Numeric)
      damage_string = value.abs.to_s
    else
      damage_string = value.to_s
    end
    bitmap = Bitmap.new(160, 48)
    bitmap.font.name = "Arial Black"
    bitmap.font.size = 32
    bitmap.font.color.set(0, 0, 0)
    bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
    bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
    bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
    if value.is_a?(Numeric) and value < 0
      bitmap.font.color.set(176, 255, 144) #<====================== Heal damage (green tint)
    else
      bitmap.font.color.set(255, 255, 255) #<====================== Normal damage (white)
    end
    bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
    if critical
      bitmap.font.size = 20
      bitmap.font.color.set(0, 0, 0)
      bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
      bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
      bitmap.font.color.set(255, 255, 255)
      bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
    end
    @_damage_sprite = ::Sprite.new(self.viewport)
    @_damage_sprite.bitmap = bitmap
    @_damage_sprite.ox = 80
    @_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

I'm not sure what would be the best way to change the colors. You could do something like turning on a switch in your common event and replacing the section above with

    if value.is_a?(Numeric) and value < 0
      if $game_switches[101]
        bitmap.font.color.set(0, 128, 255) #<====================== Heal SP damage (blue)
      else
        bitmap.font.color.set(176, 255, 144) #<====================== Heal damage (greenish)
      end
    else
      if $game_switches[101]
        bitmap.font.color.set(255, 128, 0) #<====================== Normal SP damage (orange)
      else
        bitmap.font.color.set(255, 255, 255) #<====================== Normal damage (white)
      end
    end
    $game_switches[101] = false # Turn the game switch off
Title: Re: SP damage display
Post by: Simon Greedwell on February 06, 2014, 08:43:47 pm
Where's that first method located? I can't seem to find in on my script database.
Title: Re: SP damage display
Post by: KK20 on February 07, 2014, 01:05:46 am
It's located in the help file.