RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

Weapon and Armor modifies max HP/SP

Started by Zeriab, June 09, 2007, 01:35:36 PM

0 Members and 1 Guest are viewing this topic.

Zeriab

A script I made in 5-10 minutes or so because someone requested it.
I am to lazy to write a proper topic and to write comments.
It should be compatible to most scripts.
[spoiler=Code]class Game_Actor
  if @stack.nil?
alias zer_ori_maxhp maxhp
alias zer_ori_maxsp maxsp
@stack = true
  end
 
  def maxhp
n = zer_ori_maxhp
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.hp_plus : 0
n += armor1 != nil ? armor1.hp_plus : 0
n += armor2 != nil ? armor2.hp_plus : 0
n += armor3 != nil ? armor3.hp_plus : 0
n += armor4 != nil ? armor4.hp_plus : 0
n = [[n, 1].max, 9999].min
return n
  end
 
  def maxsp
n = zer_ori_maxsp
weapon = $data_weapons[@weapon_id]
armor1 = $data_armors[@armor1_id]
armor2 = $data_armors[@armor2_id]
armor3 = $data_armors[@armor3_id]
armor4 = $data_armors[@armor4_id]
n += weapon != nil ? weapon.sp_plus : 0
n += armor1 != nil ? armor1.sp_plus : 0
n += armor2 != nil ? armor2.sp_plus : 0
n += armor3 != nil ? armor3.sp_plus : 0
n += armor4 != nil ? armor4.sp_plus : 0
n = [[n, 1].max, 9999].min
return n
  end
end

module RPG
  class Weapon
attr_writer :hp_plus
attr_writer :sp_plus
def hp_plus
  return 0 if @hp_plus.nil?
  return @hp_plus
end
def sp_plus
  return 0 if @sp_plus.nil?
  return @sp_plus
end
  end
end

module RPG
  class Armor
attr_writer :hp_plus
attr_writer :sp_plus
def hp_plus
  return 0 if @hp_plus.nil?
  return @hp_plus
end
def sp_plus
  return 0 if @sp_plus.nil?
  return @sp_plus
end
  end
end
[/spoiler]

To use it just put something like this in a call script:
$data_armors[18].hp_plus = 50
$data_armors[16].sp_plus = 25
$data_weapons[4].hp_plus = 500
$data_weapons[6].sp_plus = 20


You can use it where ever you want in the game.
If you have loads to setup to start with you can insert a script like this:
class WeaponAndArmorSetup
  def self.run
    $data_armors[18].hp_plus = 50
    $data_armors[16].sp_plus = 25
    $data_weapons[4].hp_plus = 500
    $data_weapons[6].sp_plus = -20
  end
end


By default every weapon and armor adds 0 to hp and sp.
Use negative values to decrease the amount.

And put this in a call script: WeaponAndArmorSetup.run
It will setup the weapons and armors.

Kokowam

Wow, nice, Zeriab. Will you teach me scripting now that you're done with your break? ;D I'll use this script for study...

Zeriab

I've been back from my break since http://rmrk.net/index.php/topic,17848.0.html
I don't really know whether or not I am a good teacher for you, but we can always try ^_^

Kokowam

YAY! Shinami was in the process of teaching me but he's currently occupied with a huge syntax book. He then did what my other teacher (of eventing) did and "unfortunately deleted it." I guess I can have two teachers of the same thing at once. ;D Also, I forgot to give good feedback on this. I've seen a lot (er, some) people request for this kind of things and this is nice! You just slip in a code and it works! It's a nice and easy way to set things up. Too bad you can't edit RPG Maker itself to add the option. ;9

Zeriab

Thanks ^_^

I've edited it sort out a stack error if you pressed the Key of Script Destruction, i.e. F12

Rune

I want items to increase my hp by 5%, 10% etc
When I type
$data_armors[33].hp_plus = *0.05
It just adds a 0.5 onto the end
What am I doing wrong? Or is there a way to multiply hp or sp?
Either way, could you help me?
Sincerely,
Your conscience.

Zeriab

Currently the script can only add/remove a static amount of hp/sp.
It is a good idea so I might add that feature to the script when I get time.

Rune

Sincerely,
Your conscience.