Main Menu
  • Welcome to The RPG Maker Resource Kit.

Random Stat Variance for Items

Started by modern algebra, August 07, 2011, 11:32:19 PM

0 Members and 1 Guest are viewing this topic.

modern algebra

Random Stat Variance for Items
Version: 1.0
Author: modern algebra
Date: August 7, 2011

Version History




  • <Version 1.0> 2011.08.07 - Original Release

Description



This script allows weapons or armors to have randomly varying stats. So, one long sword could have 5 ATK while another could have 7 ATK.

Features


  • Randomizes the stats of items you specify to the degree you specify
  • Makes item drops a little more dynamic and can emulate higher quality and lower quality items of the same type

Screenshots



Instructions

This script REQUIRES Instance Items Base and must be below it, but still above Main.

It is very easy to use, however, and it will work for any item stat that is stored as an integer. All you need to do is use this code in the item's notebox:
      \VAR_stat[variance]
          stat : the stat you want to vary. It has to be a stat that stores an integer, and it must be the name of the method that returns it.
          variance : maximum amount you want the stat to vary by. It must be an integer. It will take a random number between 0 and this number and add it to the default stat value.

Valid stat strings:
ITEM - base_damage, variance, atk_f, spi_f, parameter_type, parameter_points, hp_recovery_rate, hp_recovery, scope, speed, occasion, mp_recovery_rate, mp_recovery, price, common_event_id
WEAPON - atk, def, agi, spi, hit, price
ARMOR - atk, def, spi, agi, eva, kind, price

Script




#==============================================================================
#    Random Stat Variance for Items
#    Version: 1.0
#    Author: modern algebra (rmrk.net)
#    Date: August 7, 2011
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#
#    This script allows weapons or armors to have randomly varying stats. So,
#   one long sword could have 5 ATK while another could have 7 ATK.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#    This script REQUIRES Instance Items Base and must be BELOW it in
#   the editor, but still ABOVE Main.
#
#    It is very easy to use, however, and it will work for any item stat that
#   is stored as an integer. All you need to do is use this code in the item's
#   notebox:
#      \VAR_stat[variance]
#        stat : the stat you want to vary. It has to be a stat that stores an
#          integer, and it must be the name of the method that returns it.
#        variance : maximum amount you want the stat to vary by. It must be an
#          integer. It will take a random number between 0 and this number and
#          add it to the default stat value.
#
#    Valid stat strings:
#      ITEM - base_damage, variance, atk_f, spi_f, parameter_type,
#        parameter_points, hp_recovery_rate, hp_recovery, scope, speed,
#        occasion, mp_recovery_rate, mp_recovery, price, common_event_id
#      WEAPON - atk, def, agi, spi, hit, price
#      ARMOR - atk, def, spi, agi, eva, kind, price
#
#    EXAMPLES:
#      \VAR_ATK[4] - If the ATK stat is set as, for instance 5, then the atk
#        stat of this item will be anywhere between 5 and 9.
#      \var_def[3] - The DEF of this weapon or armor will be between the
#        default + rand(4)
#==============================================================================

if $imported && $imported["MAInstanceItemsBase"]
 
$imported["MARandomVarianceItems"] = true
#==============================================================================
# ** BaseItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - random_variance
#==============================================================================

class RPG::BaseItem
  # Push the Variance code into the checks for instance items
  MA_INSTANCE_CHECKS.push (/\\VAR_.*?\[\d+\]/i)
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Random Variance
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def random_variance
    unless @rand_vars
      @rand_vars = {}
      self.note.scan (/\\VAR_(.*?)\[(\d+)\]/i) { |stat, var| @rand_vars[stat.downcase] = var.to_i }
    end
    return @rand_vars
  end
end

#==============================================================================
# *** II_BaseItem
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - setup
#==============================================================================

module II_BaseItem
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias malgbr_etups_ranvarsts_7jh3 setup
  def setup (item, *args, &block)
    malgbr_etups_ranvarsts_7jh3 (item, *args, &block) # Run Original Method
    item.random_variance.each { |stat, variance|
      # If the operation will work
      if self.class.method_defined? (stat.to_sym) && (self.send (stat)).is_a? (Numeric) &&
          self.class.method_defined? ("#{stat}=".to_sym)
        self.send ("#{stat}=", self.send (stat) + rand(variance + 1))
      end
    }
  end
end

end


If it is not copying correctly, you can also retrieve the script from Pastebin.

Credit




  • modern algebra

Support



Please post in this topic if you encounter any issues or wish to make any suggestions.

Demo



Coming soon.

cozziekuns

It would be cool if you could randomise the extra options for items, like Fast Attack for Weapons or Half MP Cost for Armours. But it's a great script as it is.

Also, any tips on using the send method for Objects? I looked into it before but it didn't seem that useful; here, you seem to have used it to it's fullest extent.

Mushu

idk if it'll let you on the link but, this system allows you to change special attributes of items
http://www.rpgrevolution.com/forums/index.php?showtopic=19618&hl=OECS