Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Weapon and Armor modifies max HP/SP

Status
Not open for further replies.

Zeriab

Sponsor

Here is a version which reduces the hp and sp to fit the max hp and max sp.
The removed hp and sp is lost. I.e. it does not come again when removing the equipment.
Enjoy ^_^

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
    @hp = n if n < hp
    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
    @sp = n if n < sp
    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
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top