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.

Breakable Weapons in Combat

Status
Not open for further replies.
I was wondering if anyone could create a script that would make it so weapons have a percent chance in breaking in combat after each attack.
 
Let's try here in fast reply. lol

Code:
class RPG::Weapon
  Attack_Break_Chance = {}
  Attack_Break_Chance.default = 10
  def attack_break_chance
    return Attack_Break_Chance[@id]
  end
end

class Game_Battler
  alias_method :seph_weaponsbreak_gmbtlr_ae, :attack_effect
  def attack_effect(attacker)
    result = seph_weaponsbreak_gmbtlr_ae(attacker)
    if result && attacker.is_a?(Game_Actor)
      attacker.attack_break_weapon
    end
    return result
  end
end

class Game_Actor
  def attack_break_weapon
    weapon = $data_weapons[@weapon_id]
    return if weapon.nil?
    if rand(100) < weapon.attack_break_chance
      @damage = 'Weapon Broke!'
      @damage_pop = true
      @weapon_id = 0
    end
  end
end

Try that. Just modify:
Code:
  Attack_Break_Chance = {}
  Attack_Break_Chance.default = 10

10 is the default percent for all weapons.
To make custom percents for a weapon, just add a key and value pair in the {}. For example, for weapon 5, 45 percent, add 5 => 45. For weapon 3, with a 85 percent, add 3 =>. 85. So your line will look like:

Attack_Break_Chance = {5 => 45, 3 => 85}
 
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