iPhone App Directory
RPG Maker VX
 
Gallery Members Search Calendar Help


Welcome Guest ( Log In | Register )

Collapse

>Announcement

Keep an eye out for the upcoming 3rd Quarter Contest!
 
Reply to this topicStart new topic
> Damage Limit / Critical Damage Selection (1.3), Limit damage and/or choose your own critical damage mod.
Rating 5 V
Mithran
post Jan 23 2009, 07:46 PM
Post #1


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Damage Limit / Attack Critical Damage Selection v 1.3c
by Mithran


Introduction
I didn't see it here, so why not. This small script to limit the damage from all attacks in addition to allowing you to choose your own damage modifier for critical hits. This script should be compatiable with nearly every script. It is compatable with my critical skills script as well, and will be required for future versions.

Features
- Impose a damage limit on all attacks
- Lift the damage limit on specific battlers through note tag use
- Set your own critical damage modifier for each weapon and/or change the global modifier
- allow critical to ignore defense, if you desire
- set a global damage modifier, giving a semblance of smaller damage algorithms, if you desire
- all methods are aliased, high compatability

How to Use
Needs to be placed in materials below all other custom scripts, but above main. Customization module is at the top of the script.

Script
Spoiler:
CODE
# Damage Limit / Attack Critical Damage Selection
# v 1.3c
# By Mithran
# Updated March 23, 2010
=begin

This short script allows players to, by use of the customization module
at the top of the script, limit the damage that both players and enemies
deal to a maximum amount.  It also allows the use of a note tag on equipment
or enemy note tags to disable the damage cap and use a secondary damage
cap instead.

New in v 1.3!
Edit Critical Damage Rate by note tags
Use either or both of the following note tags to set the critical damage rate
of any enemy or piece of equipment.  If the enemy has no critical altering
notes or an actor is using no equipment with critical altering notes, the
default set below will be used.

<BASE CRI DMG nn%>
sets the base cri damage rate.  replace nn with the percent you want to use
Example:
<BASE CRI DMG 200%>
Criticals will deal twice the damage as normal attacks.  This overrides the
CRITICAL_DAMAGE_MOD setting in the module.

<CRI DMG (+-) nn%>
use either plus or minus, no parenthesis
replace nn with the percent you want to use
Example:
<CRI DMG + 5%>
Increases critical damage by 5%.  Can be combined with the base crit damage.
Eg., if it was 300% before, it would become 305%.  
Minimum damage for criticals is 100% of a normal attack (it will never be reduced).

<CRITICAL IGNORE DEFENSE>
<NO CRITICAL IGNORE DEFENSE>
Overrides the default CRITICAL_IGNORE_DEFENSE setting below for the given item
or skill.  For actors, only weapons are checked.  If either weapon ignores
defense, all normal attack criticals will.  For skills, only the critical ignore
defense value for the skill itself is checked, the battler does not matter.

New in v 1.2!
Now allows scaling of all damage through a setting in the module.  This allows
the semblance of a smaller damage algorithm, without actually editing the
algorithm itself.

Critical Ignore Defense -
Set this to true to have all critical hits ignore targets' defense.
Works for both normal attacks and skills.

Usage: Set up the appropriate values in the module below.  

To break damage limit, put the following in the note tag for equipment or on
the enemy:

<BREAK DAMAGE LIMIT>

All caps is required.  They will then use the secondary defined damage limit.
Setting either limit to zero will remove the cap from battlers in that category.
Setting USE_DAMAGE_LIMIT to false will turn off all damage limiting.

Install:  Place above main and below all custom scripts.

=end

$imported = {} if $imported == nil
$imported["DamageLimit"] = true

#==============================================================================#
#                                      * Customization *
#==============================================================================#

module Mithran
  module DamageLimit
    ACTOR_DAMAGE_LIMIT = 9999
    # Damage limit for actors
    ACTOR_BREAK_DAMAGE_LIMIT = 99999
    # Damage limit for actors with <BREAK DAMAGE LIMIT>
    
    ENEMY_DAMAGE_LIMIT = 9999
    # Damage limit for enemies
    ENEMY_BREAK_DAMAGE_LIMIT = 99999  
    # Damage limit for enemies with <BREAK DAMAGE LIMIT>
    
    MP_DAMAGE_DENOMINATOR = 10.0
    # The value that each damage limit is divided by to get the limit for MP damage.
    # At 10, the default mp damage limit is 999 and the break limit is 9999
      
    USE_DAMAGE_LIMIT = true
    # if set to false, ALL damage limiting is disabled
  end # <- Do not alter this line
  
  module CriticalDamage
    CRITICAL_DAMAGE_MOD = 3.0
    # Default damage for a critical hit is 3.0 times the normal amount
    # Changing this will change the default damage rate on all critical
    
    CRITICAL_IGNORE_DEFENSE = false
# By default, critical attacks do not ignore defense. Edit this value accordingly.
# If set to true, this will make normal attacks, when critical, do damage as
# if the targets 'defense' paramter were zero
# This will make skills act as if the 'ignore defense' box was checked when critting
# Can be overriden by the individual note settings in the module.
  end # <- Do not alter this line
  
  module ScaleDamage
    SCALE_DAMAGE_MOD = 1.0
    # All damage, both HP and MP, will be multipled by this amount
    # leaving it at 1.0 will make no changes to the system
    # If you use numbers less than 1, be sure to lead with a 0.
    # Changing it to a smaller number will lower all damage in the game, and
    # a larger number will increase all damage.  This can give you control over
    # the amount of damage dealt without editing the battle algorithms
    # (NOTE - if damage was 1 or more before scaling, it will remain at least 1
    # after scaling.  All other damage will be rounded)
    
#==============================================================================#
#                                   * Customization End *
#==============================================================================#
  end
end

class Game_Battler
  alias make_attack_damage_value_damagelimit make_attack_damage_value
  def make_attack_damage_value(attacker)
    pre_crit_check(attacker)
    @temp_dl_normal_attack = true if attacker.critical_ignore_defense
    make_attack_damage_value_damagelimit(attacker)
    @hp_damage *= 3 if !@critical && @pre_critical
    @mp_damage *= 3 if !@critical && @pre_critical
    @critical = @pre_critical
    @critical = false if @hp_damage == 0 && @mp_damage == 0
    make_new_critical_damage_value(attacker) if @critical
    scale_damage if Mithran::ScaleDamage::SCALE_DAMAGE_MOD != 1.0
    limit_damage(attacker) if Mithran::DamageLimit::USE_DAMAGE_LIMIT
    @pre_critical = false
    @temp_dl_normal_attack = false
  end
  
  alias :def_damagelimit :def
  def def
    return 0 if @pre_critical && @temp_dl_normal_attack
    return def_damagelimit
  end
  
  alias make_obj_damage_value_damagelimit make_obj_damage_value
  def make_obj_damage_value(user, obj)
    obj.temp_ignore_def = false
    pre_crit_check(user, obj)
    obj.temp_ignore_def = true if @pre_critical && obj.critical_ignore_defense
    make_obj_damage_value_damagelimit(user, obj)
    @critical = @pre_critical
    make_obj_critical_damage_value(user, obj) if $imported["MithranCriticalSkills"]
    make_new_critical_damage_value(user, obj) if @critical
    scale_damage if Mithran::ScaleDamage::SCALE_DAMAGE_MOD != 1.0
    limit_damage(user) if Mithran::DamageLimit::USE_DAMAGE_LIMIT
    @pre_critical = false
    obj.temp_ignore_def = false
  end
  
  def pre_crit_check(user, obj = nil)
    @pre_critical = false
    if obj != nil
      @pre_critical = determine_obj_critical(user, obj) if $imported["MithranCriticalSkills"] && obj.critical_allowed
    else      
      @pre_critical = (rand(100) < user.cri)
      @pre_critical = false if prevent_critical
    end
  end
  
  alias execute_damage_damagelimit execute_damage
  def execute_damage(user)
    limit_damage(user) if Mithran::DamageLimit::USE_DAMAGE_LIMIT
    execute_damage_damagelimit(user)
  end
  
  def scale_damage
    pre_scale_hp = @hp_damage
    pre_scale_mp = @mp_damage
    @hp_damage *= Mithran::ScaleDamage::SCALE_DAMAGE_MOD
    @mp_damage *= Mithran::ScaleDamage::SCALE_DAMAGE_MOD
    @hp_damage = @hp_damage.round
    @mp_damage = @mp_damage.round
    if @hp_damage == 0 && pre_scale_hp > 0
      @hp_damage = 1
    elsif @hp_damage == 0 && pre_scale_hp < 0
      @hp_damage = -1
    end
    if @mp_damage == 0 && pre_scale_mp > 0
      @mp_damage = 1
    elsif @mp_damage == 0 && pre_scale_mp < 0
      @mp_damage = -1
    end
  end
    
  def limit_damage(attacker)
    limit = 0
    if attacker.actor?
      if attacker.break_damage_limit?
        limit = Mithran::DamageLimit::ACTOR_BREAK_DAMAGE_LIMIT
      else
        limit = Mithran::DamageLimit::ACTOR_DAMAGE_LIMIT
      end
    else
      if attacker.break_damage_limit?
        limit = Mithran::DamageLimit::ENEMY_BREAK_DAMAGE_LIMIT
      else
        limit = Mithran::DamageLimit::ENEMY_DAMAGE_LIMIT
      end
    end
    if limit > 0
      denom = Mithran::DamageLimit::MP_DAMAGE_DENOMINATOR
      denom = 1 if denom < 1
      @hp_damage = [@hp_damage, limit].min
      @hp_damage = [@hp_damage, -limit].max
      @mp_damage = [@mp_damage, (limit / denom).floor].min
      @mp_damage = [@mp_damage, (-limit / denom).ceil].max
    end
  end
  
  def critical_damage_mod(user, obj = nil)
    base_mod = user.personal_cri_damage_mod
    if $imported['StateParametersPlus']
      for state in user.spp_states_all.reverse
        next if state.critical_mod_set < 100
        base_mod = state.critical_mod_set / 100.0
      end
      for state in user.spp_states_all
        base_mod += state.critical_mod_plus / 100.0
      end
      for state in user.spp_states_all
        base_mod *= state.critical_mod_rate / 100.0
      end
    end
    return [base_mod, 1.0].max
  end
  
  def personal_cri_damage_mod
    if actor?
      base = equips.compact.inject(0) { |m, item|
      (item.base_cri_mod > m) ? item.base_cri_mod : m
      }
      base = Mithran::CriticalDamage::CRITICAL_DAMAGE_MOD * 100 if base == 0
      n = equips.compact.inject(0) {|m, item| m + item.add_cri_mod }
      return (base + n) / 100.0
    else
      return enemy.add_cri_mod + enemy.base_cri_mod / 100.0
    end
  end
    
  def make_new_critical_damage_value(user, obj = nil)
    hpdmg = @hp_damage / 3.0
    mpdmg = @mp_damage / 3.0
    mod = critical_damage_mod(user, obj)
    hpdmg *= mod
    mpdmg *= mod
    @hp_damage = hpdmg.to_i
    @mp_damage = mpdmg.to_i
  end
  
  def critical_ignore_defense
    if actor?
      weapons.compact.find {|w| w.critical_ignore_defense }
    else
      enemy.critical_ignore_defense
    end
  end
  
end

class Game_Actor < Game_Battler
  def break_damage_limit?
    for item in equips.compact
      return true if item.break_damage_limit?
    end
    return false
  end
end

class Game_Enemy < Game_Battler
  def break_damage_limit?
    return enemy.note =~ /<BREAK DAMAGE LIMIT>/
  end
end

class RPG::BaseItem
  def break_damage_limit?
    return self.note =~ /<BREAK DAMAGE LIMIT>/
  end
  
  def base_cri_mod
    self.note =~ /<BASE CRI DMG (\d+)(?:%)?>/i ? $1.to_i : 0
  end

  def add_cri_mod
    self.note =~ /<CRI DMG\s*([+-]?\s*\d+)(?:%)?>/i ? $1.to_i : 0
  end
  
  def critical_ignore_defense
    self.note =~ /<(NO)?\s?CRITICAL IGNORE DEFENSE>/i ? $1.nil? : Mithran::CriticalDamage::CRITICAL_IGNORE_DEFENSE
  end
  
end

class RPG::UsableItem
  attr_accessor :temp_ignore_def
  
  alias ignore_defense_damagelimit ignore_defense unless $@
  def ignore_defense
    return true if @temp_ignore_def
    return ignore_defense_damagelimit
  end
end


class RPG::Enemy
  
  def base_cri_mod
    self.note =~ /<BASE CRI DMG (\d+)(?:%)?>/i ?
      $1.to_i : Mithran::CriticalDamage::CRITICAL_DAMAGE_MOD * 100
  end
    
  def add_cri_mod
    self.note =~ /<CRI DMG\s*([+-]?\s*\d+)(?:%)?>/i ? $1.to_i : 0
  end
  
  def critical_ignore_defense
    self.note =~ /<(NO)?\s?CRITICAL IGNORE DEFENSE>/i ? $1.nil? : Mithran::CriticalDamage::CRITICAL_IGNORE_DEFENSE
  end
  
end


FAQ
q. Hey, I thought you were working on States Options!
a. I am. It is a much bigger undertaking, so I need a bigger chunk of uninterrupted time to get it ready.

q. Why use this?
a. Why not? smile.gif

Credit and Thanks
- Mithran

Author's Notes
Feedback is welcome. My script development thread for other projects is here.

This post has been edited by Mithran: Mar 24 2010, 10:38 PM


--------------------
Go to the top of the page
 
+Quote Post
   
Azuaya
post Jan 23 2009, 10:16 PM
Post #2


Random Wanderer
Group Icon


Type: Coder




Oh my god... your a genius Mithran! I so needed this for my game since I pretty much don't know how to adjust the battle algorithm and so forth but you saved the day ^^ well hoping to see you produce more of these great scripts. Your scripts definitely help battle damage formula a lot better.
Go to the top of the page
 
+Quote Post
   
Distribue
post Jan 24 2009, 04:08 PM
Post #3



Group Icon


Type: Undisclosed




I like how your scripts actually change the game-play rather than just all "LOL SIDEVIEW BATTLES" Keep up the good work. Can't wait til States Options come out.
Go to the top of the page
 
+Quote Post
   
Mithran
post Jan 24 2009, 11:56 PM
Post #4


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Thank you both for the words of encouragement.

Update

v 1.1
Fixed a minor compatability error for future projects.

Modified script is in the original post.

This post has been edited by Mithran: Jan 26 2009, 05:33 AM


--------------------
Go to the top of the page
 
+Quote Post
   
Chiem1000
post Jan 25 2009, 12:24 AM
Post #5



Group Icon


Type: Writer
Alignment: Lawful Evil




Thank you so much for this Mithran. I do really appreciate this one.
Cause the 3x normel damage with Critical hit, is a bit to high for me.


<>Chiem1000

This post has been edited by Chiem1000: Jan 25 2009, 12:27 AM
Go to the top of the page
 
+Quote Post
   
carbajosa
post Feb 4 2009, 03:09 PM
Post #6



Group Icon






It reminds me of Final Fantasy games biggrin.gif


--------------------
» Click to show Spoiler - click again to hide... «



» Click to show Spoiler - click again to hide... «
Go to the top of the page
 
+Quote Post
   
CrimsonPride
post Feb 11 2009, 04:06 AM
Post #7



Group Icon


Type: Designer




A quick request:

Would it be possible to add within this script the ability to "add" critical to weapons/armors/accessories through note tags or something? And adjust an individual weapon's critical rate?

Thanks in advance if you look into it, sorry if its a ridiculous request smile.gif
Go to the top of the page
 
+Quote Post
   
Mithran
post Feb 11 2009, 05:31 AM
Post #8


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




QUOTE (CrimsonPride @ Feb 10 2009, 08:06 PM) *
A quick request:

Would it be possible to add within this script the ability to "add" critical to weapons/armors/accessories through note tags or something? And adjust an individual weapon's critical rate?

Thanks in advance if you look into it, sorry if its a ridiculous request smile.gif


Yeah, this one is on my list. For now, KGC_ReproduceFunctions can modfiy the 'cri' stat, which alters how often actors or enemies can crit. My State Parameters PLUS can modify the actual damage rate of critical damage through states (plus the cri stat), and you could use my Conditional Autostates to add an invisible critical rate state to your indiviudal items (set the condition to 1, always true), if you are looking for a quick workaround. I'll bump the Critical Options script on my requests list. I may or may not add it to this script, because I had a few other features in mind. Thanks for your comments.


--------------------
Go to the top of the page
 
+Quote Post
   
CrimsonPride
post Feb 11 2009, 05:36 AM
Post #9



Group Icon


Type: Designer




QUOTE (Mithran @ Feb 11 2009, 12:31 AM) *
Yeah, this one is on my list. For now, KGC_ReproduceFunctions can modfiy the 'cri' stat, which alters how often actors or enemies can crit. My State Parameters PLUS can modify the actual damage rate of critical damage through states (plus the cri stat), and you could use my Conditional Autostates to add an invisible critical rate state to your indiviudal items (set the condition to 1, always true), if you are looking for a quick workaround. I'll bump the Critical Options script on my requests list. I may or may not add it to this script, because I had a few other features in mind. Thanks for your comments.


That would all work. I'll try to get reproduce functions working again (tends to blow up when I try to use it)

Thanks!

EDIT: Reproduce functions does indeed blow up when I attempt to use it: I get a NoMethod error on line 1014 when I attempt to attack, which I am assuming is a result of Tankentai.

This post has been edited by CrimsonPride: Feb 11 2009, 07:05 AM
Go to the top of the page
 
+Quote Post
   
Mithran
post Feb 12 2009, 02:44 AM
Post #10


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




QUOTE (CrimsonPride @ Feb 10 2009, 09:36 PM) *
That would all work. I'll try to get reproduce functions working again (tends to blow up when I try to use it)

Thanks!

EDIT: Reproduce functions does indeed blow up when I attempt to use it: I get a NoMethod error on line 1014 when I attempt to attack, which I am assuming is a result of Tankentai.


Quickie script to modify 'cri' by equip notes or enemy notes.
» Click to show Spoiler - click again to hide... «


--------------------
Go to the top of the page
 
+Quote Post
   
CrimsonPride
post Feb 12 2009, 03:44 AM
Post #11



Group Icon


Type: Designer




Woah that was fast. Thanks a lot! smile.gif
Go to the top of the page
 
+Quote Post
   
Mithran
post Apr 19 2009, 04:36 PM
Post #12


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




Update

v 1.2
- New feature: Critical Ignore Defense. Allows criticals to ignore defense.
- New feature: Scale Damage. Scale down (or up) all damage by a global modifier, giving the semblance of different algorithms without actually modifying them.
- Improvement: Stronger checks for damage limit for enhanced compatability with scripts by other scripters.

Previous changes:
Spoiler:
v 1.1
Fixed a minor compatability error for future projects.


Modified script is in the original post.


--------------------
Go to the top of the page
 
+Quote Post
   
Xalidir
post Apr 21 2009, 09:01 PM
Post #13



Group Icon


Type: Undisclosed
Alignment: Unaligned




would this script fix the low damage output the characters do with the default scaling system?

example, character A at level 99 has his ultimate weapon that has 500 attack, and his attack is all 500. when he hits a monster with 1 defense, he'll do a measly 3,000-4,000

i'm sorry, by all accounts, if your character's hitting THAT hard, he should hit for 9999 if not more


--------------------
| |

My Request: Great Kingdoms RTP Portraits Request Form
IMPORTANT TO READ!!!
Board Rules

Want to Sprite?
An Introduction to Frankenspriting and Editing

Spoiler:
QUOTE (PINEDAVX @ Dec 20 2010, 08:22 PM)
If tomorrow we want to ban all idiots we have, we'll do it and no one has any right to appeal. Guess what? You don't have rights here, only privileges. Privileges we can and will take away from you as we see fit.

Pretty much, being here is a priviledge, and it CAN be revoked.

Supports:

---
Jet's Handed Weapon Snippet (Requested by me, ask Jet for permission)
Spoiler:
CODE
#===============================================================================
# Handed Weapons
# By Jet10985 (Jet)
# Requested by: Xalidir
#===============================================================================
# This snippet allows you to specify if a weapon is main or off-handed.
# Main handed can only be equiped in the first weapon slot.
# Off handed can only be equipped in the second weapon slot.
# This script has: 0 customization options.
#===============================================================================
# Overwritten Methods:
# None
#-------------------------------------------------------------------------------
# Aliased methods:
# Scene_Equip: update_item_selection
#===============================================================================
=begin
To make an item Main-Handed, put this in the notebox:

<main hand>

To make an item off-handed, put this in the notebox:

<off hand>
--------------------------------------------------------------------------------
Note: Off-handed weapons cannot be equipped at all if the actor can't dual-wield
=end

class RPG::BaseItem
  
  def hand
    if @hand.nil?
      i = 0
      for note in [/<main hand>/i, /<off hand>/i]
        @hand = self.note[note].nil? ? nil : i
        break if @hand != nil
        i += 1
      end
      @hand = 2 if @hand.nil?
    end
    return @hand
  end
end

class Scene_Equip
  
  alias jet9842_update_item_selection update_item_selection unless $@
  def update_item_selection
    if Input.trigger?(Input::C)
      item = @item_window.item
      equip_type = @equip_window.index
      if equip_type == 0 and !item.nil?
        Sound.play_buzzer if item.hand == 1
        return if item.hand == 1
      elsif equip_type == 1 and !item.nil?
        Sound.play_buzzer if item.hand == 0
        return if item.hand == 0
      end
    end
    jet9842_update_item_selection
  end
end


How to Fix Actor Related Variables the Lazy Way
Spoiler:
In the Game_Interpreter script, there's a line that is messed up.
CODE
Line: 750      actor = $game_actors[@parameters[1]]
Line: 751      actor = $game_actors[@params[4]]

To fix this, change Line: 750 from above to the one below
CODE
when 4 # Actor

This will fix any Actor Related Variables for you. I recommend grabbing the Variables Fix from the site.
Go to the top of the page
 
+Quote Post
   
Mithran
post Apr 21 2009, 11:40 PM
Post #14


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




If you decide to use the scale damage option, it scales ALL damage, including damage from skills. If you want to only change a part of the damage, you'll need a script that specifically changes the damage algroithm for just that part.


--------------------
Go to the top of the page
 
+Quote Post
   
federico nahuel
post Nov 2 2009, 02:39 AM
Post #15



Group Icon


Type: Undisclosed




Hi, im just beginner. so i´m have a question: how to modify the critical damage?
Go to the top of the page
 
+Quote Post
   
Mithran
post Nov 2 2009, 03:15 AM
Post #16


Scripter
Group Icon


Type: Coder
Alignment: True Neutral




QUOTE
module CriticalDamage
CRITICAL_DAMAGE_MOD = 3.0
# Default damage for a critical hit is 3.0 times the normal amount
# Changing this will change the default damage rate on all critical


Find that section and change the 3.0 to a different number. 3.0, the default, is 3 times normal damage on a critical. You can type the text indicated at the top of the script to change the critical values of indiviudal weapons or armor.


--------------------
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: 31st August 2014 - 07:25 AM

RPGMakerVX.net is an Privacy Policy, Legal.