Updated script below:
CODE
#===============================================================================
#
# Yanfly Engine Melody - New Battle Stats
# Last Date Updated: 2012.02.21
# Level: Normal, Hard
#
# This script offers the functionality to add new battle stats for both actors
# and enemies alike. These stats can be adjusted in the script itself while any
# potential weapons, armours, states, and enemies can have their settings made
# within their respective noteboxes.
#
# - DEX - Dexterity
# Dexterity is a new stat that directly impacts hit rates, evasion rates, and
# critical hit rates. In default VX, there was no growth at all over these three
# stats other than through equipment. Now, actors progressing through the game
# can directly impact the hit rate, evasion rate, and critical hit rate of a
# character upon calculation.
#
# - RES - Resistance
# Resistance is a new stat to provide a magical defense against magical attacks.
# Just like DEF is to ATK, RES is to SPI. In default VX, both magical defense
# and magical attack were found in one stat. Now, they're split across two,
# which frankly makes more sense.
#
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 2012.02.21 - Fixed stat growth for YEM Enemy Levels.
# o 2010.06.20 - Bugfix update for dex= and res=
# o 2010.06.14 - Compatibility Update for Skill Equip System.
# o 2010.05.31 - Compatibility Update for YEM Enemy Levels.
# o 2010.05.19 - Started Script and Finished.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials but above ▼ Main. Remember to save.
#
# Scroll down and set whichever stats you wish to include in your game. More
# instructions are available in each individual section.
#===============================================================================
$imported = {} if $imported == nil
module YEM
module STATS
module DEX
#=========================================================================
# - DEX - Dexterity
# -----------------------------------------------------------------------
# Dexterity is a new stat that directly impacts hit rates, evasion rates,
# and critical hit rates. In default VX, there was no growth at all over
# these three stats other than through equipment. Now, actors progressing
# through the game can directly impact the hit rate, evasion rate, and
# critical hit rate of a character upon calculation.
#
# -----------------------------------------------------------------------
# Item Tags - For Items only.
# -----------------------------------------------------------------------
# <dex growth: +x> or <dex growth: -x>
# This raises or lowers the target's base DEX by x amount.
#
# -----------------------------------------------------------------------
# Equipment Tags - For Weapons and Armours only.
# -----------------------------------------------------------------------
# <dex: +x> or <dex: -x>
# <dex: +x%> or <dex: -x%>
# This allows the weapon or armour to increase DEX for the actor wearing
# it by x amount or x%. Using the tag without the percentage will raise
# the amount by a set value while using the percentage will increase the
# base DEX of the actor by a percentile value.
#
# -----------------------------------------------------------------------
# State Tags - For Status Effects only.
# -----------------------------------------------------------------------
# <dex: x%> or <dex: +x> or <dex: -x>
# This adjusts the DEX stat in battle by x percentile or a set x amount.
# If multiple of these tags are used, it will be calculated based on the
# order of operations. Stackable.
#
# -----------------------------------------------------------------------
# Enemy Tags - For Enemies only.
# -----------------------------------------------------------------------
# <base dex: x>
# This sets the enemy's base DEX to x. The base dex would be the enemy's
# unaltered DEX value. If this tag isn't present, the enemy's base DEX
# will be calculated based on the formula provided by the module.
#=========================================================================
# This changes whether or not the DEX stat will be used at all. Set it
# to true if you wish to use the DEX stat. False if otherwise.
$imported["DEX Stat"] = true
# This is the ingame vocabulary for the DEX stat.
VOCAB = "DEX"
# This hash allows you to edit each actor's base DEX formula and the rate
# of growth for DEX as levels progress. Note that actor 0 will be used if
# the actor's ID does not appear on this list.
ACTOR_BASE ={
# ID => Formula
0 => "actor.parameters[2,@level]/2+actor.parameters[5,@level]/2",
4 => "@level * 6 + 20",
1 => "@level * 7 + 35",
2 => "@level * 2 + 16",
3 => "@level * 2 + 12",
} # Do not remove this.
# This is the formula used for the base DEX of an enemy if not specific
# base DEX has been defined by the <base dex: x> tag.
ENEMY_BASE = "@atk * 4 + @agi * 4 / 3"
# These are the formulas used to convert DEX bonuses for each of the
# varying stats. These bonuses are added onto the previously calculated
# HIT, EVA, and CRI values.
DEX_TO_HIT = "self.dex * 0.10"
DEX_TO_EVA = "self.dex * 0.03"
DEX_TO_CRI = "self.dex * 0.09"
end # DEX
module RES
#=========================================================================
# - RES - Resistance
# -----------------------------------------------------------------------
# Resistance is a new stat to provide a magical defense against magical
# attacks. Just like DEF is to ATK, RES is to SPI. In default VX, both
# magical defense and magical attack were found in one stat. Now, they're
# split across two, which frankly makes more sense.
#
# -----------------------------------------------------------------------
# Item Tags - For Items only.
# -----------------------------------------------------------------------
# <res growth: +x> or <res growth: -x>
# This raises or lowers the target's base RES by x amount.
#
# -----------------------------------------------------------------------
# Equipment Tags - For Weapons and Armours only.
# -----------------------------------------------------------------------
# <res: +x> or <res: -x>
# <res: +x%> or <res: -x%>
# This allows the weapon or armour to increase RES for the actor wearing
# it by x amount or x%. Using the tag without the percentage will raise
# the amount by a set value while using the percentage will increase the
# base RES of the actor by a percentile value.
#
# -----------------------------------------------------------------------
# State Tags - For Status Effects only.
# -----------------------------------------------------------------------
# <res: x%> or <res: +x> or <res: -x>
# This adjusts the RES stat in battle by x percentile or a set x amount.
# If multiple of these tags are used, it will be calculated based on the
# order of operations. Stackable.
#
# -----------------------------------------------------------------------
# Enemy Tags - For Enemies only.
# -----------------------------------------------------------------------
# <base res: x>
# This sets the enemy's base RES to x. The base res would be the enemy's
# unaltered RES value. If this tag isn't present, the enemy's base RES
# will be calculated based on the formula provided by the module.
#=========================================================================
# This changes whether or not the RES stat will be used at all. Set it
# to true if you wish to use the RES stat. False if otherwise.
$imported["RES Stat"] = true
# This is the ingame vocabulary for the RES stat.
VOCAB = "RES"
# This hash allows you to edit each actor's base RES formula and the rate
# of growth for RES as levels progress. Note that actor 0 will be used if
# the actor's ID does not appear on this list.
ACTOR_BASE ={
# ID => Formula
0 => "actor.parameters[3,@level]/2+actor.parameters[4,@level]/2",
4 => "@level * 4 + 20",
1 => "@level * 2 + 20",
2 => "@level * 6 + 30",
3 => "@level * 7 + 34",
} # Do not remove this.
# This is the formula used for the base RES of an enemy if not specific
# base RES has been defined by the <base res: x> tag.
ENEMY_BASE = "(@def * 4 + @spi * 4) / 2 + 96"
end # RES
end # STATS
end # YEM
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
module YEM
module REGEXP
module BASEITEM
STAT_PER = /<(.*):[ ]*([\+\-]\d+)([%%])>/i
STAT_SET = /<(.*):[ ]*([\+\-]\d+)>/i
end # BASEITEM
module ITEM
STAT_GROW = /<(.*)[ ](?:BOOST|growth):[ ]([\+\-]\d+)>/i
end # ITEM
module STATE
STAT_PER = /<(.*):[ ]*(\d+)([%%])>/i
STAT_SET = /<(.*):[ ]*([\+\-]\d+)>/i
end # STATE
module ENEMY
BASE_STAT = /<(?:BASE|basic)[ ](.*):[ ]*(\d+)>/i
end # ENEMY
end # REGEXP
end # YEM
#===============================================================================
# module Vocab
#===============================================================================
module Vocab
#--------------------------------------------------------------------------
# self.dex
#--------------------------------------------------------------------------
def self.dex; return YEM::STATS::DEX::VOCAB; end
#--------------------------------------------------------------------------
# self.res
#--------------------------------------------------------------------------
def self.res; return YEM::STATS::RES::VOCAB; end
end
#===============================================================================
# RPG::BaseItem
#===============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex
attr_accessor :dex_per
attr_accessor :res
attr_accessor :res_per
#--------------------------------------------------------------------------
# common cache: yem_cache_baseitem_nbs
#--------------------------------------------------------------------------
def yem_cache_baseitem_nbs
return if @cached_state_nbs; @cached_state_nbs = true
@dex = 0
@res = 0
@dex_per = 0
@res_per = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::BASEITEM::STAT_PER
case $1.upcase
when "DEX", "DEXTERITY"
@dex_per = $2.to_i
when "RES", "RESISTANCE"
@res_per = $2.to_i
end
#---
when YEM::REGEXP::BASEITEM::STAT_SET
case $1.upcase
when "DEX", "DEXTERITY"
@dex = $2.to_i
when "RES", "RESISTANCE"
@res = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_baseitem_nbs
end # RPG::BaseItem
#===============================================================================
# RPG::Item
#===============================================================================
class RPG::Item < RPG::UsableItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :stat_growth
#--------------------------------------------------------------------------
# common cache: yem_cache_item_nbs
#--------------------------------------------------------------------------
def yem_cache_item_nbs
return if @cached_item_nbs; @cached_item_nbs = true
@stat_growth = {} if @stat_growth == nil
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::ITEM::STAT_GROW
case $1.upcase
when "DEX", "DEXTERITY"
type = :dex
when "RES", "RESISTANCE"
type = :res
else; next
end
@stat_growth[type] = $2.to_i
end
} # self.note.split
end # yem_cache_item_nbs
end # RPG::Item
#===============================================================================
# RPG::State
#===============================================================================
class RPG::State
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex_rate
attr_accessor :dex_set
attr_accessor :res_rate
attr_accessor :res_set
#--------------------------------------------------------------------------
# common cache: yem_cache_state_nbs
#--------------------------------------------------------------------------
def yem_cache_state_nbs
return if @cached_state_nbs; @cached_state_nbs = true
@dex_rate = 100
@res_rate = 100
@dex_set = 0
@res_set = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::STATE::STAT_PER
case $1.upcase
when "DEX", "DEXTERITY"
@dex_rate = $2.to_i
when "RES", "RESISTANCE"
@res_rate = $2.to_i
end
#---
when YEM::REGEXP::STATE::STAT_SET
case $1.upcase
when "DEX", "DEXTERITY"
@dex_set = $2.to_i
when "RES", "RESISTANCE"
@res_set = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_state_nbs
end # RPG::State
#===============================================================================
# RPG::Enemy
#===============================================================================
class RPG::Enemy
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex
attr_accessor :res
#--------------------------------------------------------------------------
# common cache: yem_cache_enemy_nbs
#--------------------------------------------------------------------------
def yem_cache_enemy_nbs
return if @cached_enemy_nbs; @cached_enemy_nbs = true
@dex = eval(YEM::STATS::DEX::ENEMY_BASE)
@res = eval(YEM::STATS::RES::ENEMY_BASE)
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::ENEMY::BASE_STAT
case $1.upcase
when "DEX", "DEXTERITY"
@dex = $2.to_i
when "RES", "RESISTANCE"
@res = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_state_nbs
end # RPG::Enemy
#===============================================================================
# Vocab
#===============================================================================
module Vocab
#--------------------------------------------------------------------------
# new method: self.dex
#--------------------------------------------------------------------------
def self.dex; return YEM::STATS::DEX::VOCAB; end
#--------------------------------------------------------------------------
# new method: self.res
#--------------------------------------------------------------------------
def self.res; return YEM::STATS::RES::VOCAB; end
end # Vocab
#===============================================================================
# Scene_Title
#===============================================================================
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# alias method: load_bt_database
#--------------------------------------------------------------------------
alias load_bt_database_nbs load_bt_database unless $@
def load_bt_database
load_bt_database_nbs
load_nbs_cache
end
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
alias load_database_nbs load_database unless $@
def load_database
load_database_nbs
load_nbs_cache
end
#--------------------------------------------------------------------------
# new method: load_nbs_cache
#--------------------------------------------------------------------------
def load_nbs_cache
groups = [$data_skills, $data_items, $data_weapons, $data_armors,
$data_enemies, $data_states]
for group in groups
for obj in group
next if obj == nil
obj.yem_cache_baseitem_nbs if obj.is_a?(RPG::BaseItem)
obj.yem_cache_item_nbs if obj.is_a?(RPG::Item)
obj.yem_cache_state_nbs if obj.is_a?(RPG::State)
obj.yem_cache_enemy_nbs if obj.is_a?(RPG::Enemy)
end
end
end
end # Scene_Title
#===============================================================================
# Game_Battler
#===============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# anti-crash method: clear_battle_cache
#--------------------------------------------------------------------------
unless method_defined?(:clear_battle_cache)
def clear_battle_cache; @cache_params = {}; end
end # method_defined?(:clear_battle_cache)
#--------------------------------------------------------------------------
# anti-crash method: parameter_limit
#--------------------------------------------------------------------------
unless method_defined?(:parameter_limit)
def parameter_limit; return 999; end
end # method_defined?(:parameter_limit)
#--------------------------------------------------------------------------
# anti-crash method: stack
#--------------------------------------------------------------------------
unless method_defined?(:stack)
def stack(state); return 1; end
end # method_defined?(:stack)
#--------------------------------------------------------------------------
# alias method: item_growth_effect
#--------------------------------------------------------------------------
alias item_growth_effect_nbs item_growth_effect unless $@
def item_growth_effect(user, item)
item_growth_effect_nbs(user, item)
if item.stat_growth != {}
for key in item.stat_growth
stat = key[0]; value = key[1]
case stat
when :dex
@boost_dex += value
when :res
@boost_res += value
end
end
end
end
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: dex
#--------------------------------------------------------------------------
def dex
clear_battle_cache if @cache_params == nil
if $scene.is_a?(Scene_Battle)
return @cache_params[:dex] if @cache_params[:dex] != nil
end
#---
@dex_plus = 0 if @dex_plus == nil
n = [base_dex + @dex_plus, 1].max
for state in states
stack(state).times do
n = n * state.dex_rate / 100.0
end
end
for state in states
next if state.dex_set == 0
n += state.dex_set * stack(state)
end
#---
@cache_params[:dex] = [[Integer(n), parameter_limit].min, 1].max
return @cache_params[:dex]
end
#--------------------------------------------------------------------------
# new method: dex=
#--------------------------------------------------------------------------
def dex=(value)
@dex_plus = 0 if @dex_plus == nil
@dex_plus += value - self.dex
@dex_plus = [[@dex_plus, -parameter_limit].max, parameter_limit].min
clear_battle_cache
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: res
#--------------------------------------------------------------------------
def res
clear_battle_cache if @cache_params == nil
if $scene.is_a?(Scene_Battle)
return @cache_params[:res] if @cache_params[:res] != nil
end
#---
@res_plus = 0 if @res_plus == nil
n = [base_res + @res_plus, 1].max
for state in states
stack(state).times do
n = n * state.res_rate / 100.0
end
end
for state in states
next if state.res_set == 0
n += state.res_set * stack(state)
end
#---
@cache_params[:res] = [[Integer(n), parameter_limit].min, 1].max
return @cache_params[:res]
end
#--------------------------------------------------------------------------
# new method: res=
#--------------------------------------------------------------------------
def res=(value)
@res_plus = 0 if @res_plus == nil
@res_plus += value - self.res
@res_plus = [[@res_plus, -parameter_limit].max, parameter_limit].min
clear_battle_cache
end
#--------------------------------------------------------------------------
# overwrite method: make_obj_damage_value
#--------------------------------------------------------------------------
unless $imported["BattleEngineMelody"]
def make_obj_damage_value(user, obj)
damage = obj.base_damage
if damage > 0
damage += user.atk * 4 * obj.atk_f / 100
damage += user.spi * 2 * obj.spi_f / 100
unless obj.ignore_defense
damage -= self.def * 2 * obj.atk_f / 100
damage -= self.res * 1 * obj.spi_f / 100
end
damage = 0 if damage < 0
elsif damage < 0
damage -= user.atk * 4 * obj.atk_f / 100
damage -= user.spi * 2 * obj.spi_f / 100
end
damage *= elements_max_rate(obj.element_set)
damage /= 100
damage = apply_variance(damage, obj.variance)
damage = apply_guard(damage)
if obj.damage_to_mp
@mp_damage = damage
else
@hp_damage = damage
end
end
end # $imported["BattleEngineMelody"]
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Battler
#===============================================================================
# Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: base_dex
#--------------------------------------------------------------------------
def base_dex
if YEM::STATS::DEX::ACTOR_BASE.include?(@actor_id)
n = eval(YEM::STATS::DEX::ACTOR_BASE[@actor_id])
else
n = eval(YEM::STATS::DEX::ACTOR_BASE[0])
end
#---
percent = 100
for equip in equips.compact
percent += equip.dex_per
end
n *= percent / 100.0
#---
for equip in equips.compact
n += equip.dex
end
#---
n += equip_skill_stat_bonus(:dex) if $imported["SkillEquipSystem"]
#---
@boost_dex = 0 if @boost_dex == nil
n += @boost_dex
return Integer(n)
end
#--------------------------------------------------------------------------
# alias method: hit
#--------------------------------------------------------------------------
alias hit_game_actor_nbs hit unless $@
def hit
n = hit_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_HIT)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: eva
#--------------------------------------------------------------------------
alias eva_game_actor_nbs eva unless $@
def eva
n = eva_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_EVA)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: cri
#--------------------------------------------------------------------------
alias cri_game_actor_nbs cri unless $@
def cri
n = cri_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_CRI)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: base_res
#--------------------------------------------------------------------------
def base_res
if YEM::STATS::RES::ACTOR_BASE.include?(@actor_id)
n = eval(YEM::STATS::RES::ACTOR_BASE[@actor_id])
else
n = eval(YEM::STATS::RES::ACTOR_BASE[0])
end
#---
percent = 100
for equip in equips.compact
percent += equip.res_per
end
n *= percent / 100.0
#---
for equip in equips.compact
n += equip.res
end
#---
n += equip_skill_stat_bonus(:res) if $imported["SkillEquipSystem"]
#---
@boost_res = 0 if @boost_res == nil
n += @boost_res
return Integer(n)
end
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Actor
#===============================================================================
# Game_Enemy
#===============================================================================
class Game_Enemy < Game_Battler
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: base_dex
#--------------------------------------------------------------------------
def base_dex
@boost_dex = 0 if @boost_dex == nil
result = Integer(enemy.dex) + @boost_dex
if $imported["EnemyLevels"]
base = result
per = enemy.growth_per[:dex]
set = enemy.growth_set[:dex]
result = Integer(eval(YEM::ENEMY_LEVEL::BASE_FORMULAS[:dex]))
end
return Integer(result)
end
#--------------------------------------------------------------------------
# alias method: hit
#--------------------------------------------------------------------------
alias hit_game_enemy_nbs hit unless $@
def hit
n = hit_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_HIT)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: eva
#--------------------------------------------------------------------------
alias eva_game_enemy_nbs eva unless $@
def eva
n = eva_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_EVA)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: cri
#--------------------------------------------------------------------------
alias cri_game_enemy_nbs cri unless $@
def cri
n = cri_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_CRI)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: base_res
#--------------------------------------------------------------------------
def base_res
@boost_res = 0 if @boost_res == nil
result = Integer(enemy.res) + @boost_res
if $imported["EnemyLevels"]
base = result
per = enemy.growth_per[:res]
set = enemy.growth_set[:res]
result = Integer(eval(YEM::ENEMY_LEVEL::BASE_FORMULAS[:res]))
end
return Integer(result)
end
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Enemy
#===============================================================================
# Window_Base
#===============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# alias method: draw_actor_parameter
#--------------------------------------------------------------------------
alias draw_actor_parameter_nbs draw_actor_parameter unless $@
def draw_actor_parameter(actor, x, y, type)
case type
when 4 # RES
parameter_name = Vocab::res
parameter_value = actor.res
when 5 # DEX
parameter_name = Vocab::dex
parameter_value = actor.dex
else
draw_actor_parameter_nbs(actor, x, y, type)
return
end
self.contents.font.color = system_color
self.contents.draw_text(x, y, 120, WLH, parameter_name)
self.contents.font.color = normal_color
self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2)
end
end # Window_Base
#===============================================================================
# Window_Status
#===============================================================================
class Window_Status < Window_Base
#--------------------------------------------------------------------------
# alias method: draw_parameters
#--------------------------------------------------------------------------
alias draw_parameters_nbs draw_parameters unless $@
def draw_parameters(x, y)
draw_parameters_nbs(x, y)
dy = y+WLH*3
if $imported["RES Stat"]
dy += WLH
draw_actor_parameter(@actor, x, dy, 4)
end
if $imported["DEX Stat"]
dy += WLH
draw_actor_parameter(@actor, x, dy, 5)
end
end
end # Window_Status
#===============================================================================
#
# END OF FILE
#
#===============================================================================
#
# Yanfly Engine Melody - New Battle Stats
# Last Date Updated: 2012.02.21
# Level: Normal, Hard
#
# This script offers the functionality to add new battle stats for both actors
# and enemies alike. These stats can be adjusted in the script itself while any
# potential weapons, armours, states, and enemies can have their settings made
# within their respective noteboxes.
#
# - DEX - Dexterity
# Dexterity is a new stat that directly impacts hit rates, evasion rates, and
# critical hit rates. In default VX, there was no growth at all over these three
# stats other than through equipment. Now, actors progressing through the game
# can directly impact the hit rate, evasion rate, and critical hit rate of a
# character upon calculation.
#
# - RES - Resistance
# Resistance is a new stat to provide a magical defense against magical attacks.
# Just like DEF is to ATK, RES is to SPI. In default VX, both magical defense
# and magical attack were found in one stat. Now, they're split across two,
# which frankly makes more sense.
#
#===============================================================================
# Updates
# -----------------------------------------------------------------------------
# o 2012.02.21 - Fixed stat growth for YEM Enemy Levels.
# o 2010.06.20 - Bugfix update for dex= and res=
# o 2010.06.14 - Compatibility Update for Skill Equip System.
# o 2010.05.31 - Compatibility Update for YEM Enemy Levels.
# o 2010.05.19 - Started Script and Finished.
#===============================================================================
# Instructions
# -----------------------------------------------------------------------------
# To install this script, open up your script editor and copy/paste this script
# to an open slot below ▼ Materials but above ▼ Main. Remember to save.
#
# Scroll down and set whichever stats you wish to include in your game. More
# instructions are available in each individual section.
#===============================================================================
$imported = {} if $imported == nil
module YEM
module STATS
module DEX
#=========================================================================
# - DEX - Dexterity
# -----------------------------------------------------------------------
# Dexterity is a new stat that directly impacts hit rates, evasion rates,
# and critical hit rates. In default VX, there was no growth at all over
# these three stats other than through equipment. Now, actors progressing
# through the game can directly impact the hit rate, evasion rate, and
# critical hit rate of a character upon calculation.
#
# -----------------------------------------------------------------------
# Item Tags - For Items only.
# -----------------------------------------------------------------------
# <dex growth: +x> or <dex growth: -x>
# This raises or lowers the target's base DEX by x amount.
#
# -----------------------------------------------------------------------
# Equipment Tags - For Weapons and Armours only.
# -----------------------------------------------------------------------
# <dex: +x> or <dex: -x>
# <dex: +x%> or <dex: -x%>
# This allows the weapon or armour to increase DEX for the actor wearing
# it by x amount or x%. Using the tag without the percentage will raise
# the amount by a set value while using the percentage will increase the
# base DEX of the actor by a percentile value.
#
# -----------------------------------------------------------------------
# State Tags - For Status Effects only.
# -----------------------------------------------------------------------
# <dex: x%> or <dex: +x> or <dex: -x>
# This adjusts the DEX stat in battle by x percentile or a set x amount.
# If multiple of these tags are used, it will be calculated based on the
# order of operations. Stackable.
#
# -----------------------------------------------------------------------
# Enemy Tags - For Enemies only.
# -----------------------------------------------------------------------
# <base dex: x>
# This sets the enemy's base DEX to x. The base dex would be the enemy's
# unaltered DEX value. If this tag isn't present, the enemy's base DEX
# will be calculated based on the formula provided by the module.
#=========================================================================
# This changes whether or not the DEX stat will be used at all. Set it
# to true if you wish to use the DEX stat. False if otherwise.
$imported["DEX Stat"] = true
# This is the ingame vocabulary for the DEX stat.
VOCAB = "DEX"
# This hash allows you to edit each actor's base DEX formula and the rate
# of growth for DEX as levels progress. Note that actor 0 will be used if
# the actor's ID does not appear on this list.
ACTOR_BASE ={
# ID => Formula
0 => "actor.parameters[2,@level]/2+actor.parameters[5,@level]/2",
4 => "@level * 6 + 20",
1 => "@level * 7 + 35",
2 => "@level * 2 + 16",
3 => "@level * 2 + 12",
} # Do not remove this.
# This is the formula used for the base DEX of an enemy if not specific
# base DEX has been defined by the <base dex: x> tag.
ENEMY_BASE = "@atk * 4 + @agi * 4 / 3"
# These are the formulas used to convert DEX bonuses for each of the
# varying stats. These bonuses are added onto the previously calculated
# HIT, EVA, and CRI values.
DEX_TO_HIT = "self.dex * 0.10"
DEX_TO_EVA = "self.dex * 0.03"
DEX_TO_CRI = "self.dex * 0.09"
end # DEX
module RES
#=========================================================================
# - RES - Resistance
# -----------------------------------------------------------------------
# Resistance is a new stat to provide a magical defense against magical
# attacks. Just like DEF is to ATK, RES is to SPI. In default VX, both
# magical defense and magical attack were found in one stat. Now, they're
# split across two, which frankly makes more sense.
#
# -----------------------------------------------------------------------
# Item Tags - For Items only.
# -----------------------------------------------------------------------
# <res growth: +x> or <res growth: -x>
# This raises or lowers the target's base RES by x amount.
#
# -----------------------------------------------------------------------
# Equipment Tags - For Weapons and Armours only.
# -----------------------------------------------------------------------
# <res: +x> or <res: -x>
# <res: +x%> or <res: -x%>
# This allows the weapon or armour to increase RES for the actor wearing
# it by x amount or x%. Using the tag without the percentage will raise
# the amount by a set value while using the percentage will increase the
# base RES of the actor by a percentile value.
#
# -----------------------------------------------------------------------
# State Tags - For Status Effects only.
# -----------------------------------------------------------------------
# <res: x%> or <res: +x> or <res: -x>
# This adjusts the RES stat in battle by x percentile or a set x amount.
# If multiple of these tags are used, it will be calculated based on the
# order of operations. Stackable.
#
# -----------------------------------------------------------------------
# Enemy Tags - For Enemies only.
# -----------------------------------------------------------------------
# <base res: x>
# This sets the enemy's base RES to x. The base res would be the enemy's
# unaltered RES value. If this tag isn't present, the enemy's base RES
# will be calculated based on the formula provided by the module.
#=========================================================================
# This changes whether or not the RES stat will be used at all. Set it
# to true if you wish to use the RES stat. False if otherwise.
$imported["RES Stat"] = true
# This is the ingame vocabulary for the RES stat.
VOCAB = "RES"
# This hash allows you to edit each actor's base RES formula and the rate
# of growth for RES as levels progress. Note that actor 0 will be used if
# the actor's ID does not appear on this list.
ACTOR_BASE ={
# ID => Formula
0 => "actor.parameters[3,@level]/2+actor.parameters[4,@level]/2",
4 => "@level * 4 + 20",
1 => "@level * 2 + 20",
2 => "@level * 6 + 30",
3 => "@level * 7 + 34",
} # Do not remove this.
# This is the formula used for the base RES of an enemy if not specific
# base RES has been defined by the <base res: x> tag.
ENEMY_BASE = "(@def * 4 + @spi * 4) / 2 + 96"
end # RES
end # STATS
end # YEM
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
module YEM
module REGEXP
module BASEITEM
STAT_PER = /<(.*):[ ]*([\+\-]\d+)([%%])>/i
STAT_SET = /<(.*):[ ]*([\+\-]\d+)>/i
end # BASEITEM
module ITEM
STAT_GROW = /<(.*)[ ](?:BOOST|growth):[ ]([\+\-]\d+)>/i
end # ITEM
module STATE
STAT_PER = /<(.*):[ ]*(\d+)([%%])>/i
STAT_SET = /<(.*):[ ]*([\+\-]\d+)>/i
end # STATE
module ENEMY
BASE_STAT = /<(?:BASE|basic)[ ](.*):[ ]*(\d+)>/i
end # ENEMY
end # REGEXP
end # YEM
#===============================================================================
# module Vocab
#===============================================================================
module Vocab
#--------------------------------------------------------------------------
# self.dex
#--------------------------------------------------------------------------
def self.dex; return YEM::STATS::DEX::VOCAB; end
#--------------------------------------------------------------------------
# self.res
#--------------------------------------------------------------------------
def self.res; return YEM::STATS::RES::VOCAB; end
end
#===============================================================================
# RPG::BaseItem
#===============================================================================
class RPG::BaseItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex
attr_accessor :dex_per
attr_accessor :res
attr_accessor :res_per
#--------------------------------------------------------------------------
# common cache: yem_cache_baseitem_nbs
#--------------------------------------------------------------------------
def yem_cache_baseitem_nbs
return if @cached_state_nbs; @cached_state_nbs = true
@dex = 0
@res = 0
@dex_per = 0
@res_per = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::BASEITEM::STAT_PER
case $1.upcase
when "DEX", "DEXTERITY"
@dex_per = $2.to_i
when "RES", "RESISTANCE"
@res_per = $2.to_i
end
#---
when YEM::REGEXP::BASEITEM::STAT_SET
case $1.upcase
when "DEX", "DEXTERITY"
@dex = $2.to_i
when "RES", "RESISTANCE"
@res = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_baseitem_nbs
end # RPG::BaseItem
#===============================================================================
# RPG::Item
#===============================================================================
class RPG::Item < RPG::UsableItem
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :stat_growth
#--------------------------------------------------------------------------
# common cache: yem_cache_item_nbs
#--------------------------------------------------------------------------
def yem_cache_item_nbs
return if @cached_item_nbs; @cached_item_nbs = true
@stat_growth = {} if @stat_growth == nil
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::ITEM::STAT_GROW
case $1.upcase
when "DEX", "DEXTERITY"
type = :dex
when "RES", "RESISTANCE"
type = :res
else; next
end
@stat_growth[type] = $2.to_i
end
} # self.note.split
end # yem_cache_item_nbs
end # RPG::Item
#===============================================================================
# RPG::State
#===============================================================================
class RPG::State
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex_rate
attr_accessor :dex_set
attr_accessor :res_rate
attr_accessor :res_set
#--------------------------------------------------------------------------
# common cache: yem_cache_state_nbs
#--------------------------------------------------------------------------
def yem_cache_state_nbs
return if @cached_state_nbs; @cached_state_nbs = true
@dex_rate = 100
@res_rate = 100
@dex_set = 0
@res_set = 0
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::STATE::STAT_PER
case $1.upcase
when "DEX", "DEXTERITY"
@dex_rate = $2.to_i
when "RES", "RESISTANCE"
@res_rate = $2.to_i
end
#---
when YEM::REGEXP::STATE::STAT_SET
case $1.upcase
when "DEX", "DEXTERITY"
@dex_set = $2.to_i
when "RES", "RESISTANCE"
@res_set = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_state_nbs
end # RPG::State
#===============================================================================
# RPG::Enemy
#===============================================================================
class RPG::Enemy
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :dex
attr_accessor :res
#--------------------------------------------------------------------------
# common cache: yem_cache_enemy_nbs
#--------------------------------------------------------------------------
def yem_cache_enemy_nbs
return if @cached_enemy_nbs; @cached_enemy_nbs = true
@dex = eval(YEM::STATS::DEX::ENEMY_BASE)
@res = eval(YEM::STATS::RES::ENEMY_BASE)
#---
self.note.split(/[\r\n]+/).each { |line|
case line
#---
when YEM::REGEXP::ENEMY::BASE_STAT
case $1.upcase
when "DEX", "DEXTERITY"
@dex = $2.to_i
when "RES", "RESISTANCE"
@res = $2.to_i
end
#---
end
} # self.note.split
end # yem_cache_state_nbs
end # RPG::Enemy
#===============================================================================
# Vocab
#===============================================================================
module Vocab
#--------------------------------------------------------------------------
# new method: self.dex
#--------------------------------------------------------------------------
def self.dex; return YEM::STATS::DEX::VOCAB; end
#--------------------------------------------------------------------------
# new method: self.res
#--------------------------------------------------------------------------
def self.res; return YEM::STATS::RES::VOCAB; end
end # Vocab
#===============================================================================
# Scene_Title
#===============================================================================
class Scene_Title < Scene_Base
#--------------------------------------------------------------------------
# alias method: load_bt_database
#--------------------------------------------------------------------------
alias load_bt_database_nbs load_bt_database unless $@
def load_bt_database
load_bt_database_nbs
load_nbs_cache
end
#--------------------------------------------------------------------------
# alias method: load_database
#--------------------------------------------------------------------------
alias load_database_nbs load_database unless $@
def load_database
load_database_nbs
load_nbs_cache
end
#--------------------------------------------------------------------------
# new method: load_nbs_cache
#--------------------------------------------------------------------------
def load_nbs_cache
groups = [$data_skills, $data_items, $data_weapons, $data_armors,
$data_enemies, $data_states]
for group in groups
for obj in group
next if obj == nil
obj.yem_cache_baseitem_nbs if obj.is_a?(RPG::BaseItem)
obj.yem_cache_item_nbs if obj.is_a?(RPG::Item)
obj.yem_cache_state_nbs if obj.is_a?(RPG::State)
obj.yem_cache_enemy_nbs if obj.is_a?(RPG::Enemy)
end
end
end
end # Scene_Title
#===============================================================================
# Game_Battler
#===============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# anti-crash method: clear_battle_cache
#--------------------------------------------------------------------------
unless method_defined?(:clear_battle_cache)
def clear_battle_cache; @cache_params = {}; end
end # method_defined?(:clear_battle_cache)
#--------------------------------------------------------------------------
# anti-crash method: parameter_limit
#--------------------------------------------------------------------------
unless method_defined?(:parameter_limit)
def parameter_limit; return 999; end
end # method_defined?(:parameter_limit)
#--------------------------------------------------------------------------
# anti-crash method: stack
#--------------------------------------------------------------------------
unless method_defined?(:stack)
def stack(state); return 1; end
end # method_defined?(:stack)
#--------------------------------------------------------------------------
# alias method: item_growth_effect
#--------------------------------------------------------------------------
alias item_growth_effect_nbs item_growth_effect unless $@
def item_growth_effect(user, item)
item_growth_effect_nbs(user, item)
if item.stat_growth != {}
for key in item.stat_growth
stat = key[0]; value = key[1]
case stat
when :dex
@boost_dex += value
when :res
@boost_res += value
end
end
end
end
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: dex
#--------------------------------------------------------------------------
def dex
clear_battle_cache if @cache_params == nil
if $scene.is_a?(Scene_Battle)
return @cache_params[:dex] if @cache_params[:dex] != nil
end
#---
@dex_plus = 0 if @dex_plus == nil
n = [base_dex + @dex_plus, 1].max
for state in states
stack(state).times do
n = n * state.dex_rate / 100.0
end
end
for state in states
next if state.dex_set == 0
n += state.dex_set * stack(state)
end
#---
@cache_params[:dex] = [[Integer(n), parameter_limit].min, 1].max
return @cache_params[:dex]
end
#--------------------------------------------------------------------------
# new method: dex=
#--------------------------------------------------------------------------
def dex=(value)
@dex_plus = 0 if @dex_plus == nil
@dex_plus += value - self.dex
@dex_plus = [[@dex_plus, -parameter_limit].max, parameter_limit].min
clear_battle_cache
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: res
#--------------------------------------------------------------------------
def res
clear_battle_cache if @cache_params == nil
if $scene.is_a?(Scene_Battle)
return @cache_params[:res] if @cache_params[:res] != nil
end
#---
@res_plus = 0 if @res_plus == nil
n = [base_res + @res_plus, 1].max
for state in states
stack(state).times do
n = n * state.res_rate / 100.0
end
end
for state in states
next if state.res_set == 0
n += state.res_set * stack(state)
end
#---
@cache_params[:res] = [[Integer(n), parameter_limit].min, 1].max
return @cache_params[:res]
end
#--------------------------------------------------------------------------
# new method: res=
#--------------------------------------------------------------------------
def res=(value)
@res_plus = 0 if @res_plus == nil
@res_plus += value - self.res
@res_plus = [[@res_plus, -parameter_limit].max, parameter_limit].min
clear_battle_cache
end
#--------------------------------------------------------------------------
# overwrite method: make_obj_damage_value
#--------------------------------------------------------------------------
unless $imported["BattleEngineMelody"]
def make_obj_damage_value(user, obj)
damage = obj.base_damage
if damage > 0
damage += user.atk * 4 * obj.atk_f / 100
damage += user.spi * 2 * obj.spi_f / 100
unless obj.ignore_defense
damage -= self.def * 2 * obj.atk_f / 100
damage -= self.res * 1 * obj.spi_f / 100
end
damage = 0 if damage < 0
elsif damage < 0
damage -= user.atk * 4 * obj.atk_f / 100
damage -= user.spi * 2 * obj.spi_f / 100
end
damage *= elements_max_rate(obj.element_set)
damage /= 100
damage = apply_variance(damage, obj.variance)
damage = apply_guard(damage)
if obj.damage_to_mp
@mp_damage = damage
else
@hp_damage = damage
end
end
end # $imported["BattleEngineMelody"]
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Battler
#===============================================================================
# Game_Actor
#===============================================================================
class Game_Actor < Game_Battler
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: base_dex
#--------------------------------------------------------------------------
def base_dex
if YEM::STATS::DEX::ACTOR_BASE.include?(@actor_id)
n = eval(YEM::STATS::DEX::ACTOR_BASE[@actor_id])
else
n = eval(YEM::STATS::DEX::ACTOR_BASE[0])
end
#---
percent = 100
for equip in equips.compact
percent += equip.dex_per
end
n *= percent / 100.0
#---
for equip in equips.compact
n += equip.dex
end
#---
n += equip_skill_stat_bonus(:dex) if $imported["SkillEquipSystem"]
#---
@boost_dex = 0 if @boost_dex == nil
n += @boost_dex
return Integer(n)
end
#--------------------------------------------------------------------------
# alias method: hit
#--------------------------------------------------------------------------
alias hit_game_actor_nbs hit unless $@
def hit
n = hit_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_HIT)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: eva
#--------------------------------------------------------------------------
alias eva_game_actor_nbs eva unless $@
def eva
n = eva_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_EVA)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: cri
#--------------------------------------------------------------------------
alias cri_game_actor_nbs cri unless $@
def cri
n = cri_game_actor_nbs
n += eval(YEM::STATS::DEX::DEX_TO_CRI)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: base_res
#--------------------------------------------------------------------------
def base_res
if YEM::STATS::RES::ACTOR_BASE.include?(@actor_id)
n = eval(YEM::STATS::RES::ACTOR_BASE[@actor_id])
else
n = eval(YEM::STATS::RES::ACTOR_BASE[0])
end
#---
percent = 100
for equip in equips.compact
percent += equip.res_per
end
n *= percent / 100.0
#---
for equip in equips.compact
n += equip.res
end
#---
n += equip_skill_stat_bonus(:res) if $imported["SkillEquipSystem"]
#---
@boost_res = 0 if @boost_res == nil
n += @boost_res
return Integer(n)
end
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Actor
#===============================================================================
# Game_Enemy
#===============================================================================
class Game_Enemy < Game_Battler
if $imported["DEX Stat"]
#--------------------------------------------------------------------------
# new method: base_dex
#--------------------------------------------------------------------------
def base_dex
@boost_dex = 0 if @boost_dex == nil
result = Integer(enemy.dex) + @boost_dex
if $imported["EnemyLevels"]
base = result
per = enemy.growth_per[:dex]
set = enemy.growth_set[:dex]
result = Integer(eval(YEM::ENEMY_LEVEL::BASE_FORMULAS[:dex]))
end
return Integer(result)
end
#--------------------------------------------------------------------------
# alias method: hit
#--------------------------------------------------------------------------
alias hit_game_enemy_nbs hit unless $@
def hit
n = hit_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_HIT)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: eva
#--------------------------------------------------------------------------
alias eva_game_enemy_nbs eva unless $@
def eva
n = eva_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_EVA)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
# alias method: cri
#--------------------------------------------------------------------------
alias cri_game_enemy_nbs cri unless $@
def cri
n = cri_game_enemy_nbs
n += eval(YEM::STATS::DEX::DEX_TO_CRI)
return [Integer(n), 0].max
end
#--------------------------------------------------------------------------
end # imported["DEX Stat"]
if $imported["RES Stat"]
#--------------------------------------------------------------------------
# new method: base_res
#--------------------------------------------------------------------------
def base_res
@boost_res = 0 if @boost_res == nil
result = Integer(enemy.res) + @boost_res
if $imported["EnemyLevels"]
base = result
per = enemy.growth_per[:res]
set = enemy.growth_set[:res]
result = Integer(eval(YEM::ENEMY_LEVEL::BASE_FORMULAS[:res]))
end
return Integer(result)
end
#--------------------------------------------------------------------------
end # imported["RES Stat"]
end # Game_Enemy
#===============================================================================
# Window_Base
#===============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# alias method: draw_actor_parameter
#--------------------------------------------------------------------------
alias draw_actor_parameter_nbs draw_actor_parameter unless $@
def draw_actor_parameter(actor, x, y, type)
case type
when 4 # RES
parameter_name = Vocab::res
parameter_value = actor.res
when 5 # DEX
parameter_name = Vocab::dex
parameter_value = actor.dex
else
draw_actor_parameter_nbs(actor, x, y, type)
return
end
self.contents.font.color = system_color
self.contents.draw_text(x, y, 120, WLH, parameter_name)
self.contents.font.color = normal_color
self.contents.draw_text(x + 120, y, 36, WLH, parameter_value, 2)
end
end # Window_Base
#===============================================================================
# Window_Status
#===============================================================================
class Window_Status < Window_Base
#--------------------------------------------------------------------------
# alias method: draw_parameters
#--------------------------------------------------------------------------
alias draw_parameters_nbs draw_parameters unless $@
def draw_parameters(x, y)
draw_parameters_nbs(x, y)
dy = y+WLH*3
if $imported["RES Stat"]
dy += WLH
draw_actor_parameter(@actor, x, dy, 4)
end
if $imported["DEX Stat"]
dy += WLH
draw_actor_parameter(@actor, x, dy, 5)
end
end
end # Window_Status
#===============================================================================
#
# END OF FILE
#
#===============================================================================