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.

HBGames

This scripts allows someone who attacked someone with "rough skin" to take a proportional amount of the damage they inflict as damage to themself.

Code:
class Game_Enemy < Game_Battler
  
  alias enemy_rough_skin_initialize initialize
  def initialize(troop_id, member_index)
    enemy_rough_skin_initialize(troop_id, member_index)
    
    if @enemy_id == 1
      @rough_skin = true
    end
    
  end
end


class Game_Battler
  
  attr_accessor :rough_skin
  attr_accessor :rough_skin_damage
  attr_accessor :rough_skin_damage_percent
  
  alias rough_skin_initialize initialize
  def initialize
    rough_skin_initialize
    @rough_skin = false
    @rough_skin_damage = 0
    @rough_skin_damage_percent = 50
  end
  
  alias rough_skin_attack_effect attack_effect
  def attack_effect(attacker)
    attack = rough_skin_attack_effect(attacker)
    if self.rough_skin == true
      attacker.rough_skin_damage = (self.damage.to_i * self.rough_skin_damage_percent)/100
    end
    return attack
  end
end


class Scene_Battle
  
  alias rough_skin_update_phase4_step5 update_phase4_step5
  def update_phase4_step5
    rough_skin_update_phase4_step5
    if @active_battler.rough_skin_damage != 0
      @active_battler.damage = @active_battler.rough_skin_damage
      @active_battler.hp -= @active_battler.damage
      @active_battler.rough_skin_damage = 0
      @active_battler.damage_pop = true
      @active_battler.white_flash = true
      @wait_count = 8
    end
  end
  
end

The if statement:
Code:
    if @enemy_id == 1
      @rough_skin = true
    end
Shows how to make an enemy have "rough skin" to make an enemies skin rougher/smoother use:
Code:
@rough_skin_damage_percent = X
Where X is the percent of damage inflicted on the attacker.

This is partly useful to stop people just hitting enter/space for every battle they enter. Enjoy!


EDIT:

Credit to Kalina for this edit:
Basically it does the same except your SP will take "damage" aswell from the rough skin, note: hp and sp percents are set seperately (incase it sounded like the same percent was used for both).
Code:
class Game_Battler
  
  attr_accessor :rough_skin
  attr_accessor :rough_skin_hp_damage
  attr_accessor :rough_skin_hp_damage_percent
  attr_accessor :rough_skin_sp_damage
  attr_accessor :rough_skin_sp_damage_percent
  
  alias rough_skin_initialize initialize
  def initialize
    rough_skin_initialize
    @rough_skin = false
    @rough_skin_hp_damage = 0
    @rough_skin_hp_damage_percent = 50
    @rough_skin_sp_damage = 0
    @rough_skin_sp_damage_percent = 50
  end
  
  alias rough_skin_attack_effect attack_effect
  def attack_effect(attacker)
    attack = rough_skin_attack_effect(attacker)
    if self.rough_skin == true
      attacker.rough_skin_hp_damage = (self.damage.to_i * self.rough_skin_hp_damage_percent)/100
      attacker.rough_skin_sp_damage = (self.damage.to_i * self.rough_skin_sp_damage_percent)/100
    end
    return attack
  end
end

Kalina also had the idea of giving enemies negative multipliers meaning you'd be recovered from attacking them (I hadn't thought about this or the SP edit so congrats to Kalina).

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