RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Random Stat Variance for Items

0 Members and 2 Guests are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Best Member2012 Best RPG Maker User (Scripting)2012 Favorite Staff Member2012 Most Mature MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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


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.

Credit


  • modern algebra

Support


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

Demo


Coming soon.

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
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.

****
Rep:
Level 69
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