Skills : Drain/Osmosis
#1
Kain Nobel
Version: 1.0

Introduction

This script is deticated to handling skills that absorb HP and SP. With this, you can set the custom font and display strings of HP/SP absorb damage and specify each skills direct, percent and allowed variance to absorb.

Features
  • Set Skills that can drain HP/SP
  • You can set the direct HP/SP drawn from each skill's damage
  • You can set the percent HP/SP drawn from each skill's damage
  • You can set a variance on HP/SP drawn from each skill's damage
  • Set the font/color and string display of absored HP/SP
  • Set the returning animation of absorbtion
  • Automatically applies Drain HP element tag to skills that drain HP.
  • Automatically applies Drain SP element tag to skills that drain SP.
  • Settings are all commented and easy for non-scripters to understand.
Script

Code:
#===============================================================================
# ** Skills : Drain/Osmosis
#===============================================================================

#-------------------------------------------------------------------------------
# * SDK Log
#-------------------------------------------------------------------------------
SDK.log('Skills.Drain/Osmosis', 'Kain Nobel ©', 2.0, '04.01.2009')
SDK.check_requirements(2.4, [1, 2])
#-------------------------------------------------------------------------------
# * SDK Enabled Test : Begin
#-------------------------------------------------------------------------------
if SDK.enabled?('Skills.Drain/Osmosis')

#===============================================================================
# ** RPG::Skill
#===============================================================================

class RPG::Skill
#=============================================================================
# ** RPG::Skill::Drain
#=============================================================================
module Drain
   #---------------------------------------------------------------------------
   # * HP Drain Element Tag ID (set inside Database/System tab).
   #---------------------------------------------------------------------------
   HP_Element_Tag = nil
   #---------------------------------------------------------------------------
   # * SP Drain Element Tag ID (set inside Database/System tab).
   #---------------------------------------------------------------------------
   SP_Element_Tag = nil
   #---------------------------------------------------------------------------
   # * Font Name for Drain Damage String.
   #---------------------------------------------------------------------------
   DamageFontName = "Arial Black"
   #---------------------------------------------------------------------------
   # * Font Size for Drain Damage String.
   #---------------------------------------------------------------------------
   DamageFontSize = 28
   #---------------------------------------------------------------------------
   # * Damage font for drain damage is bolded?
   #---------------------------------------------------------------------------
   DamageFontBold = false
   #---------------------------------------------------------------------------
   # * Damage font for drain damage is italicized?
   #---------------------------------------------------------------------------
   DamageFontItal = false
   #---------------------------------------------------------------------------
   # * Color for text outline displaying HP drain value.
   #---------------------------------------------------------------------------
   HP_ColorBack = Color.new(0, 160, 0)
   #---------------------------------------------------------------------------
   # * Color for main text color displaying HP drain value.
   #---------------------------------------------------------------------------
   HP_ColorMain = Color.new(0, 255, 0)
   #---------------------------------------------------------------------------
   # * Color for text outline displaying SP drain value.
   #---------------------------------------------------------------------------
   SP_ColorBack = Color.new(160, 0, 160)
   #---------------------------------------------------------------------------
   # * Color for main text color displaying SP drain value.
   #---------------------------------------------------------------------------
   SP_ColorMain = Color.new(255, 0, 255)
   #---------------------------------------------------------------------------
   # * Reformat the Damage String for draining HP    (ie "HP +[x]") [x] = value
   #---------------------------------------------------------------------------
   HP_DamageFormat = "HP +[x]"
   #---------------------------------------------------------------------------
   # * Reformat the Damage String for draining SP    (ie "HP +[x]") [x] = value
   #---------------------------------------------------------------------------
   SP_DamageFormat = "SP +[x]"
   #---------------------------------------------------------------------------
   # * Animation played to the reciever of drained HP/SP.      (skill_id => n)
   #---------------------------------------------------------------------------
   Animation   = {7 => 15}
   #---------------------------------------------------------------------------
   # * The percent to drain from damage inflicted on HP.       (skill_id => n)
   #---------------------------------------------------------------------------
   HP_Percent  = {1 => 100, 6 => 100, 7 => 100, 9 => 100}
   #---------------------------------------------------------------------------
   # * A direct value to drain from damage inflicted on HP.    (skill_id => n)
   #---------------------------------------------------------------------------
   HP_Direct   = {}
   #---------------------------------------------------------------------------
   # * Allowed variance to +/- from sub total HP drained.      (skill_id => n)
   #---------------------------------------------------------------------------
   HP_Variance = {}
   #---------------------------------------------------------------------------
   # * The percent to drain from damage inflicted on SP.       (skill_id => n)
   #---------------------------------------------------------------------------
   SP_Percent   = {}
   #---------------------------------------------------------------------------
   # * A direct value to drain from damage inflicted on SP.    (skill_id => n)
   #---------------------------------------------------------------------------
   SP_Direct    = {}
   #---------------------------------------------------------------------------
   # * Allowed variance to +/- from sub total SP drained.      (skill_id => n)
   #---------------------------------------------------------------------------
   SP_Variance = {}
   #---------------------------------------------------------------------------
   # * Critical Flag to be set when draining (this is an scripter thing...)
   #---------------------------------------------------------------------------
   Critical_Flag = "Drain/Osmosis"
   #---------------------------------------------------------------------------
   # * Default Settings (You might not want to modify these...)
   #---------------------------------------------------------------------------
   Animation.default   = 0
   HP_Percent.default  = 0
   HP_Direct.default   = 0
   HP_Variance.default = 0
   SP_Percent.default  = 0
   SP_Direct.default   = 0
   SP_Variance.default = 0
end
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :drainskill_rpgskill_initialize, :initialize
#-----------------------------------------------------------------------------
# * Object Initialization
#-----------------------------------------------------------------------------
def initialize
   drainskill_rpgskill_initialize
   if self.drain_hp? && !@element_set.include?(Drain::HP_Element_Tag)
     unless Drain::HP_Element_Tag.nil?
       @element_set << Drain::HP_Element_Tag
     end
   end
   if self.drain_sp? && !@element_set.include?(Drain::SP_Element_Tag)
     unless Drain::SP_Element_Tag.nil?
       @element_set << Drain::SP_Element_Tag
     end
   end
end
#-----------------------------------------------------------------------------
# * Drain Animation
#-----------------------------------------------------------------------------
def drain_animation
   return Drain::Animation[@id]
end
#-----------------------------------------------------------------------------
# * HP Drain Percent
#-----------------------------------------------------------------------------
def hp_drain_percent
   return Drain::HP_Percent[@id]
end
#-----------------------------------------------------------------------------
# * HP Drain Direct
#-----------------------------------------------------------------------------
def hp_drain_direct
   return Drain::HP_Direct[@id]
end
#-----------------------------------------------------------------------------
# * HP Drain Variance
#-----------------------------------------------------------------------------
def hp_drain_variance
   return Drain::HP_Variance[@id]
end
#-----------------------------------------------------------------------------
# * SP Drain Percent
#-----------------------------------------------------------------------------
def sp_drain_percent
   return Drain::SP_Percent[@id]
end
#-----------------------------------------------------------------------------
# * SP Drain Direct
#-----------------------------------------------------------------------------
def sp_drain_direct
   return Drain::SP_Direct[@id]
end
#-----------------------------------------------------------------------------
# * SP Drain Variance
#-----------------------------------------------------------------------------
def sp_drain_variance
   return Drain::SP_Variance[@id]
end
#-----------------------------------------------------------------------------
# * HP Drain
#-----------------------------------------------------------------------------
def hp_drain(value)
   unless hp_drain_percent.zero?
     value *= hp_drain_percent / 100.0
   end
   value += hp_drain_direct
   value += rand(2).zero? ? -hp_drain_variance : hp_drain_variance
   return Integer(value)
end
#-----------------------------------------------------------------------------
# * SP Drain
#-----------------------------------------------------------------------------
def sp_drain(value)
   unless sp_drain_percent.zero?
     value *= sp_drain_percent / 100.0
   end
   value += sp_drain_direct
   value += rand(2).zero? ? -sp_drain_variance : sp_drain_variance
   return Integer(value)
end
#-----------------------------------------------------------------------------
# * Drain?
#-----------------------------------------------------------------------------
def drain?
   return (hp_drain? || sp_drain?)
end
#-----------------------------------------------------------------------------
# * HP Drain?
#-----------------------------------------------------------------------------
def hp_drain?
   return (!hp_drain_percent.zero? || !hp_drain_direct.zero?)
end
#-----------------------------------------------------------------------------
# * SP Drain?
#-----------------------------------------------------------------------------
def sp_drain?
   return (!sp_drain_percent.zero? || !sp_drain_direct.zero?)
end
end

#===============================================================================
# ** Game_BattleAction
#===============================================================================


class Game_BattleAction
#-----------------------------------------------------------------------------
# * Public Instance Variables
#-----------------------------------------------------------------------------
attr_accessor :drain_hp
attr_accessor :drain_sp
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :drainskill_gmbtlact_clear, :clear
#-----------------------------------------------------------------------------
# * Clear
#-----------------------------------------------------------------------------
def clear
   drainskill_gmbtlact_clear
   @drain_hp = 0
   @drain_sp = 0
end
end

#===============================================================================
# ** Game_Battler
#===============================================================================

class Game_Battler
#-----------------------------------------------------------------------------
# * Public Instance Variables
#-----------------------------------------------------------------------------
attr_accessor :drain_animation
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :drainskill_gmbtlr_skilleffect, :skill_effect
#-----------------------------------------------------------------------------
# * Skill Effect
#-----------------------------------------------------------------------------
def skill_effect(user, skill)
   unless skill.drain?
     return drainskill_gmbtlr_skilleffect(user, skill)
   end
   old_hp, old_sp = self.hp, self.sp
   effective = drainskill_gmbtlr_skilleffect(user, skill)
   last_damage = self.damage
   self.damage = 0
   hit, hit_result = skill_effect_first_hit_result(user, skill)
   effective = skill_effect_effective_correction(effective, hit)
   if hit_result
     power = skill_effect_power(user, skill)
     rate = skill_effect_rate(user, skill)
     skill_effect_base_damage(power, rate)
     skill_effect_element_correction(skill)
     if self.damage > 0
       skill_effect_guard_correction
     end
     skill_effect_disperation(skill)
     hit, hit_result = skill_effect_second_hit_result(user, skill)
     effective = skill_effect_effective_correction(effective, hit)
   end
   if hit_result
     effective = true if skill_effect_physical_hit_result(skill)
     last_sp = self.sp
     self.sp -= self.damage
     effective = self.sp != last_sp
     @state_changed = false
     effective |= states_plus(skill.plus_state_set)
     effective |= states_minus(skill.minus_state_set)
     skill_effect_power0(skill)
   else
     skill_effect_miss
   end
   skill_effect_damagefix
   hp_drain = skill.hp_drain(old_hp - self.hp)
   sp_drain = skill.sp_drain(old_sp - self.sp)
   user.hp += [hp_drain, 0].max
   user.sp += [sp_drain, 0].max
   self.damage   = last_damage
   user.critical = RPG::Skill::Drain::Critical_Flag
   user.current_action.drain_hp ||= 0
   user.current_action.drain_sp ||= 0
   user.current_action.drain_hp += hp_drain
   user.current_action.drain_sp += sp_drain
   user.damage = Array.new
   user.damage << [user.current_action.drain_hp, 0].max
   user.damage << [user.current_action.drain_sp, 0].max
   unless skill.drain_animation.zero? || skill.drain_animation.nil?
     user.drain_animation = skill.drain_animation
   end
   return effective
end
end

#===============================================================================
# ** Scene_Battle
#===============================================================================

class Scene_Battle < SDK::Scene_Base
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :drainskill_scnbtl_updatep4s6,       :update_phase4_step6
#-----------------------------------------------------------------------------
# * Update Phase 4 : Step 6
#-----------------------------------------------------------------------------
def update_phase4_step6
   draining_battlers.each do |battler|
     battler.damage_pop = true
     unless battler.drain_animation == 0 || battler.drain_animation.nil?
       battler.animation_id = battler.drain_animation
       battler.animation_hit = true
       battler.drain_animation = nil
     end
   end
   drainskill_scnbtl_updatep4s6
end
#-----------------------------------------------------------------------------
# * Draining Battlers
#-----------------------------------------------------------------------------
def draining_battlers
   battlers = Array.new
   $game_party.actors.each do |actor|
     if actor.current_action.drain_hp || actor.current_action.drain_sp
       battlers << actor
     end
   end
   $game_troop.enemies.each do |enemy|
     if enemy.current_action.drain_hp || enemy.current_action.drain_sp
       battlers << enemy
     end
   end
   battlers.each {|battler|
     battler.current_action.drain_hp = nil
     battler.current_action.drain_sp = nil
   }
   return battlers
end
end

#===============================================================================
# ** RPG::Sprite
#===============================================================================

class RPG::Sprite < ::Sprite
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :drainskill_RPGsprite_damage, :damage
#-----------------------------------------------------------------------------
# * Damage
#-----------------------------------------------------------------------------
def damage(value, critical)
   unless value.is_a?(Array) && critical == RPG::Skill::Drain::Critical_Flag
     drainskill_RPGsprite_damage(value, critical)
     return
   end
   dispose_damage
   hp_drain = RPG::Skill::Drain::HP_DamageFormat.dup
   hp_drain.gsub!("[x]", "#{value[0]}")
   hp_drain.gsub!("+", "-") if value[0] < 0
   sp_drain = RPG::Skill::Drain::SP_DamageFormat.dup
   sp_drain.gsub!("[x]", "#{value[1]}")
   sp_drain.gsub!("+", "-") if value[1] < 0
   bitmap = Bitmap.new(160, 8 + (RPG::Skill::Drain::DamageFontSize * 2))
   bitmap.font.name    = RPG::Skill::Drain::DamageFontName
   bitmap.font.size    = RPG::Skill::Drain::DamageFontSize
   bitmap.font.bold    = RPG::Skill::Drain::DamageFontBold
   bitmap.font.italic  = RPG::Skill::Drain::DamageFontItal
   bitmap.font.color = RPG::Skill::Drain::HP_ColorBack
   bitmap.draw_text(-1, 12-1, 160, 40, hp_drain, 1)
   bitmap.draw_text(+1, 12-1, 160, 40, hp_drain, 1)
   bitmap.draw_text(-1, 12+1, 160, 40, hp_drain, 1)
   bitmap.draw_text(+1, 12+1, 160, 40, hp_drain, 1)
   bitmap.font.color = RPG::Skill::Drain::HP_ColorMain
   bitmap.draw_text(0, 12, 160, 40, hp_drain, 1)
   bitmap.font.color = RPG::Skill::Drain::SP_ColorBack
   y = bitmap.font.size + 2
   bitmap.draw_text(-1, y-1, 160, 40, sp_drain, 1)
   bitmap.draw_text(+1, y-1, 160, 40, sp_drain, 1)
   bitmap.draw_text(-1, y+1, 160, 40, sp_drain, 1)
   bitmap.draw_text(+1, y+1, 160, 40, sp_drain, 1)
   bitmap.font.color = RPG::Skill::Drain::SP_ColorMain
   bitmap.draw_text(0, y, 160, 40, sp_drain, 1)
   @_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

#-------------------------------------------------------------------------------
# * SDK Enabled Test : End
#-------------------------------------------------------------------------------
end

Instructions

Place below SDK, above main. Please read the instructions on the settings in the script, they are all commented and easy to understand. If you have any further questions please don't be shy to ask.

FAQ

I'll add later if need be...

Compatibility

Requires SDK 2.4 individual part labled "GAME_BATTLER#SKILL_EFFECT"

Scripts that remodel the damage display, it might not work on the return effect of HP/SP. If so, please contact me and I'll tinker with a patch if I have time.

Author's Notes

I'm going to remodel this script to work with weapons, armors and items later on, so please await the newer version(s).

Terms and Conditions

Free to use in non-commercial games, please ask permission before using commercially. At the very least, at least credit me if you use this.

Enjoy :D
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }


Messages In This Thread
Skills : Drain/Osmosis - by Kain Nobel - 04-19-2009, 01:11 PM
Skills : Drain/Osmosis - by DerVVulfman - 04-19-2009, 08:11 PM
Skills : Drain/Osmosis - by Kain Nobel - 05-18-2009, 11:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Klass Change & Skills XP kyonides 1 1,213 05-29-2023, 07:39 AM
Last Post: kyonides
   KDualWield & Accessory Skills XP kyonides 1 1,321 02-10-2023, 06:53 AM
Last Post: kyonides
   Draining Skills! / Compatible with ABSes and custom non-active BSes / No SDK required DrHouse93 0 4,830 06-24-2016, 11:43 AM
Last Post: DrHouse93
   Lycan Slip-Thru Items/Skills DerVVulfman 0 4,779 03-14-2013, 07:02 AM
Last Post: DerVVulfman
   Skills : Replacements Kain Nobel 0 4,800 12-29-2012, 07:16 AM
Last Post: Kain Nobel
   MrMo's Item-Using Skills DerVVulfman 0 5,356 04-05-2012, 03:52 AM
Last Post: DerVVulfman
   Passive Skills DVV DerVVulfman 12 23,975 08-03-2011, 03:53 AM
Last Post: DerVVulfman
   Conditional + Combo Skills Trickster 1 8,678 10-21-2010, 04:17 AM
Last Post: DerVVulfman
   FFIX Skills Learning System aka Equipment Skills, NEW!!! v2.3 (8-8-2010) Charlie Fleed 13 29,526 10-13-2010, 05:17 PM
Last Post: Charlie Fleed
   FFIX Skills Activation System, Version 0.3 Charlie Fleed 51 72,276 03-21-2010, 10:34 PM
Last Post: Charlie Fleed



Users browsing this thread: 1 Guest(s)