Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

Code:
#===============================================================================

# ** Weapons : Critical Bonus

#===============================================================================

 

#-------------------------------------------------------------------------------

# * SDK Log

#-------------------------------------------------------------------------------

if Object.const_defined?(:SDK)

  SDK.log('Weapons.CriticalBonus', 'Kain Nobel ©', 3.5, '2009.09.09')

end

 

#===============================================================================

# ** Kernel (MACL 'RGSS.Higher Classes' additions)

#===============================================================================

 

module Kernel

  #---------------------------------------------------------------------------

  # * Name      : Random Boolean (Rand Bool)

  #   Info      : Equal chance of returning a true or false value

  #   Author    : Kain Nobel

  #   Call Info : None

  #---------------------------------------------------------------------------

  def random_boolean

    # Return true if random 2 is more than 1

    rand(2) <= 1

  end

  alias_method :rand_bool, :random_boolean

  #---------------------------------------------------------------------------

  # * Name      : Random Odds (Rand Odds)

  #   Info      : Specified odds of returning a true or false value

  #   Author    : Kain Nobel

  #   Call Info : 1 or 2 arguments

  #               Odds True is a Numeric representing odds of returning ture

  #               Odds False is a Numeric representing odds of returning false

  #---------------------------------------------------------------------------

  def random_odds(odds_true = 1, odds_false = 10)

    # If Odds of being True equal odds of being False

    if odds_true == odds_false

      # Return a random boolean

      return random_boolean

    end

    # Return odds true are more than odds false

    rand(odds_false) < odds_true

  end

  alias_method :rand_odds, :random_odds

end

 

#===============================================================================

# ** RPG::Weapon

#===============================================================================

 

class RPG::Weapon

  #-----------------------------------------------------------------------------

  # * Chance of each weapon striking a critical hit

  #-----------------------------------------------------------------------------

  Critical = {

  1 => 100

  }

  Critical.default = 0

  #-----------------------------------------------------------------------------

  # * Critical

  #-----------------------------------------------------------------------------

  def critical

    # Return value of constant

    Critical[@id]

  end

end

 

#===============================================================================

# ** Game_Battler

#===============================================================================

 

class Game_Battler

  #-----------------------------------------------------------------------------

  # * Alias Listings

  #-----------------------------------------------------------------------------

  alias_method :weaponcritical_gmbattler_attackeffect, :attack_effect

  #-----------------------------------------------------------------------------

  # * Attack Effect : Critical Correction

  #-----------------------------------------------------------------------------

  def attack_effect(attacker)

    # The usual

    weaponcritical_gmbattler_attackeffect(attacker)

    # If damage is numerical and not self critical

    if self.damage.is_a?(Numeric) && !self.critical

      # If attacker can carry a weapon

      if attacker.respond_to?(:weapon_id)

        # Get weapon object from attacker's weapon ID

        weapon = $data_weapons[attacker.weapon_id]

        # If weapon has a critical value

        if weapon.respond_to?(:critical)

          # Get the odds of striking critical with weapon

          if random_odds([weapon.critical, 100].min, 100)

            # Double the damage

            self.damage  *= 2

            # Set critical flag

            self.critical = true

            # If using 'Battler.OverKill' script and fatal damage

            if Object.const_defined?(:OverKill) && @hp < self.damage

              # Set 'OverKill' string

              self.critical = OverKill::Critical_String

            end

          end

        end

      end

    end

  end

end

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:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top