Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Magic Defense script that doesn't mess up healing, Enelvon's and Yanfly's not working for me
sillypieman
post Feb 20 2013, 11:11 AM
Post #1


I's Pac Manz!
Group Icon

Group: Revolutionary
Posts: 2,418
Type: Developer
RM Skill: Advanced




I tried using Yanfly's script, but when I tried to play it with most of the extra stats disabled it would give me errors. I think it was conflicting with the Tankentai battle system.

So I found Enelvon's Resistance/Luck script. It's simple, and it does exactly what I need it to do--provide a magic defense stat. The problem is: all healing spells just heal for the damage amount, and they aren't affected by spirit at all.

And I did confirm that it is this script causing it, because when I take it out the healing spells work fine. Also doing Ignore Defense for the healing spells doesn't help either. It's very strange, and I would greatly appreciate any help or insight. Thanks in advance!


P.S. Here's the script I'm using.
CODE
module RESISTANCE
#-------------------------------------------------------------------------------
#
# Resistance/Magic Defense System v2.4
# Written by Enelvon
# THIS SCRIPT IS RPGMAKERVX.NET EXCLUSIVE! Please do not distribute it
# elsewhere.
#
# This script allows you to have a Resistance stat that replaces the default
# method of defense from Spirit-based skill attacks, which I found to be
# ridiculous. With this script, setting up enemy Res is ESSENTIAL unless you
# want them to always take full damage from Spirit-based skills.
#
#
# Instructions:
# 1. Place this above Main. If you use my Luck script, place it above that as
# well.
# 2. Change the Vocabulary for Resistance to whatever you want it to be called.
# Vocabulary
Resistance = "Resistance"
Res_abr = "RES" # Abbreviation for Resistance
LIMIT_BREAK = false # Set this to true to allow actors to pass 999 resistance.

class Res_Information # Ignore this.
def self.initiate_res # Ignore this.
# 4. Define each Actor's Res growth.
# To define an Actor's Res, use this snippet:
# set_res_growth(Actor ID, Base Luck, Res Gained Per Level)
#-------------------------------------------------------------------------------
# Place Actor Res growths below here. Remember, use ONLY lowercase letters.
set_res_growth(1, 0, 1) # example - delete/change as needed.
set_res_growth(2, 0, 1)
set_res_growth(3, 0, 1)



#-------------------------------------------------------------------------------
# 5. To increase an Actor's Res in an event, use this in the Script event
# command:
# "$data_actors[actor_id].inc_res(val)"
# 6. To have weapons or armors add to the Actor's Res stat, add this tag into
# their Notes field: '<RES n>' (without the quotes). Replace n with the number
# you want it to add. If you want it to subtract from the Res stat, use
# '<SUB_RES n>' (without the quotes). Replace n with the number you want it
# to subtract - no negative sign. That's all!
# 7. To have a state influence the Res stat, in the Notes field of the state add
# this tag: '<AFFECT_RES n>' (without the quotes). Replace n with the number
# (as a percent without the percent sign) you want the state to change by.
# For example, <AFFECT_RES 50> would have the Actor's Res stat, while
# <AFFECT_RES 200> would double it. The default (you don't need to add anything)
# for a state is an invisible <AFFECT_RES 100>, or no change.
end
end
end

class Game_Enemy < Game_Battler
def res #Set the Res stat for Enemies
case @enemy_id
when 12 #Big Scaly 1
return 19 #Resistance stat
when 41 #Big Scaly 2 (train)
return 20
when 42 #Big Scaly 2 (train)
return 20
when 72 #Swamp King
return 24
when 19 #Xavier Shadow
return 35
when 20 #Lion
return 25
end
return 8 #default Enemy Res
end
def base_res
return enemy.res
end
end

# this is the window display in status
class Window_Status < Window_Base
alias res_draw_params draw_parameters
def draw_parameters(x, y)
draw_actor_parameter(@actor, x, y + WLH * 0, 0)
draw_actor_parameter(@actor, x, y + WLH * 1, 1)
draw_actor_parameter(@actor, x, y + WLH * 2, 2)
draw_actor_parameter(@actor, x, y + WLH * 3, 3)
draw_actor_parameter(@actor, x, y + WLH * 4, 4)
#draw_actor_parameter(@actor, x, y + WLH * 5, 5)
end
end

class Window_Base < Window
alias create_res_param_draw draw_actor_parameter
def draw_actor_parameter(actor, x, y, type)
case type
when 0
parameter_name = Vocab::atk
parameter_value = actor.atk
when 1
parameter_name = Vocab::def
parameter_value = actor.def
when 2
parameter_name = Vocab::spi
parameter_value = actor.spi
when 3
parameter_name = Vocab::agi
parameter_value = actor.agi
when 4
parameter_name = RESISTANCE::Res_abr
parameter_value = actor.res
#when 5
#parameter_name = Luck::Luck_abr
#parameter_value = actor.luck
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


module RESISTANCE
class Res_Information
def self.set_res_growth(actor_index, base, growth)
actor = $data_actors[actor_index]
actor.res_base = base
actor.res_growth = growth
end
end
end

module RPG
class Actor
def res(level)
base = @res_base != nil ? @res_base : 0
growth = @res_growth != nil ? @res_growth : 0
res = base + growth*level
if RESISTANCE::LIMIT_BREAK == false
unless res > 999
return res
else
res = 999
return res
end
elsif RESISTANCE::LIMIT_BREAK == true
return res
end
end
def inc_res(num)
index = self.id
@res_base += num
actor = $game_actors[index]
actor.res = res(actor.level)
end
attr_writer :res_base
attr_writer :res_growth
end
end

#-------------------------------------------------------------------------------
class Game_Battler

alias enelvon_res_value_clear clear_extra_values
def clear_extra_values
@maxhp_plus = 0
@maxmp_plus = 0
@atk_plus = 0
@def_plus = 0
@spi_plus = 0
@agi_plus = 0
@res_plus = 0
@lck_plus = 0
end

def res
n = [[base_res + @res_plus, 1].max, 999].min
for state in states
note = state.note
note.gsub(/<AFFECT_RES ([0-9]*)>/) {}
s = $1.to_i
n *= s / 100.0
end
n = [[Integer(n), 1].max, 999].min
return n
end

def res=(new_res)
@res_plus += new_res - self.res
@res_plus = [[@res_plus, -999].max, 999].min
end

alias enelvon_res_skill_damage :make_obj_damage_value
def make_obj_damage_value(user, obj)
damage = obj.base_damage # get base damage
if damage > 0 # a positive number?
damage += user.atk * 4 * obj.atk_f / 100 # Attack F of the user
damage += user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
unless obj.ignore_defense # Except for ignore defense
damage -= self.def * 2 * obj.atk_f / 100
damage -= self.res * 2 * obj.spi_f / 100
end
damage = 0 if damage < 0 # If negative, make 0
if damage < 0 # a negative number?
damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
end
end
damage *= elements_max_rate(obj.element_set) # elemental adjustment
damage /= 100
damage = apply_variance(damage, obj.variance) # variance
damage = apply_guard(damage) # guard adjustment
if obj.damage_to_mp
@mp_damage = damage # damage MP
else
@hp_damage = damage # damage HP
end
end
end

#-------------------------------------------------------------------------------
class Game_Actor < Game_Battler
def base_res
n = actor.res(@level)
for weapon in weapons.compact
note = weapon.note
note.gsub(/<RES ([0-9]*)>/) {}
w = $1.to_i
unless 1000 <= n + w
n += w
end
end
for weapon in weapons. compact
note = weapon.note
note.gsub(/<SUB_RES ([0-9]*)>/) {}
ws = $1.to_i
unless 0 > n - ws
n -= ws
end
end
for armor in armors.compact
note = armor.note
note.gsub(/<RES ([0-9]*)>/) {}
a = $1.to_i
unless 1000 <= n + a
n += a
end
end
for armor in armors.compact
note = armor.note
note.gsub(/<SUB_RES ([0-9]*)>/) {}
as = $1.to_i
unless 0 > n - as
n -= as
end
end
return n
end
end
#==============================================================================
# ** Game_Enemies
#------------------------------------------------------------------------------
# This class handles the enemy array. The instance of this class is
# referenced by $game_enemies.
#==============================================================================

class Game_Enemies
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Enemy
# enemy_id : enemy ID
#--------------------------------------------------------------------------
def [](enemy_id)
if @data[enemy_id] == nil and $data_enemies[enemy_id] != nil
@data[enemy_id] = Game_Enemy.new(0,enemy_id)
end
return @data[enemy_id]
end
end

#-------------------------------------------------------------------------------
class Scene_Title < Scene_Base
alias res_start start
def start
res_start
set_up_res
end
def set_up_res
RESISTANCE::Res_Information::initiate_res
end
alias enelvon_res_game create_game_objects
def create_game_objects
$game_enemies = Game_Enemies.new
enelvon_res_game
end
end


Edit: Starting on line 203 it has:
damage = 0 if damage < 0 # If negative, make 0
if damage < 0 # a negative number?
damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
end

I'm thinking it has something to do with that. I'm messing around with it and still can't figure it out.

This post has been edited by sillypieman: Feb 20 2013, 11:18 AM


__________________________
Lucid Awakening 2 Demo released!

===================

Momiji's Gamer Blog
Get exclusive information about my RPG Maker projects, downloads to my games and demos, and other gamer reviews, opinions, rants, and whatever else is on my mind. Get inside the head of Sillypieman.
Go to the top of the page
 
+Quote Post
   
sillypieman
post Feb 20 2013, 11:43 AM
Post #2


I's Pac Manz!
Group Icon

Group: Revolutionary
Posts: 2,418
Type: Developer
RM Skill: Advanced




Okay, I ended up fixing it myself after a lot of experimentation. Here is the part I changed:
CODE
alias enelvon_res_skill_damage :make_obj_damage_value
def make_obj_damage_value(user, obj)
damage = obj.base_damage # get base damage
if damage > 0
  if damage > 0 # a positive number?
    damage += user.atk * 4 * obj.atk_f / 100 # Attack F of the user
    damage += user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
    unless obj.ignore_defense # Except for ignore defense
    damage -= self.def * 2 * obj.atk_f / 100
    damage -= self.res * 2 * obj.spi_f / 100
  end
  damage = 0 if damage < 0 # If negative, make 0
    if damage < 0 # a negative number?
      damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
      damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
    end
  end
else
    damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
    damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
end


I added an If statement before all the damage calculation to check if it was greater than 0. If it is, it would do the normal damage calculation he had written. If not (less than 0, which means a healing spell), it would just SUBTRACT instead of ADD in the spirit stat, and wouldn't do all the defense calculation.

Here's the modified script in case anyone is looking for something like this:
CODE
module RESISTANCE
#-------------------------------------------------------------------------------
#
# Resistance/Magic Defense System v2.4
# Written by Enelvon
# THIS SCRIPT IS RPGMAKERVX.NET EXCLUSIVE! Please do not distribute it
# elsewhere.
#
#-------------------------------------------------------------------------------
# Modified by Matthew M. Sharp (a.k.a. Sillypieman) 2/20/2013
# Changed damage calculation so that healing spells weren't affected by
# resistance, and increased along with the caster's Spirit stat.
#-------------------------------------------------------------------------------
# This script allows you to have a Resistance stat that replaces the default
# method of defense from Spirit-based skill attacks, which I found to be
# ridiculous. With this script, setting up enemy Res is ESSENTIAL unless you
# want them to always take full damage from Spirit-based skills.
#
#
# Instructions:
# 1. Place this above Main. If you use my Luck script, place it above that as
# well.
# 2. Change the Vocabulary for Resistance to whatever you want it to be called.
# Vocabulary
Resistance = "Resistance"
Res_abr = "RES" # Abbreviation for Resistance
LIMIT_BREAK = false # Set this to true to allow actors to pass 999 resistance.

class Res_Information # Ignore this.
def self.initiate_res # Ignore this.
# 4. Define each Actor's Res growth.
# To define an Actor's Res, use this snippet:
# set_res_growth(Actor ID, Base Luck, Res Gained Per Level)
#-------------------------------------------------------------------------------
# Place Actor Res growths below here. Remember, use ONLY lowercase letters.
set_res_growth(1, 0, 1) # example - delete/change as needed.
set_res_growth(2, 0, 1)
set_res_growth(3, 0, 1)



#-------------------------------------------------------------------------------
# 5. To increase an Actor's Res in an event, use this in the Script event
# command:
# "$data_actors[actor_id].inc_res(val)"
# 6. To have weapons or armors add to the Actor's Res stat, add this tag into
# their Notes field: '<RES n>' (without the quotes). Replace n with the number
# you want it to add. If you want it to subtract from the Res stat, use
# '<SUB_RES n>' (without the quotes). Replace n with the number you want it
# to subtract - no negative sign. That's all!
# 7. To have a state influence the Res stat, in the Notes field of the state add
# this tag: '<AFFECT_RES n>' (without the quotes). Replace n with the number
# (as a percent without the percent sign) you want the state to change by.
# For example, <AFFECT_RES 50> would have the Actor's Res stat, while
# <AFFECT_RES 200> would double it. The default (you don't need to add anything)
# for a state is an invisible <AFFECT_RES 100>, or no change.
end
end
end

class Game_Enemy < Game_Battler
def res #Set the Res stat for Enemies
case @enemy_id
when 12 #Big Scaly 1
return 19 #Resistance stat
when 41 #Big Scaly 2 (train)
return 20
when 42 #Big Scaly 2 (train)
return 20
when 72 #Swamp King
return 24
when 19 #Xavier Shadow
return 35
when 20 #Lion
return 25
end
return 8 #default Enemy Res
end
def base_res
return enemy.res
end
end

# this is the window display in status
class Window_Status < Window_Base
alias res_draw_params draw_parameters
def draw_parameters(x, y)
draw_actor_parameter(@actor, x, y + WLH * 0, 0)
draw_actor_parameter(@actor, x, y + WLH * 1, 1)
draw_actor_parameter(@actor, x, y + WLH * 2, 2)
draw_actor_parameter(@actor, x, y + WLH * 3, 3)
draw_actor_parameter(@actor, x, y + WLH * 4, 4)
#draw_actor_parameter(@actor, x, y + WLH * 5, 5)
end
end

class Window_Base < Window
alias create_res_param_draw draw_actor_parameter
def draw_actor_parameter(actor, x, y, type)
case type
when 0
parameter_name = Vocab::atk
parameter_value = actor.atk
when 1
parameter_name = Vocab::def
parameter_value = actor.def
when 2
parameter_name = Vocab::spi
parameter_value = actor.spi
when 3
parameter_name = Vocab::agi
parameter_value = actor.agi
when 4
parameter_name = RESISTANCE::Res_abr
parameter_value = actor.res
#when 5
#parameter_name = Luck::Luck_abr
#parameter_value = actor.luck
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


module RESISTANCE
class Res_Information
def self.set_res_growth(actor_index, base, growth)
actor = $data_actors[actor_index]
actor.res_base = base
actor.res_growth = growth
end
end
end

module RPG
class Actor
def res(level)
base = @res_base != nil ? @res_base : 0
growth = @res_growth != nil ? @res_growth : 0
res = base + growth*level
if RESISTANCE::LIMIT_BREAK == false
unless res > 999
return res
else
res = 999
return res
end
elsif RESISTANCE::LIMIT_BREAK == true
return res
end
end
def inc_res(num)
index = self.id
@res_base += num
actor = $game_actors[index]
actor.res = res(actor.level)
end
attr_writer :res_base
attr_writer :res_growth
end
end

#-------------------------------------------------------------------------------
class Game_Battler

alias enelvon_res_value_clear clear_extra_values
def clear_extra_values
@maxhp_plus = 0
@maxmp_plus = 0
@atk_plus = 0
@def_plus = 0
@spi_plus = 0
@agi_plus = 0
@res_plus = 0
@lck_plus = 0
end

def res
n = [[base_res + @res_plus, 1].max, 999].min
for state in states
note = state.note
note.gsub(/<AFFECT_RES ([0-9]*)>/) {}
s = $1.to_i
n *= s / 100.0
end
n = [[Integer(n), 1].max, 999].min
return n
end

def res=(new_res)
@res_plus += new_res - self.res
@res_plus = [[@res_plus, -999].max, 999].min
end

alias enelvon_res_skill_damage :make_obj_damage_value
def make_obj_damage_value(user, obj)
damage = obj.base_damage # get base damage
if damage > 0
  if damage > 0 # a positive number?
    damage += user.atk * 4 * obj.atk_f / 100 # Attack F of the user
    damage += user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
    unless obj.ignore_defense # Except for ignore defense
    damage -= self.def * 2 * obj.atk_f / 100
    damage -= self.res * 2 * obj.spi_f / 100
  end
  damage = 0 if damage < 0 # If negative, make 0
    if damage < 0 # a negative number?
      damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
      damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
    end
  end
else
    damage -= user.atk * 4 * obj.atk_f / 100 # Attack F of the user
    damage -= user.spi * 2 * obj.spi_f / 100 # Spirit F of the user
end
damage *= elements_max_rate(obj.element_set) # elemental adjustment
damage /= 100
damage = apply_variance(damage, obj.variance) # variance
damage = apply_guard(damage) # guard adjustment
if obj.damage_to_mp
@mp_damage = damage # damage MP
else
@hp_damage = damage # damage HP
end
end
end

#-------------------------------------------------------------------------------
class Game_Actor < Game_Battler
def base_res
n = actor.res(@level)
for weapon in weapons.compact
note = weapon.note
note.gsub(/<RES ([0-9]*)>/) {}
w = $1.to_i
unless 1000 <= n + w
n += w
end
end
for weapon in weapons. compact
note = weapon.note
note.gsub(/<SUB_RES ([0-9]*)>/) {}
ws = $1.to_i
unless 0 > n - ws
n -= ws
end
end
for armor in armors.compact
note = armor.note
note.gsub(/<RES ([0-9]*)>/) {}
a = $1.to_i
unless 1000 <= n + a
n += a
end
end
for armor in armors.compact
note = armor.note
note.gsub(/<SUB_RES ([0-9]*)>/) {}
as = $1.to_i
unless 0 > n - as
n -= as
end
end
return n
end
end
#==============================================================================
# ** Game_Enemies
#------------------------------------------------------------------------------
# This class handles the enemy array. The instance of this class is
# referenced by $game_enemies.
#==============================================================================

class Game_Enemies
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Enemy
# enemy_id : enemy ID
#--------------------------------------------------------------------------
def [](enemy_id)
if @data[enemy_id] == nil and $data_enemies[enemy_id] != nil
@data[enemy_id] = Game_Enemy.new(0,enemy_id)
end
return @data[enemy_id]
end
end

#-------------------------------------------------------------------------------
class Scene_Title < Scene_Base
alias res_start start
def start
res_start
set_up_res
end
def set_up_res
RESISTANCE::Res_Information::initiate_res
end
alias enelvon_res_game create_game_objects
def create_game_objects
$game_enemies = Game_Enemies.new
enelvon_res_game
end
end


This can be closed now smile.gif


__________________________
Lucid Awakening 2 Demo released!

===================

Momiji's Gamer Blog
Get exclusive information about my RPG Maker projects, downloads to my games and demos, and other gamer reviews, opinions, rants, and whatever else is on my mind. Get inside the head of Sillypieman.
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 19th May 2013 - 01:21 PM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker