The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on July 07, 2008, 08:23:30 PM

Title: HP / MP Equipment Bonuses
Post by: modern algebra on July 07, 2008, 08:23:30 PM
HP / MP Equipment Bonuses
Version: 1.0
Author: modern algebra
Date: July 7, 2008

Description


This script allows you to set Equipment that give bonuses to your Max HP and Max MP

Features


Instructions

Place script above Main and below other Custom scripts

    Simply use these codes in the note box of any Equipment:
    
      \maxhp[<integer>] positive or negative
      \maxmp[<integer>] positive or negative

Script


Code: [Select]
#==============================================================================
#  Max HP/MP Equipment
#  Version 1.0
#  Author: modern algebra
#  Date: July 7, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Instructions:
#    Place Above Main and below other Custom scripts
#
#    Simply use this code in the note box of any Equipment:
#    
#      \maxhp[<integer>] positive or negative
#      \maxmp[<integer>] positive or negative
#==============================================================================

#==============================================================================
# ** RPG::BaseItem
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    new methods - maxhp, maxmp
#==============================================================================

class RPG::BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * MaxHP Bonus
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maxhp
    return $1.to_i if self.note[/\\maxhp\[(-*\d+)\]/i] != nil
    return 0
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * MaxMP Bonus
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def maxmp
    return $1.to_i if self.note[/\\maxmp\[(-*\d+)\]/i] != nil
    return 0
  end
end

#==============================================================================
# ** Game_Actor
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#  Summary of Changes:
#    aliased method - setup, change_equip
#    new method - add_hpmp_bonuses
#==============================================================================

class Game_Actor
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_levent_hpmpmax_upd_equipment_stup setup
  def setup (actor_id)
    # Run Original method
    modalg_levent_hpmpmax_upd_equipment_stup (actor_id)
    equips.each_index { |i| calc_hpmp_bonuses (equips[i]) }
    self.hp = self.maxhp
    self.mp = self.maxmp
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Change Equip
  #--------------------------------------------------------------------------
  #  Adds and subtracts maxhp upon equip
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias modalg_levnthn_maxhpmp_equip_change_9nej change_equip
  def change_equip (equip_type, item, test = false)
    calc_hpmp_bonuses (equips[equip_type], false)
    # Run Original Method
    modalg_levnthn_maxhpmp_equip_change_9nej (equip_type, item, test)
    calc_hpmp_bonuses (item)
    self.hp = [self.hp, self.maxhp].min
    self.mp = [self.mp, self.maxmp].min
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Add HPMP Bonuses
  #    item : the item in question
  #    sign : true => add, false => subtract
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def calc_hpmp_bonuses (item = nil, sign = true)
    return if item == nil
    hp = sign ? item.maxhp : -item.maxhp
    @maxhp_plus += hp
    mp = sign ? item.maxmp : -item.maxmp
    @maxmp_plus += mp
  end
end

Credit



Thanks


Support


Post here at rmrk.net for the swiftest response


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
Title: Re: HP / MP Equipment Bonuses
Post by: Leventhan on July 08, 2008, 08:19:27 AM
Thank you very much modern! ;8
Title: Re: HP / MP Equipment Bonuses
Post by: modern algebra on July 09, 2008, 12:32:28 AM
Sorry Leventhan - I made a mistake.

Change:

Code: [Select]
    return $1.to_i if self.note[/\\maxhp\[-*(\d+)\]/i] != nil
to

Code: [Select]
    return $1.to_i if self.note[/\\maxhp\[(-*\d+)\]/i] != nil

It's at about line 28
Title: Re: HP / MP Equipment Bonuses
Post by: Drunken Paladin on July 14, 2008, 05:14:01 PM
    Simply use these codes in the note box of any Equipment:
   
      \maxhp[<integer>] positive or negative
      \maxmp[<integer>] positive or negative

Forgive me, I'm not really very experienced with scripting, but do you mean input an actual integer inside the brackets in the note-section of an item?

I.e., \maxhp[20] will increase the Max HP by 20?

EDIT: Indeed you did! My nub ass included the < > inside the brackets and couldn't figure out what you meant. Many thanks, this is a great script.  :)
Title: Re: HP / MP Equipment Bonuses
Post by: Foghart on February 08, 2011, 08:44:00 PM
Sorry, but I can't put this to work.
I don't know if i'm doing in the right way, but I put the code like this:
Quote
\maxhp[<+10>]

You can put some example on how we can put the code?
Thanks, seeya.
Title: Re: HP / MP Equipment Bonuses
Post by: modern algebra on February 08, 2011, 09:13:31 PM
You don't need the + and drop the <>. Those were just meant to represent that that is where you put something. So, if you wanted to add 10, you'd put:

\maxhp[10]

If you wanted it to remove 10, then:

\maxhp[-10]
Title: Re: HP / MP Equipment Bonuses
Post by: Foghart on February 08, 2011, 11:13:05 PM
The % can be worked too?
For example... 10%, 25%.
Title: Re: HP / MP Equipment Bonuses
Post by: modern algebra on February 08, 2011, 11:51:28 PM
No, not in this script at least.
Title: Re: HP / MP Equipment Bonuses
Post by: Foghart on February 09, 2011, 01:02:09 AM
Ahh... too bad, I was looking for this.

EDIT:
Anyone who can put the % to work, please contact me, I really need this kind of system to do a "equipment strategy" for my game.
Title: Re: HP / MP Equipment Bonuses
Post by: glenick1 on January 21, 2012, 10:31:33 PM
I got some kind of problem with this script. I'm totally unexperienced with scripts, so it could be an easy answer tho.

Whenever I give my armor a bonus, like \maxhp[150], the hp remains the same. But when i unequip my armor, the max hp does drop with 150 tho. How can I fix this?

EDIT: When I re-equip the armor, the max hp increases with 150 hp, but the amount is exactly the same as without the script.
Title: Re: HP / MP Equipment Bonuses
Post by: modern algebra on January 21, 2012, 11:26:39 PM
I don't receive that error, but my best guess is that it is an incompatibility with another script - one which overwrites the setup method of Game_Actor.

Try putting this script below every one of your other custom scripts, but still above Main.
Title: Re: HP / MP Equipment Bonuses
Post by: glenick1 on January 23, 2012, 04:03:01 PM
I know it sounds weird, but today i continued my game, and the script was working. Quite weird, but atleast it's ok now :D Thanks for the script!