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.

Damage Amount Reversal Script?

This one's a fairly simple request, but I'm nonetheless appreciative of whoever provides me some direction with it.

Basically, I want to create a script that, when a particular weapon is equipped or when a particular status effect is inflicted, the damage that a character causes gets reversed. If the character ordinarily did 149 points of damage, the script would flip the numbers to inflict 941 points of damage instead. This would preferably only happen about 20% of the time (with an adjustable probability).

If I'm not mistaken, this can be done fairly easily by creating a string from the damage, converting the string to an array, and doing a for loop to flip each character. Ruby probably has an easier way to do it, but even if so, I would have no idea of how to actually import it into the battle system and set the while weapon[1] equipped condition.

Thank you in advance !
 
[rgss]class Game_Battler
  # State/Weapon ID => probability
  Reverse_Damage_States = {}
  Reverse_Damage_Weapons = {}
  alias_method :seph_revdmg_gmbtlr_ae, :attack_effect
  def attack_effect(attacker)
    effective = seph_revdmg_gmbtlr_ae(attacker)
    reverse_damage_effect
    return effective
  end
  alias_method :seph_revdmg_gmbtlr_se, :skill_effect
  def skill_effect(user, skill)
    effective = seph_revdmg_gmbtlr_se(user, skill)
    reverse_damage_effect
    return effective
  end
  alias_method :seph_revdmg_gmbtlr_ie, :item_effect
  def item_effect(item)
    effective = seph_revdmg_gmbtlr_ie(item)
    reverse_damage_effect
    return effective
  end
  def reverse_damage_effect
    if self.damage.is_a?(Numeric)
      reverse_damage = false
      for state_id in self.states
        if Reverse_Damage_States.has_key?(state_id) && rand(100) < Reverse_Damage_States[state_id]
          reverse_damage = true
          break
        end
      end
      unless reverse_damage
        if Reverse_Damage_Weapons.has_key?(@weapon_id) && rand(100) < Reverse_Damage_Weapons[@weapon_id]
          reverse_damage = true
        end
      end
      if reverse_damage
        self.hp += self.damage
        self.damage = self.damage.reverse
        self.hp -= self.damage
      end
    end
  end
end
 
class Integer
  def reverse
    return self.to_s.reverse.to_i
  end
end
[/rgss]

If state 6 has a 20% chance of reversing damage, change: Reverse_Damage_States = {} to Reverse_Damage_States = {6=>20}

Should work with weapons too. Let me know if this doesn't work. Applies for both attacks, skills and item damages.
 
Thanks for responding so quickly!

I inserted the script just before the stuff under "Main," and it came up with a Syntax error when I tried to run the game. Adding an extra "end" resolved it, but everyone's damage inflicted came up as 0 when inflicted with the "Damage Reverse" state. This may be because of where I randomly inserted the "end."

Thanks again!
 

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