Custom Defense Script
Authors: winkio
Version: 1.00
Type: Battle Add-on
Key Term: Battle Add-on
IntroductionThis 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
ScreenshotsNone needed
ScriptPut this below the default scripts and above any scripts that deal with battle.
#==============================================================================
# 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
InstructionsThis 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.
CompatibilityIncompatible 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 NotesIt 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.