Help - Search - Members - Calendar
Full Version: Limiting Damage
RPG RPG Revolution Forums > Scripting > Script Submissions > RGSS-Submissions
Ty
Script Name: Limiting Damage
Written by: Synthesize
Current Version: V1.00
Release Date: October 1st, 2007

What is it??
With this script the designer has the ability to define the minimum and maximum amounts of damage that can be dealt on a single attack.

The Script
Place in a new script window above Main.
CODE
#============================================================================
#                            Limiting Damage  
#----------------------------------------------------------------------------
# Written by Synthesize
# Version 100
# October 1st, 2007
#============================================================================
# Compatibility:
# Rewrites:
#    Game_Battler::attack_effect
#    Game_Battler::skill_effect
#--------------------------------------------------------------------------
# Begin Customization Section
#--------------------------------------------------------------------------
module LimitDamage  
  Maximum_Damage = 9999
  Minimum_Damage = 1
  Maximum_SkillDamage = 9999
  Minimum_SkillDamage = 1
  # Change these values to your expected setting.
  # Note: By default minimum damage is 0.
end
#--------------------------------------------------------------------------
# End Customization Section
#--------------------------------------------------------------------------
# Begin Game_Battler Rewrite
#--------------------------------------------------------------------------
class Game_Battler
  def attack_effect(attacker)
   # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true
      # Calculate basic damage
      atk = [attacker.atk - self.pdef / 2, 0].max
      self.damage = atk * (20 + attacker.str) / 20
      # Element correction
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Critical correction
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true
        end
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / attacker.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
    end
    # If hit occurs
    if hit_result == true
      # State Removed by Shock
      remove_states_shock
      # Substract damage from HP
      if self.damage < LimitDamage::Minimum_Damage
        self.damage = LimitDamage::Minimum_Damage
      elsif self.damage > LimitDamage::Maximum_Damage
        self.damage = LimitDamage::Maximum_Damage
      end
      self.hp -= self.damage
      # State change
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # When missing
    else
      # Set damage to "Miss"
      self.damage = "Miss"
      # Clear critical flag
      self.critical = false
    end
    # End Method
    return true
  end
  #---------------------------------------------------------------------
  # Begin Skill Adjustment
  #---------------------------------------------------------------------
   def skill_effect(user, skill)
     # Clear critical flag
    self.critical = false
    # If skill scope is for ally with 1 or more HP, and your own HP = 0,
    # or skill scope is for ally with 0, and your own HP = 1 or more
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # End Method
      return false
    end
    # Clear effective flag
    effective = false
    # Set effective flag if common ID is effective
    effective |= skill.common_event_id > 0
    # First hit detection
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
    # Set effective flag if skill is uncertain
    effective |= hit < 100
    # If hit occurs
    if hit_result == true
      # Calculate power
      power = skill.power + user.atk * skill.atk_f / 100
      if power > 0
        power -= self.pdef * skill.pdef_f / 200
        power -= self.mdef * skill.mdef_f / 200
        power = [power, 0].max
      end
      # Calculate rate
      rate = 20
      rate += (user.str * skill.str_f / 100)
      rate += (user.dex * skill.dex_f / 100)
      rate += (user.agi * skill.agi_f / 100)
      rate += (user.int * skill.int_f / 100)
      # Calculate basic damage
      self.damage = power * rate / 20
      # Element correction
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
      # If damage value is strictly positive
      if self.damage > 0
        # Guard correction
        if self.guarding?
          self.damage /= 2
        end
      end
      # Dispersion
      if skill.variance > 0 and self.damage.abs > 0
        amp = [self.damage.abs * skill.variance / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # Second hit detection
      eva = 8 * self.agi / user.dex + self.eva
      hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
      hit = self.cant_evade? ? 100 : hit
      hit_result = (rand(100) < hit)
      # Set effective flag if skill is uncertain
      effective |= hit < 100
    end
    # If hit occurs
    if hit_result == true
      # If physical attack has power other than 0
      if skill.power != 0 and skill.atk_f > 0
        # State Removed by Shock
        remove_states_shock
        # Set to effective flag
        effective = true
      end
      # Substract damage from HP
      if self.damage < LimitDamage::Minimum_SkillDamage
        self.damage = LimitDamage::Minimum_SkillDamage
      elsif self.damage > LimitDamage::Maximum_SkillDamage
        self.damage = LimitDamage::Maximum_SkillDamage
      end
      last_hp = self.hp
      self.hp -= self.damage
      effective |= self.hp != last_hp
      # State change
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      # If power is 0
      if skill.power == 0
        # Set damage to an empty string
        self.damage = ""
        # If state is unchanged
        unless @state_changed
          # Set damage to "Miss"
          self.damage = "Miss"
        end
      end
    # If miss occurs
    else
      # Set damage to "Miss"
      self.damage = "Miss"
    end
    # If not in battle
    unless $game_temp.in_battle
      # Set damage to nil
      self.damage = nil
    end
    # End Method
    return effective
  end
end

#============================================================================
# Written by Synthesize
# Special Thanks: Peter for the request
#----------------------------------------------------------------------------
#                            Limiting Damage
#============================================================================

Questions Concerns? Post them.
Peter
Thanks for the script this is exactly what I needed.

Though I have a question, would this script work with a multi-hit script?
Ty
It would work with a multi-hit script, as long as the methods I rewrote are not rewritten again.
Peter
I tried your script on my game yet it inclueds ATB, and overdrive as well as multi-hit scripts. Everything works fine except when I give the attack command. An error flashes and before I can read it the game shuts down. I think It has somehing to do with the Game_Battler section in my overdrive script , should I replace my current Game battler scrip for yours in both the ATB script and the Overdrive Scripts
Ty
Can you send me a link to these scripts? Thanks ^^

And don't replace anything in your Overdrive/ATB Script.
RPG Wizard
Added to the database.

http://www.rpgrevolution.com/script/13
FatalDemon
I know this is old but could you add some kind of limit break system? Like certain people or attacks that can break the limit? Or is that already in and I am just an idiot? >.>
jens009
QUOTE
I know this is old but could you add some kind of limit break system? Like certain people or attacks that can break the limit? Or is that already in and I am just an idiot? >.>

I had done this before but not with Synthesize script.

@Synthesize: If you ever saw his request, you can do this by making an element that has a name of "Limit Break" per say and allow that skill to break the limit. (Meaning being able to go beyond the set limit of your script)

In any case, I'll try to look into it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.