Jump to content
WCouillard

Kread-EX Vampiric Damage Mod?

Recommended Posts

OK, so, kinda stuck on another mod...

 

I have a script by Kread-EX that let's you assign a notetag to a state, and users with that state will absorb a certain amount of HP as designated by the notetag. What I want to do is also allow this notetag to apply to certain skills, rather than just states. I've successfully modified it to also be able to drain a portion on MP, but getting it to work with skills... not so much. Here is the original script...

 

# :=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  ▼ Vampire State
#  Author: Kread-EX
#
#  For Nessy.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

# Put <vampire: x%> in the state's notebox.

#===========================================================================
# ■ RPG::State
#===========================================================================

class RPG::State < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire
  #--------------------------------------------------------------------------
  def vampire
    @vampire ||= @note.match(/<vampire:\s*(\d+)%>/i) {$1.to_i}
    @vampire
  end
end

#===========================================================================
# ■ Game_Battler
#===========================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● Calculate damage
  #--------------------------------------------------------------------------
  alias_method(:krx_vs_gb_mdv, :make_damage_value)
  def make_damage_value(user, item)
    krx_vs_gb_mdv(user, item)
    vamp = user.states.select {|state| state.vampire != nil}
    if vamp && !vamp.empty?
      @result.hp_drain = (@result.hp_damage * vamp.first.vampire.fdiv(100)).round
    end
  end
end

And here is the modified one that also allows MP draining (for States). If anyone could help me to get this to work for specific skills as well as states, I'd love you forever.

 

NOTE: I also added a way to eliminate certain skill IDs from utilizing the vampiric state.

 

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  ▼ Vampire State
#  Author: Kread-EX
#
#  For Nessy.
#
#  Some additional functionality added by WCouillard
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Instructions
#
# Put <vampire: x%> in a state's notebox to allow the actor to absorb x% of
# the damage dealt as HP.
#
# Put <mpvampire: x%> in a state's notebox to allow the actor to absorb x% of
# the damage dealt as MP.
#===========================================================================
# ■ Module VAMP
#===========================================================================
module VAMP
  #--------------------------------------------------------------------------
  # ● List Skill ID's that ignore vampiric effects, even with state applied
  #--------------------------------------------------------------------------
  # ● NOTE: Important to include all HEALING abilities here
  #--------------------------------------------------------------------------
  IGNORE_SKILLS   = [89, 90, 91, 286, 288, 290, 291]
end
#===========================================================================
# ■ RPG::Skill
#===========================================================================

class RPG::Skill < RPG::UsableItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire skill
  #--------------------------------------------------------------------------
  def vampire
    @vampire ||= @note.match(/<vampire:\s*(\d+)%>/i) {$1.to_i}
    @vampire
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire skill
  #--------------------------------------------------------------------------
  def mpvampire
    @mpvampire ||= @note.match(/<mpvampire:\s*(\d+)%>/i) {$1.to_i}
    @mpvampire
  end
end
#===========================================================================
# ■ RPG::State
#===========================================================================

class RPG::State < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire state
  #--------------------------------------------------------------------------
  def vampire
    @vampire ||= @note.match(/<vampire:\s*(\d+)%>/i) {$1.to_i}
    @vampire
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire state
  #--------------------------------------------------------------------------
  def mpvampire
    @mpvampire ||= @note.match(/<mpvampire:\s*(\d+)%>/i) {$1.to_i}
    @mpvampire
  end
end

#===========================================================================
# ■ RPG::UsableItem
#===========================================================================

class RPG::UsableItem < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire
  #--------------------------------------------------------------------------
  def vampire
    @vampire ||= @note.match(/<vampire:\s*(\d+)%>/i) {$1.to_i}
    @vampire
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire
  #--------------------------------------------------------------------------
  def mpvampire
    @mpvampire ||= @note.match(/<mpvampire:\s*(\d+)%>/i) {$1.to_i}
    @mpvampire
  end
end

#===========================================================================
# ■ Game_Battler
#===========================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● Calculate damage
  #--------------------------------------------------------------------------
  alias_method(:krx_vs_gb_mdv, :make_damage_value)
  def make_damage_value(user, item)
    krx_vs_gb_mdv(user, item)
    vampskill = user.skills.select {|skill| skill.vampire != nil}
    mpvampskill = user.skills.select {|skill| skill.mpvampire != nil}
    vampstate = user.states.select {|state| state.vampire != nil}
    mpvampstate = user.states.select {|state| state.mpvampire != nil}
    if item.is_a?(RPG::Skill)
      for i in 0..VAMP::IGNORE_SKILLS.length
        if item.id.to_s == VAMP::IGNORE_SKILLS[i].to_s
          return
        end
      end
    end
    if vampskill && !vampskill.empty?
      @result.hp_drain = (@result.hp_damage * vampskill.first.vampire.fdiv(100)).round
    end
    if mpvampskill && !mpvampskill.empty?
      @result.mp_drain = (@result.hp_damage * mpvampskill.first.mpvampire.fdiv(100)).round
    end
    if vampstate && !vampstate.empty?
      @result.hp_drain = (@result.hp_damage * vampstate.first.vampire.fdiv(100)).round
    end
    if mpvampstate && !mpvampstate.empty?
      @result.mp_drain = (@result.hp_damage * mpvampstate.first.mpvampire.fdiv(100)).round
    end
  end
end

So, what happens is that any skill now drains, rather than only those with the notetag. Notetagging is something very new to me, despite using VX Ace for like a decade. I never really messed with it. Any assistance greatly appreciated. :D

Share this post


Link to post
Share on other sites

I edited the original script and implemented what you wanted to do.

Spoiler

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  ▼ Vampire State
#  Author: Kread-EX
#
#  For Nessy.
#
#  Some additional functionality added by WCouillard
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Instructions
#
# Put <vampire: x%> in a state's notebox to allow the actor to absorb x% of
# the damage dealt as HP.
#
# Put <mpvampire: x%> in a state's notebox to allow the actor to absorb x% of
# the damage dealt as MP.
#===========================================================================
# ■ Module VAMP
#===========================================================================
module VAMP
  #--------------------------------------------------------------------------
  # ● List Skill ID's that ignore vampiric effects, even with state applied
  #--------------------------------------------------------------------------
  # ● NOTE: Important to include all HEALING abilities here
  #--------------------------------------------------------------------------
  IGNORE_SKILLS   = [80, 90, 91, 286, 288, 290, 291]
end
#===========================================================================
# ■ RPG::Skill
#===========================================================================

class RPG::Skill < RPG::UsableItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire
  #--------------------------------------------------------------------------
  def vampire
    note =~ /<vampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire
  #--------------------------------------------------------------------------
  def mpvampire
    note =~ /<mpvampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
  
  def ignore_vampire
    note =~ /<Ignore vampire>/ ? true : false
  end
end
#===========================================================================
# ■ RPG::State
#===========================================================================

class RPG::State < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire
  #--------------------------------------------------------------------------
  def vampire
    note =~ /<vampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire
  #--------------------------------------------------------------------------
  def mpvampire
    note =~ /<mpvampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
end

#===========================================================================
# ■ RPG::UsableItem
#===========================================================================

class RPG::UsableItem < RPG::BaseItem
  #--------------------------------------------------------------------------
  # ● Determine if vampire
  #--------------------------------------------------------------------------
  def vampire
    note =~ /<vampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
  #--------------------------------------------------------------------------
  # ● Determine if mp vampire
  #--------------------------------------------------------------------------
  def mpvampire
    note =~ /<mpvampire:\s*(\d+)%>/ ? $1.to_i : 0
  end
end

#===========================================================================
# ■ Game_Battler
#===========================================================================

class Game_Battler < Game_BattlerBase
  #--------------------------------------------------------------------------
  # ● Calculate damage
  #--------------------------------------------------------------------------
  alias_method(:krx_vs_gb_mdv, :make_damage_value)
  def make_damage_value(user, item)
    krx_vs_gb_mdv(user, item)
    
    # the two lines below basically do the same thing you tried doing with the
    # loop. it just uses the built-in functions ruby provides
    return if !item.is_a?(RPG::Skill) # return if the item is not a RPG::Skill
    # return if the index of item.id is nil. if it is nil then it is not in the IGNORE_SKILLS list
    return if !VAMP::IGNORE_SKILLS.index(item.id).nil? # not needed if you decide to use the <Ignore vampire> notetag
    return if item.ignore_vampire
    
    # start with total hp and mp vamp values from the item's.
    # if the item drains no hp it returns 0
    total_hp_vamp = item.vampire
    total_mp_vamp = item.mpvampire
    
    # get the vampire values of all the states. those that do not give vampire
    hp_vamps = user.states.map{ |s| s.vampire }
    mp_vamps = user.states.map{ |s| s.mpvampire }
    
    # get the sum of the vampire values of all states
    total_hp_vamp += hp_vamps.reduce(:+)
    total_mp_vamp += mp_vamps.reduce(:+)
    
    # add the total value to the hp_drain
    @result.hp_drain = (@result.hp_damage * total_hp_vamp.fdiv(100)).round
    @result.mp_drain = (@result.hp_damage * total_mp_vamp.fdiv(100)).round
  end
end

 

 

I also included some comments so that you understand the changes I made.

Additionally, I added an extra notetag "<Ignore vampire> that you can use on skills, which does what you wanted to do with the list. It seemed more practical in my opinion.

As it is now, there is no limit to hp/mp_drain percentage, so maybe you want to add one?

Lastly, the vampire and mpvampire methods in RPG::UsableItem are not needed.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×