Equipment that increases HP and MP

Mon, 07 Jul 2008 19:24:04 +0000 - Author: Peter O.
This script is designed for RPG Maker VX.

The script below implements equipment that adds a boost or drop to an actor's maximum HP and/or MP. Put this script after all other scripts in the Materials section of the script editor.

After installing the script, add the tag [MaxHPIncrease: X] and/or [MaxMPIncrease: X] to the weapon or armor's notes, where X is the amount of HP or MP that the weapon or armor increases. X can be negative and can be a number or a percentage. The following are examples of its use:

[MaxHPIncrease: -10] - Decrease maximum HP by 10 [MaxHPIncrease: 30%] - Increase maximum HP by 30% [MaxMPIncrease: -50%] - Decrease maximum MP by 50%

The script code is below.

class Game_Actor
  @@MaxHPWeapons=nil
  @@MaxMPWeapons=nil
  @@MaxHPArmors=nil
  @@MaxMPArmors=nil
  def parseMaxHPTag(note,tag)
   value=[0,false]
   note.scan(/\[#{tag}\:\s*(\-?)(\d+)(\%?)\]/i){
    value=$2.to_i
    if $1=="-"
     value=-value
    end
    if $3=="%"
     value=[value,true]
    else
     value=[value,false]
    end
    break
   }
   return value
  end
  def parseMaxHPNotes
   @@MaxHPWeapons={}
   @@MaxMPWeapons={}
   @@MaxHPArmors={}
   @@MaxMPArmors={}
   for equip in $data_weapons
    next if !equip
    @@MaxHPWeapons[equip.id]=parseMaxHPTag(equip.note,"MaxHPIncrease")
    @@MaxMPWeapons[equip.id]=parseMaxHPTag(equip.note,"MaxMPIncrease")
   end
   for equip in $data_armors
    next if !equip
    @@MaxHPArmors[equip.id]=parseMaxHPTag(equip.note,"MaxHPIncrease")
    @@MaxMPArmors[equip.id]=parseMaxHPTag(equip.note,"MaxMPIncrease")
   end
  end
  def modifyValue(v,base,x)
   v+=(x[1]) ? base*x[0]/100 : x[0]
   v=1 if v<1 # Ensure max value is not 0 or less
   return v
  end
  alias :petero_maxhp_base_maxhp :base_maxhp
  alias :petero_maxhp_base_maxmp :base_maxmp
  alias :petero_maxhp_hp :hp
  alias :petero_maxhp_mp :mp
  def base_maxhp
   parseMaxHPNotes() if !@@MaxHPWeapons
   base=petero_maxhp_base_maxhp
   b=base
   for equip in self.weapons
    b=modifyValue(b,base,@@MaxHPWeapons[equip.id])
   end
   for equip in self.armors
    b=modifyValue(b,base,@@MaxHPArmors[equip.id])
   end
   return b
  end
  def base_maxmp
   parseMaxHPNotes() if !@@MaxHPWeapons
   base=petero_maxhp_base_maxmp
   b=base
   for equip in self.weapons
    b=modifyValue(b,base,@@MaxMPWeapons[equip.id])
   end
   for equip in self.armors
    b=modifyValue(b,base,@@MaxMPArmors[equip.id])
   end
   return b
  end
  def hp
   b=petero_maxhp_hp
   curmaxhp=self.maxhp
   if b>curmaxhp # Ensure HP is not over max HP
    self.hp=curmaxhp
   end
   return b
  end
  def mp
   b=petero_maxhp_mp
   curmaxmp=self.maxmp
   if b>curmaxmp # Ensure MP is not over max MP
    self.mp=curmaxmp
   end
   return b
  end
end


Discussion

Other Formats