The RPG Maker Resource Kit

RMRK RPG Maker Creation => VX => VX Scripts Database => Topic started by: modern algebra on August 07, 2011, 11:32:19 PM

Title: Random Stat Variance for Items
Post by: modern algebra on August 07, 2011, 11:32:19 PM
Random Stat Variance for Items
Version: 1.0
Author: modern algebra
Date: August 7, 2011

Version History



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


Screenshots

(http://img204.imageshack.us/img204/1797/instanceitems.png)

Instructions

This script REQUIRES Instance Items Base (http://rmrk.net/index.php/topic,43441.0.html) 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


Code: [Select]
#==============================================================================
#    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 (http://pastebin.com/nw3RtQyE).

Credit



Support


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

Demo


Coming soon.
Title: Re: Random Stat Variance for Items
Post by: cozziekuns on August 08, 2011, 04:27:18 PM
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.
Title: Re: Random Stat Variance for Items
Post by: Mushu on August 14, 2011, 08:03:26 PM
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