[XP] Custom Defense Script

Started by winkio, October 31, 2008, 11:32:50 am

Previous topic - Next topic

winkio

October 31, 2008, 11:32:50 am Last Edit: February 21, 2009, 06:04:07 am by Blizzard
Custom Defense Script
Authors: winkio
Version: 1.00
Type: Battle Add-on
Key Term: Battle Add-on



Introduction

This script will change the defense processing for party members so that instead of damage getting reduced by half when they defend, you can define how much damage is reduced by based on their shield.


Features


  • Custom defense processing
  • Easy to use
  • Small script



Screenshots

None needed


Script

Put this below the default scripts and above any scripts that deal with battle.
Spoiler: ShowHide

#==============================================================================
# Custom damage script
# By Winkio
#
# This script will make the damage taken when defending correspond to the shield.
# The shield's shield_mdef and shield_pdef should be an integer from 0-100.  This
# number will be converted into a percent (60 -> 60%).  damage taken when
# defending will be reduced by this percent of its original using the pdef
# percent for attacks and the mdef percent for skills (Ex. 10 damage reduced by
# 60% = 10 - 6 = 4 damage).
#==============================================================================

#==============================================================================
# Game_Actor
#
# This will modify the damage dealt to the actor from attacks and skills when
# defending
#==============================================================================

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # define percent of damage blocked from attacks for each sheild with
  # when (id) then return (percent)
  #
  # id - id of the shield in the armor database
  # percent - percent of damage blocked by shield
  #--------------------------------------------------------------------------
  def shield_mdef (id)
    case id
      when 1 then return 50
      end
    return 0
  end
  #--------------------------------------------------------------------------
  # define percent of damage blocked from skills for each sheild with
  # when (id) then return (percent)
  #
  # id - id of the shield in the armor database
  # percent - percent of damage blocked by shield
  #--------------------------------------------------------------------------
  def shield_pdef (id)
    case id
      when 1 then return 50
    end
    return 0
  end
  #--------------------------------------------------------------------------
  # shield defense calculator for pdef
  #--------------------------------------------------------------------------
  def shpdef
    n = 100 - shield_pdef(@armor1_id)
    return n
  end
  #--------------------------------------------------------------------------
  # shield defense calculator for pdef
  #--------------------------------------------------------------------------
  def shmdef
    n = 100 - shield_mdef(@armor1_id)
    return n
  end
  #--------------------------------------------------------------------------
  # updated version of attack_effect
  #--------------------------------------------------------------------------
  def attack_effect(attacker)
    # クリティカルフラグをクリア
    self.critical = false
    # 第一命中判定
    hit_result = (rand(100) < attacker.hit)
    # 命中の場合
    if hit_result == true
      # 基本ダメージを計算
      atk = [attacker.atk - self.pdef / 2, 0].max
      self.damage = atk * (20 + attacker.str) / 20
      # 属性修正
      self.damage *= elements_correct(attacker.element_set)
      self.damage /= 100
      # ダメージの符号が正の場合
      if self.damage > 0
        # クリティカル修正
        if rand(100) < 4 * attacker.dex / self.agi
          self.damage *= 2
          self.critical = true
        end
        # 防御修正
        if self.guarding?
          ##### change123 (self.damage /= 2 ---> original line)
          # changes the damage based on the percent of your shield
          self.damage *= self.shpdef
          self.damage /= 100
        end
      end
      # 分散
      if self.damage.abs > 0
        amp = [self.damage.abs * 15 / 100, 1].max
        self.damage += rand(amp+1) + rand(amp+1) - amp
      end
      # 第二命中判定
      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_result == true
      # ステート衝撃解除
      remove_states_shock
      # HP からダメージを減算
      self.hp -= self.damage
      # ステート変化
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    # ミスの場合
    else
      # ダメージに "Miss" を設定
      self.damage = "Miss"
      # クリティカルフラグをクリア
      self.critical = false
    end
    # メソッド終了
    return true
  end
  #--------------------------------------------------------------------------
  # updated version of skill effect
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
    # クリティカルフラグをクリア
    self.critical = false
    # スキルの効果範囲が HP 1 以上の味方で、自分の HP が 0、
    # またはスキルの効果範囲が HP 0 の味方で、自分の HP が 1 以上の場合
    if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
       ((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
      # メソッド終了
      return false
    end
    # 有効フラグをクリア
    effective = false
    # コモンイベント ID が有効の場合は有効フラグをセット
    effective |= skill.common_event_id > 0
    # 第一命中判定
    hit = skill.hit
    if skill.atk_f > 0
      hit *= user.hit / 100
    end
    hit_result = (rand(100) < hit)
    # 不確実なスキルの場合は有効フラグをセット
    effective |= hit < 100
    # 命中の場合
    if hit_result == true
      # 威力を計算
      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
      # 倍率を計算
      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)
      # 基本ダメージを計算
      self.damage = power * rate / 20
      # 属性修正
      self.damage *= elements_correct(skill.element_set)
      self.damage /= 100
      # ダメージの符号が正の場合
      if self.damage > 0
        # 防御修正
        if self.guarding?
          ##### (change123 self.damage /= 2 ---> original line)
          # changes the damage based on the percent of your shield
          self.damage *= self.shmdef
          self.damage /= 100
        end
      end
      # 分散
      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
      # 第二命中判定
      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)
      # 不確実なスキルの場合は有効フラグをセット
      effective |= hit < 100
    end
    # 命中の場合
    if hit_result == true
      # 威力 0 以外の物理攻撃の場合
      if skill.power != 0 and skill.atk_f > 0
        # ステート衝撃解除
        remove_states_shock
        # 有効フラグをセット
        effective = true
      end
      # HP からダメージを減算
      last_hp = self.hp
      self.hp -= self.damage
      effective |= self.hp != last_hp
      # ステート変化
      @state_changed = false
      effective |= states_plus(skill.plus_state_set)
      effective |= states_minus(skill.minus_state_set)
      # 威力が 0 の場合
      if skill.power == 0
        # ダメージに空文字列を設定
        self.damage = ""
        # ステートに変化がない場合
        unless @state_changed
          # ダメージに "Miss" を設定
          self.damage = "Miss"
        end
      end
    # ミスの場合
    else
      # ダメージに "Miss" を設定
      self.damage = "Miss"
    end
    # 戦闘中でない場合
    unless $game_temp.in_battle
      # ダメージに nil を設定
      self.damage = nil
    end
    # メソッド終了
    return effective
  end
end



Instructions

This script will make the damage taken when defending correspond to the shield.
The shield's shield_mdef and shield_pdef should be an integer from 0-100.  This
number will be converted into a percent (60 -> 60%).  damage taken when
defending will be reduced by this percent of its original using the pdef
percent for attacks and the mdef percent for skills (Ex. 10 damage reduced by
60% = 10 - 6 = 4 damage).

Put it below default scripts and above any battle scripts.


Compatibility

Incompatible with any script that modifies HOW damage is CALCULATED
Compatible will Blizz-ABS pretty much everything else
Note:  With Blizz-ABS, you must turn off the FULL_DEFEND option in the config section of Blizz-ABS


Credits and Thanks


  • Winkio
  • Originally produced for Galatea



Author's Notes

It is really easy to modify anything with how damage is calculated in RMXP, so if you need custom damage calculators or other adjustments, just let me know.

Galatea

October 31, 2008, 01:03:51 pm #1 Last Edit: October 31, 2008, 01:24:08 pm by Galatea
Wow, that was fast!
Thx dude!

*Powers you up!*

Edit: Opss , cant find the FULL_DEFEND. .
Helppppp!  :^_^':

Edir: Ohh, ignore me. i got it now.  :^_^':
XD

FlyingHamsta

One suggestion would be to include critical damage modifier as well in the same script, or other options added to spruce up defense (adding sp/hp recovery as an option, etc.)  Just seems kind of unnecessary to have a script do something that one could achieve by changing one line of code.

winkio

This is a script I made for Galatea because all he wanted was the shield def change.  Any other changes to damage calculation are custom to each game.  Why would I change the system if not everybody wants it to?

And yes, there is only one line of code changed in the calculation scripts, but that was all that was needed, along with four other methods to handle passing in the new shield data.

Why make a script if I'm just changing a few lines?  Because it is easier to use and modify.  Why else do people make scripts instead of just editing the existing ones?


Isn't it nice to have an independent script that just handles one small system?  or do we all have to have ultra-scripts split into three parts like Blizz-ABS and TOA?

Aqua

Nice script Winkio.

Would you mind if I editted a bit to fit my game (so it's states that do the def change instead of shields).  Of course, I'd give you credit! :)

winkio

np, you don't really even need to give me credit.  For something small like this, I really don't mind if you just change a few lines. 

And do you mean states or stats?  Because if you mean states, then that wouldn't be a part of the defending area, but of the main area.  And for either one, make sure you do it for Game_Battler instead of Game_Actor (Game_Actor only affects party members, Game_Battler is for party members and enemies as well.)  I used Actor in this one because enemies don't have shields.

Aqua

Yeah I meant states.

If state 8 is inflicted, then all damage is 50%.  Stuff like that...

Thanks for the tips.

:)

Diokatsu

Quite nice, a neat idea.

I like it and I might just try and use it when I resolve my storyline 8)

Blizzard

I agree with winkio, small systems have a lot of sense. They are usually compatible and very portable with many systems. I tried making Tons work that way. I put in many small systems that can work with each other. Practically you can remove any of Tons' subscripts and it should still work fine. It's just that I made it a collection to make it easier to test, make compatible with other systems and with the systems within.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.