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.

Minimum damage of 1?

Status
Not open for further replies.
Hey I have a quick question again. How would I go about setting the minimum damage dealt to 1 instead of 0?

I'm asking because I want to have a rare monster in my game that only has about 5 HP, but only takes 1 damage per hit due to extremely high defense.
 
@Yeyinde - are you sure that will work?

I'd try this code

Code:
class Game_Battler
  #--------------------------------------------------------------------------
  # * Set Hp
  #--------------------------------------------------------------------------
  alias damage_minimum_hp= hp=
  def hp=(hp)
    # Get old hp and 
    old_hp, new_hp = self.hp, hp
    # If Damage is A Number and Difference is damage
    if self.damage.is_a?(Numeric) and old_hp - new_hp == self.damage
      # Get Damage
      n = self.damage
      # Set New Damage
      damage_hp = [n, 1].max
      # Set Hp
      self.damage_minimum_hp = old_hp - damage_hp
      # Set Damage
      self.damage = damage_hp
    else
      # The usaul
      self.damage_minimum_hp = hp
    end
  end
end

or if you prefer you can

before this line in Game_Battler method attack_effect
Code:
      # Substract damage from HP
      self.hp -= self.damage

add this line
Code:
  self.damage = [self.damage, 1].max

The first code sets the minimum damage for all actions attacks, skills, items, whatever
 
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