The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX Ace => VXA Scripts Database => Topic started by: SoulPour777 on August 13, 2014, 05:33:52 PM

Title: Soulpour777 – Magic Critical Orpheus
Post by: SoulPour777 on August 13, 2014, 05:33:52 PM
Magic Critial Orpheus
Version: 1.0
Author: Soulpour777
Date: 8 / 14 / 2014 - 1:11AM

Description


Description:
This script allows the developer to create a Magic Critical chance and damage. This makes not only physical attacks gain a critical hit by default but also gains a magic critical when certain magic is applied to the enemy when a certain armor is equipped. These armors that can cause a magic critical are bound by a certain notetag.

In addition, the magic critical's formula is as follows:

item.damage.critical ? user.mat * (Subtract_to_Mev_Initial - mev) : 0
or in other words, it bases on the user's magical attack multiplied by the result of the Subtract_to_Mev_Initial and Magical Evasion Rate. This is based from how critical hits are defaultly done.

Features


Instructions

Note Tags:
To make an armor create a Magic Critical, put this on the armor's notes:
<magcrit>

Script


Code: [Select]
#==============================================================================
# ** Magic Critical Orpheus
# Author: Soulpour777
# Web URL: infinitytears.wordpress.com
# 8 / 14 / 2014 - 1:11AM
#------------------------------------------------------------------------------
# Description:
# This script allows the developer to create a Magic Critical chance and
# damage. This makes not only physical attacks gain a critical hit by default
# but also gains a magic critical when certain magic is applied to the enemy
# when a certain armor is equipped. These armors that can cause a magic critical
# are bound by a certain notetag.
# In addition, the magic critical's formula is as follows:
# item.damage.critical ? user.mat * (Subtract_to_Mev_Initial - mev) : 0
# or in other words, it bases on the user's magical attack multiplied by
# the result of the Subtract_to_Mev_Initial and Magical Evasion Rate. This
# is based from how critical hits are defaultly done.
#------------------------------------------------------------------------------
# Features:
# The developer has the following features to look at:
# 1. You can assign the Mev Initial Value
# 2. You can assign the damage multiplied to the original damage during Mag Crit
# 3. Add customized dialogs to show the result in each.
#------------------------------------------------------------------------------
# Note Tags:
# To make an armor create a Magic Critical, put this on the armor's notes:
# /<magcrit>/i
#------------------------------------------------------------------------------
# Terms of Use:
# This script is originally written by Soulpour777. Therefore, the script
# below is under his terms of use. This script is free for both commercial
# and non commercial use. If this script is used, please give proper credit.
#------------------------------------------------------------------------------
# The user is free to:
# Modify the script
# Adapt the script
#------------------------------------------------------------------------------
#==============================================================================
module Soulpour
  module Magic_Critical_Orpheus
    # The Initial Value Subtracted to the Actor's Magical Evasion Rate
    Subtract_to_Mev_Initial = 1
    # The damage multiplied to the original damage as Magic Critical
    Mag_Crit_Damage = 3 #=> Same Default as Critical Hits
    # Magic Critical Damage when applied to actor
    MagCrit_To_Actor = "A magnificent magical blow!"
    # Magic Critical Damage when applied to enemy
    MagCrit_To_Enemy = "A powerful magical attack!"
  end
end


class Game_ActionResult
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------- 
  attr_accessor                                                   :magcrit
  #--------------------------------------------------------------------------
  # * Alias Listings
  #-------------------------------------------------------------------------- 
  alias :soul_magic_critical_rgss_clear_hit_flags            :clear_hit_flags
  alias :soul_magic_critical_rgss_make_damage                    :make_damage
  #--------------------------------------------------------------------------
  # * Clear Hit Flags
  #--------------------------------------------------------------------------
  def clear_hit_flags
    soul_magic_critical_rgss_clear_hit_flags
    @magcrit = false
  end 
 
  #--------------------------------------------------------------------------
  # * Create Damage
  #--------------------------------------------------------------------------
  def make_damage(value, item)
    @magcrit = false if value == 0
    soul_magic_critical_rgss_make_damage(value, item)
  end 
 
end

class Game_System
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias :soul_magic_critical_display_initialize                   :initialize
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #-------------------------------------------------------------------------- 
  attr_accessor                                      :magcrit_display_message
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    soul_magic_critical_display_initialize
    @magcrit_display_message = nil
  end
end


class Game_Battler < Game_BattlerBase
  include Soulpour::Magic_Critical_Orpheus
  #--------------------------------------------------------------------------
  # * Calculate Critical Rate of Skill/Item
  #--------------------------------------------------------------------------
  def mag_cri(user, item)
    item.damage.critical ? user.mat * (Subtract_to_Mev_Initial - mev) : 0
  end 
  #--------------------------------------------------------------------------
  # * Apply Critical
  #--------------------------------------------------------------------------
  def apply_magcrit(damage)
    damage * Mag_Crit_Damage
  end
  #--------------------------------------------------------------------------
  # * Apply Effect of Skill/Item
  #--------------------------------------------------------------------------
  def item_apply(user, item)
    @result.clear
    @result.used = item_test(user, item)
    @result.missed = (@result.used && rand >= item_hit(user, item))
    @result.evaded = (!@result.missed && rand < item_eva(user, item))
    if @result.hit?
      unless item.damage.none?
        @result.critical = (rand < item_cri(user, item))
        @result.magcrit = (rand < mag_cri(user, item))
        make_damage_value(user, item)
        execute_damage(user)
      end
      item.effects.each {|effect| item_effect_apply(user, item, effect) }
      item_user_effect(user, item)
    end
  end 
  #--------------------------------------------------------------------------
  # * Calculate Damage
  #--------------------------------------------------------------------------
  def make_damage_value(user, item)
    value = item.damage.eval(user, self, $game_variables)
    value *= item_element_rate(user, item)
    value *= pdr if item.physical?
    if item.magical?
      if user.is_a?(Game_Actor)
        user.equips.each do |equip|
          next unless equip
          if equip.note=~ /<magcrit>/i
            value *= mdr + apply_magcrit(value)
          else
            value *= mdr
          end
        end
      else
        value *= mdr
      end
    end
    value *= rec if item.damage.recover?
    value = apply_critical(value) if @result.critical
    $game_system.magcrit_display_message = true if @result.magcrit
    value = apply_magcrit(value) if @result.magcrit
    value = apply_variance(value, item.damage.variance)
    value = apply_guard(value)
    @result.make_damage(value.to_i, item)
  end
end

class Window_BattleLog < Window_Selectable
  include Soulpour::Magic_Critical_Orpheus
  #--------------------------------------------------------------------------
  # * Display Critical Hit
  #--------------------------------------------------------------------------
  def display_magic_critical(target, item)
    if $game_system.magcrit_display_message
      text = target.actor? ? MagCrit_To_Actor : MagCrit_To_Enemy
      add_text(text)
      wait
    end
  end
  #--------------------------------------------------------------------------
  # * Display Action Results
  #--------------------------------------------------------------------------
  def display_action_results(target, item)
    if target.result.used
      last_line_number = line_number
      display_magic_critical(target, item)
      display_damage(target, item)
      display_affected_status(target, item)
      display_failure(target, item)
      wait if line_number > last_line_number
      back_to(last_line_number)
    end
  end 
end

Credit



Support


For support, please comment down or PM me at this forum.

Known Compatibility Issues

None

Author's Notes


If you are wondering why all my new scripts are entitled with Orpheus, its a Phi Brain reference.

Terms of Use


Terms of Use:
This script is originally written by Soulpour777. Therefore, the script below is under his terms of use. This script is free for both commercial and non commercial use. If this script is used, please give proper credit.

The user is free to:
Modify the script
Adapt the script
Title: Re: Soulpour777 – Magic Critical Orpheus
Post by: modern algebra on August 17, 2014, 09:40:09 PM
Thanks for sharing that Soulpour. I guess I had never noticed that magic attacks couldn't critical.
Title: Re: Soulpour777 – Magic Critical Orpheus
Post by: Arrow on August 17, 2014, 10:10:38 PM
I like this idea. Magic is typically explained away as being a product of the caster's intellect or spiritual bond to the elements. It would make sense then that if something in their head just *clicked* at the right moment and they had an epiphany, or if they happened to be tapping into an especially rich reserve of energy, they'd get a bigger boom.

Do you think it would be possible to add support for unique magi-crit animations?
Title: Re: Soulpour777 – Magic Critical Orpheus
Post by: yuyu! on August 18, 2014, 01:03:35 AM
Thanks for sharing that Soulpour. I guess I had never noticed that magic attacks couldn't critical.

Huh. o.o I didn't notice that either...

Seems like a pretty cool script to even things out for the magic users! B) I've considered games where some characters fight with magical attacks only, and this will come in handy! Thanks, soulpour! Your scripts are awesome, as usual. :)