Weapons : Critical Bonus

Kain Nobel
Version: 3.5
By: Kain Nobel

Introduction

All this does is give your weapons a new stat which increases your chances to make a critical strike. The nice thing about this scriptlet is you don't have to create weapons which increase an actor's AGI just to make them more likely to strike a critical, it is weapon-based instead of just AGI based only.

Features

  • You can give weapons an additional critical strike bonus
  • Works alongside the normal attack effect formula
  • No need to increase the AGI+ of the weapon to achieve higher critical hit rates
  • Should work with custom scripts that give enemies equipment
  • New 'random' methods created for Kernel, just as a bonus
  • Doesn't override my "OverKill" damage system (not yet posted)

Script

Weapons : Critical Bonus Spoiler
  1. #===============================================================================
  2. # ** Weapons : Critical Bonus
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. if Object.const_defined?(:SDK)
  9.   SDK.log('Weapons.CriticalBonus', 'Kain Nobel ©', 3.5, '2009.09.09')
  10. end
  11.  
  12. #===============================================================================
  13. # ** Kernel (MACL 'RGSS.Higher Classes' additions)
  14. #===============================================================================
  15.  
  16. module Kernel
  17.   #---------------------------------------------------------------------------
  18.   # * Name      : Random Boolean (Rand Bool)
  19.   #   Info      : Equal chance of returning a true or false value
  20.   #   Author    : Kain Nobel
  21.   #   Call Info : None
  22.   #---------------------------------------------------------------------------
  23.   def random_boolean
  24.     # Return true if random 2 is more than 1
  25.     rand(2) <= 1
  26.   end
  27.   alias_method :rand_bool, :random_boolean
  28.   #---------------------------------------------------------------------------
  29.   # * Name      : Random Odds (Rand Odds)
  30.   #   Info      : Specified odds of returning a true or false value
  31.   #   Author    : Kain Nobel
  32.   #   Call Info : 1 or 2 arguments
  33.   #               Odds True is a Numeric representing odds of returning ture
  34.   #               Odds False is a Numeric representing odds of returning false
  35.   #---------------------------------------------------------------------------
  36.   def random_odds(odds_true = 1, odds_false = 10)
  37.     # If Odds of being True equal odds of being False
  38.     if odds_true == odds_false
  39.       # Return a random boolean
  40.       return random_boolean
  41.     end
  42.     # Return odds true are more than odds false
  43.     rand(odds_false) < odds_true
  44.   end
  45.   alias_method :rand_odds, :random_odds
  46. end
  47.  
  48. #===============================================================================
  49. # ** RPG::Weapon
  50. #===============================================================================
  51.  
  52. class RPG::Weapon
  53.   #-----------------------------------------------------------------------------
  54.   # * Chance of each weapon striking a critical hit
  55.   #-----------------------------------------------------------------------------
  56.   Critical = {
  57.   1 => 100
  58.   }
  59.   Critical.default = 0
  60.   #-----------------------------------------------------------------------------
  61.   # * Critical
  62.   #-----------------------------------------------------------------------------
  63.   def critical
  64.     # Return value of constant
  65.     Critical[@id]
  66.   end
  67. end
  68.  
  69. #===============================================================================
  70. # ** Game_Battler
  71. #===============================================================================
  72.  
  73. class Game_Battler
  74.   #-----------------------------------------------------------------------------
  75.   # * Alias Listings
  76.   #-----------------------------------------------------------------------------
  77.   alias_method :weaponcritical_gmbattler_attackeffect, :attack_effect
  78.   #-----------------------------------------------------------------------------
  79.   # * Attack Effect : Critical Correction
  80.   #-----------------------------------------------------------------------------
  81.   def attack_effect(attacker)
  82.     # The usual
  83.     weaponcritical_gmbattler_attackeffect(attacker)
  84.     # If damage is numerical and not self critical
  85.     if self.damage.is_a?(Numeric) && !self.critical
  86.       # If attacker can carry a weapon
  87.       if attacker.respond_to?(:weapon_id)
  88.         # Get weapon object from attacker's weapon ID
  89.         weapon = $data_weapons[attacker.weapon_id]
  90.         # If weapon has a critical value
  91.         if weapon.respond_to?(:critical)
  92.           # Get the odds of striking critical with weapon
  93.           if random_odds([weapon.critical, 100].min, 100)
  94.             # Double the damage
  95.             self.damage  *= 2
  96.             # Set critical flag
  97.             self.critical = true
  98.             # If using 'Battler.OverKill' script and fatal damage
  99.             if Object.const_defined?(:OverKill) && @hp < self.damage
  100.               # Set 'OverKill' string
  101.               self.critical = OverKill::Critical_String
  102.             end
  103.           end
  104.         end
  105.       end
  106.     end
  107.   end
  108. end
Expand to see the code.


Instructions

Place Above Main, Below SDK (Only if Using)

Compatibility

Should be compatible with anything. If its not placed below anything that modifies Game_Battler.attack_effect, it might not work properly. If you don't understand this, just place it below every custom script but be sure it is still above Main.

This script aliases Game_Battler#attack_effect, so if you're using an exotic CBS or ABS that doesn't use that method, this script won't serve any purpose.

Author's Notes

Works with my Battlers : OverKill script.

Terms and Conditions

Another "Free to use in commercial and non-commercial games" script, obviously with credit thanks :thumb:
Excellent! I was about to go into script requests for this... But the search function pulled through!

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=67361