Adding Attributes (Scripting Tool)

Adding Attributes Easy 1.11
By SephirothSpawn


Introduction
Ever want to give your objects attributes? Giving an actor a new stat like luck that grows as your actor does?

This script was designed to allow you to give any object (usually data structure objects) stats, either with a set stat or a stat that grows (stat is a hash, with "level" as the key and stat value as the "value") via the Curve Generator module. If you wish to use this for a object class, there must be an instance @id specified to read the stats.

Script

Copy and paste the code anywhere but it must be above any scripts that use this
Adding Attributes:
  1. #==============================================================================
  2. # ** Adding Attributes Easy
  3. #------------------------------------------------------------------------------
  4. # SephirothSpawn
  5. # Version 1.11
  6. # 2009-02-02 (Year-Month-Day)
  7. #------------------------------------------------------------------------------
  8. # * Version History:
  9. #
  10. #    Version 1.0 -------------------------------------------------- (2009-01-21)
  11. #      Version 1.1 ------------------------------------------------- (2009-02-02)
  12. #       - Fix: Fixed add_stat default hash setup. Changed to object_to_string.
  13. #------------------------------------------------------------------------------
  14. # * Description:
  15. #
  16. #    This script was designed to allow you to give any object (usually data
  17. #    structure objects) stats, either with a set stat or a stat that grows
  18. #    (stat is a hash, with "level" as the key and stat value as the "value")
  19. #    via the Curve Generator module. If you wish to use this for a object class,
  20. #    there must be an instance @id specified to read the stats.
  21. #------------------------------------------------------------------------------
  22. # * Instructions:
  23. #
  24. #    Place the script anywhere above Main and any scripts that use it.
  25. #------------------------------------------------------------------------------
  26. # * Terms & Conditions:
  27. #
  28. #    Copyright (C) 2009 SephirothSpawn (Timothy Hoffman)
  29. #    Free for non-commercial & commercial use.
  30. #    Any modifications to the system are not to be re-distributed without my
  31. #    consent.
  32. #==============================================================================
  33.  
  34. #==============================================================================
  35. # ** Module
  36. #==============================================================================
  37.  
  38. class Module
  39.   #--------------------------------------------------------------------------
  40.   # * Add Stat
  41.   #--------------------------------------------------------------------------
  42.   private
  43.   def add_stat(stat_name, hash_settings)
  44.      # Create method
  45.      s   = "def #{stat_name};"
  46.      s += "   settings = #{object_to_string(hash_settings)};"
  47.      s += "   settings.default = #{object_to_string(hash_settings.default)};"
  48.      s += "   return settings[@id];"
  49.      s += "end;"
  50.      # Eval method
  51.      module_eval (s)
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Add Stat Curve
  55.   #--------------------------------------------------------------------------
  56.   private
  57.   def add_stat_curve(stat_name, hash_settings)
  58.      # Create method
  59.      s   = "def #{stat_name};"
  60.      s += '   @gen_stats = {} if @gen_stats == nil;'
  61.      s += "   if @gen_stats['#{stat_name}'] == nil;"
  62.      s += "      @gen_stats['#{stat_name}'] = {};"
  63.      s += "   end;"
  64.      s += "   if @gen_stats['#{stat_name}'].has_key?(@id);"
  65.      s += "      return @gen_stats['#{stat_name}'][@id];"
  66.      s += "   end;"
  67.      s += "   settings = #{object_to_string(hash_settings)};"
  68.      s += "   settings.default = #{object_to_string(hash_settings.default)};"
  69.      s += "   curve = Curve_Generator.generate_curve(*settings[@id]);"
  70.      s += "   @gen_stats['#{stat_name}'][@id] = curve;"
  71.      s += "   return @gen_stats['#{stat_name}'][@id];"
  72.      s += "end;"
  73.      # Eval method
  74.      module_eval (s)
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # * Object to String
  78.   #--------------------------------------------------------------------------
  79.   def object_to_string(object)
  80.      case object
  81.      when Array
  82.         object.collect! {|value| object_to_string(value)}
  83.         return "[#{object.join(',')}]"
  84.      when Hash
  85.         s = '{'
  86.         object.each do |key, value|
  87.            s += "#{object_to_string(key)}=>#{object_to_string(value)},"
  88.         end
  89.         s += '}'
  90.         return s
  91.      else
  92.         return object.to_s
  93.      end
  94.   end
  95. end
Expand to see the code.


This script requires the Curve Generator Module (4.01)
  1. #==============================================================================
  2. # ** Modules.Curve Generator Module (4.01)            By Trickster & SephirothSpawn
  3. #------------------------------------------------------------------------------
  4. # * Description :
  5. #
  6. #    This script was designed to generate a curve of numbers given certain
  7. #    values. As of now, their are 3 formulas for you to choose from : Point-
  8. #    slope; Early & Late; Early / Steady / Late + Curves.
  9. #------------------------------------------------------------------------------
  10. # * Syntax :
  11. #
  12. #    Generating Curve :
  13. #      - curve = Curve_Generator.generate_curve(type, <args>)
  14. #
  15. #    Type : 0 - Point Slope
  16. #               1 - Early / Late
  17. #               2 - Early / Steady / Late + Curves
  18. #
  19. #    Args :
  20. #
  21. #      Type 0 : min_level, max_level, start value, inflation
  22. #      Type 1 : min_level, max_level, min_value, max_value, early, late
  23. #      Type 2 : min level, mid_level, max level, min value, mid_value,
  24. #                   max value, early, late, steady, curve 1, curve 2, integer
  25. #
  26. #    This will return a hash : { level => value, ... }
  27. #==============================================================================
  28.  
  29. #==============================================================================
  30. # ** Curve_Generator
  31. #==============================================================================
  32.  
  33. module Curve_Generator
  34.   #--------------------------------------------------------------------------
  35.   # * Generate Curve
  36.   #
  37.   #    Type : 0 - Point Slope
  38.   #               1 - Early / Late
  39.   #               2 - Early / Steady / Late + Curves
  40.   #
  41.   #    Args :
  42.   #
  43.   #      Type 0 : min_level, max_level, start value, inflation
  44.   #      Type 1 : min_level, max_level, min_value, max_value, early, late
  45.   #      Type 2 : min level, mid_level, max level, min value, mid_value,
  46.   #                   max value, early, late, steady, curve 1, curve 2, integer
  47.   #--------------------------------------------------------------------------
  48.   def self.generate_curve(type, *args)
  49.      # Collects Saved Tables
  50.      tables = self.load_tables
  51.      # Check for Previously Generated Table
  52.      if tables.has_key?(type) && tables[type].has_key?(args)
  53.         # Return Previously Generated Table
  54.         return tables[type][args]
  55.      end
  56.      # Branch Point By Type
  57.      case type
  58.      when 0 # Point Slope
  59.         table = Point_Slope.generate_curve(*args)
  60.      when 1 # Early / Late
  61.         table = Early_Late.generate_curve(*args)
  62.      when 2 # Early / Stead / Late + Curves
  63.         table = ESL_Curves.generate_curve(*args)
  64.      end
  65.      # Set 0 Defaults
  66.      table.default = 0
  67.      # Saves Table Information
  68.      self.save_table(type, args, table)
  69.      # Return Curve Information
  70.      return table
  71.   end
  72.   #-------------------------------------------------------------------------
  73.   # * Save Table
  74.   #-------------------------------------------------------------------------
  75.   def self.save_table(type, args, table)
  76.      # Collects Saved Tables
  77.      tables = self.load_tables
  78.      # Creates Hash of Type (If non present)
  79.      tables[type] = {} unless tables.has_key?(type)
  80.      # Saves Table Data
  81.      tables[type][args] = table
  82.      # Resaves Tables to File
  83.      save_data(tables, 'Data/Curve Generator.rxdata')      
  84.   end
  85.   #-------------------------------------------------------------------------
  86.   # * Load Tables
  87.   #-------------------------------------------------------------------------
  88.   def self.load_tables
  89.      # Test For Saved Table File
  90.      unless FileTest.exist?('Data/Curve Generator.rxdata')
  91.         # Creates Curve Generator Rxdata File
  92.         save_data({}, 'Data/Curve Generator.rxdata')
  93.      end
  94.      # Returns Saved Tables
  95.      return load_data('Data/Curve Generator.rxdata')
  96.   end   
  97.  
  98.   #============================================================================
  99.   # ** Point Slope
  100.   #============================================================================
  101.  
  102.   module Point_Slope
  103.      #------------------------------------------------------------------------
  104.      # * Generate Curve
  105.      #
  106.      #    Args : min_level, max_level, start value, inflation
  107.      #------------------------------------------------------------------------
  108.      def self.generate_curve(min_l, max_l, start_value, inflation)
  109.         # Creates Table
  110.         table = {}
  111.         # Fills Table
  112.         for level in min_l..max_l
  113.            table[level] = start_value + inflation * level
  114.         end
  115.         # Return Table
  116.         return table
  117.      end
  118.   end
  119.  
  120.   #============================================================================
  121.   # ** Early Late
  122.   #============================================================================
  123.  
  124.   module Early_Late
  125.      #------------------------------------------------------------------------
  126.      # * Generate Curve
  127.      #------------------------------------------------------------------------
  128.      def self.generate_curve(min_l, max_l, min_v, max_v, e = 1.0, l = 1.0)
  129.         # Creates Table
  130.         table = {}
  131.         # Fills Table
  132.         for i in min_l..max_l
  133.            # Assigns Value
  134.            table[i] = self.calculate_value(i, min_l.to_f, max_l.to_f,
  135.                             min_v.to_f, max_v.to_f, e.to_f, l.to_f)
  136.         end
  137.         # Return Table
  138.         return table
  139.      end
  140.      #------------------------------------------------------------------------
  141.      # * Late Curve
  142.      #------------------------------------------------------------------------
  143.      def self.late_curve(level, min_level, max_level, min, max)
  144.         diff = min_level - max_level
  145.         stat = min - max
  146.         num = stat * level ** 2 - 2 * min_level * stat * level + min_level ** 2 *
  147.                  max - 2 * min_level * max_level * min + min * min_level ** 2
  148.         denom = diff ** 2
  149.         return num / denom
  150.      end
  151.      #------------------------------------------------------------------------
  152.      # * Early Curve
  153.      #------------------------------------------------------------------------
  154.      def self.early_curve(level, min_level, max_level, min, max)
  155.         diff = max_level - min_level
  156.         stat = max - @min
  157.         num = -stat * level ** 2 + 2 * max_level * stat * level + min_level **
  158.                  2 * max - 2 * min_level * max_level * max + min * max_level ** 2
  159.         denom = diff ** 2
  160.         return num / denom      
  161.      end
  162.      #------------------------------------------------------------------------
  163.      # * Steady Curve
  164.      #------------------------------------------------------------------------
  165.      def self.steady_curve(level, min_level, max_level, min, max)
  166.         ch_level = max_level - min_level
  167.         ch_stat = max - min
  168.         base = ch_stat / ch_level * level
  169.         mod = max * min_level - min * max_level
  170.         base2 = mod / ch_level
  171.         return base - base2
  172.      end
  173.      #------------------------------------------------------------------------
  174.      # * Calculate Value
  175.      #------------------------------------------------------------------------
  176.      def self.calculate_value(level, min_level, max_level, min, max, e, l)
  177.         return min if level < min_level
  178.         return max if max_level < level
  179.         if e == l
  180.            stat = self.steady_curve(level, min_level, max_level, min, max)
  181.         else
  182.            early_ = self.early_curve(level, min_level, max_level, min, max)
  183.            late_ = self.late_curve(level, min_level, max_level, min, max)
  184.            stat = (e * early_ + l * late_) / (e + l)
  185.         end
  186.         stat = Integer([[stat, min].max, max].min)
  187.         return stat
  188.      end
  189.   end
  190.        
  191.   #============================================================================
  192.   # ** ESL_Curves
  193.   #============================================================================
  194.  
  195.   module ESL_Curves
  196.      #------------------------------------------------------------------------
  197.      # * Generate Curve
  198.      #------------------------------------------------------------------------
  199.      def self.generate_curve(mn_v, md_v, mx_v, mn_l, md_l, mx_l, e = 0, l = 0,
  200.                                          s = 0, c1 = 0, c2 = 0, i = true)
  201.         # Saves Values
  202.         @min_value, @mid_value, @max_value = mn_v, md_v, mx_v
  203.         @min_level, @mid_level, @max_level = mn_l, md_l, mx_l
  204.         @early      , @late       , @steady      = e    , l    , s
  205.         @curve1    , @curve2    , @integer    = c1   , c2   , i
  206.         # Error Checking
  207.         self.error_checking
  208.         # Calculate constants
  209.         self.calculate_constants
  210.         # Returns Table
  211.         return self.generate_table
  212.      end
  213.      #-----------------------------------------------------------------------
  214.      # * Error Checking
  215.      #-----------------------------------------------------------------------
  216.      def self.error_checking
  217.         if @late + @early + @steady + @curve1 + @curve2 == 0
  218.            raise(StandardError, "No Influences Have Been Defined")
  219.         elsif @min_level == @mid_level || @min_level == @max_level ||
  220.                  @mid_level == @max_level
  221.            raise(StandardError, "Can't Use Same Level for Min, Mid, or Max Level")
  222.         end
  223.      end
  224.      #-----------------------------------------------------------------------
  225.      # * Calculate Constants
  226.      #-----------------------------------------------------------------------
  227.      def self.calculate_constants
  228.         # Calculate "infi" and "inmi"
  229.         @inmi = (@mid_value - @min_value) / (@mid_level - @min_level)
  230.         @infi = (@max_value - @min_value) / (@max_level - @min_level)
  231.         # Calculate "infimi"
  232.         @infimi = (@infi - @inmi) / (@max_level - @mid_level)
  233.      end
  234.      #-----------------------------------------------------------------------
  235.      # * Generate Table
  236.      #-----------------------------------------------------------------------
  237.      def self.generate_table
  238.         # Create Hash table
  239.         table = {}
  240.         # Run Through Each Level
  241.         self.each {|level, value| table[level] = value}
  242.         # Return Created Table
  243.         return table
  244.      end
  245.      #-----------------------------------------------------------------------
  246.      # * Each Interator
  247.      #-----------------------------------------------------------------------
  248.      def self.each
  249.         # Get Minimum level and Maximum Level
  250.         minimum, maximum = @min_level.to_i, @max_level.to_i
  251.         # Run Through Minimum and Maximum and Yield Level and Value
  252.         (minimum..maximum).each {|level| yield(level, self.get_stat(level))}
  253.      end
  254.      #-----------------------------------------------------------------------
  255.      # * Get Stat
  256.      #-----------------------------------------------------------------------
  257.      def self.get_stat(level)
  258.         return @integer ? @min_value.to_i : @min_value if level <= @min_level
  259.         return @integer ? @max_value.to_i : @max_value if level >= @max_level
  260.         # Setup Total
  261.         total = 0
  262.         # Get Values for Every Stat if greater than 0
  263.         total += @early   * self.early_curve(level)         if @early > 0
  264.         total += @late    * self.late_curve(level)          if @late > 0
  265.         total += @steady * self.steady_curve(level)       if @steady > 0
  266.         total += @curve1 * self.early_late_curve(level) if @curve1 > 0
  267.         total += @curve2 * self.late_early_curve(level) if @curve2 > 0
  268.         # Get Average
  269.         total /= @late + @early + @steady + @curve1 + @curve2
  270.         # Limit Value
  271.         total = level < @mid_level ?
  272.            [total, @mid_value].min : [total, @mid_value].max
  273.         # Further Limit Value
  274.         total = [[total, @min_value].max, @max_value].min
  275.         # Return Value
  276.         return @integer ? total.to_i : total
  277.      end
  278.      #-----------------------------------------------------------------------
  279.      # * Late Curve
  280.      #-----------------------------------------------------------------------
  281.      def self.late_curve(level)
  282.         # Calculate "A"
  283.         a_num = @infimi * (3 * @min_level + @mid_level) + @inmi
  284.         a_den = (@max_level - @min_level) * (@mid_level - @min_level)
  285.         a = - a_num / a_den
  286.         # Return Value
  287.         return curve(a, level)
  288.      end
  289.      #-----------------------------------------------------------------------
  290.      # * Early Curve
  291.      #-----------------------------------------------------------------------
  292.      def self.early_curve(level)
  293.         # Calculate "A"
  294.         a_num = @infimi * (2 * @max_level + @min_level + @mid_level) + @inmi
  295.         a_den = (@max_level - @mid_level) * (@max_level - @min_level)
  296.         a = - a_num / a_den
  297.         # Return Value
  298.         return curve(a, level)
  299.      end
  300.      #-----------------------------------------------------------------------
  301.      # * Early Late Curve
  302.      #-----------------------------------------------------------------------
  303.      def self.early_late_curve(level)
  304.         # Calculate "A"
  305.         a = @infimi / (@max_level + @min_level - 2 * @mid_level)
  306.         # Return Value
  307.         return curve(a, level)
  308.      end
  309.      #-----------------------------------------------------------------------
  310.      # * Late Early Curve
  311.      #-----------------------------------------------------------------------
  312.      def self.late_early_curve(level)
  313.         # If Less than Mid Level
  314.         if level < @mid_level
  315.            # Return Late Curve for level
  316.            return late_curve(level)
  317.         # If Greater than Mid Level
  318.         elsif level > @mid_level
  319.            # Return Early Curve for Level
  320.            return early_curve(level)
  321.         # If at Mid Level
  322.         elsif level == @mid_level
  323.            # Return Mid Value
  324.            return @mid_value
  325.         end
  326.      end
  327.      #-----------------------------------------------------------------------
  328.      # * Steady Curve
  329.      #-----------------------------------------------------------------------
  330.      def self.steady_curve(level)
  331.         ch_level = @max_level - @min_level
  332.         ch_stat = @max_value - @min_value
  333.         base = ch_stat / ch_level * level
  334.         mod = @max_value * @min_level - @min_level * @max_level
  335.         base2 = mod / ch_level
  336.         return base - base2
  337.      end
  338.      #-----------------------------------------------------------------------
  339.      # * Curve
  340.      #-----------------------------------------------------------------------
  341.      def self.curve(a, level)
  342.         # Calculate "B"
  343.         b = @infimi - a * (@min_level + @mid_level + @max_level)
  344.         # Calculate "C"
  345.         c = @inmi - a * (@mid_level ** 2 + @min_level * @mid_level +
  346.               @min_level ** 2) - b * (@mid_level + @min_level)
  347.         # Calculate "D"
  348.         d = @min_value - (a * @min_level ** 3 + b * @min_level ** 2 + c *
  349.               @min_level)
  350.         # Calculate Stat
  351.         stat = a * level ** 3 + b * level ** 2 + c * level + d
  352.         # Return Stat
  353.         return stat
  354.      end
  355.   end
  356. end
Expand to see the code.

Instructions

Basic Stats (That do not increase)
Content Hidden Spoiler
In your object class, add:
  1. class Your_Class
  2.   hash_settings = {object_id => value, object_id => value, ...}
  3.   hash_settings.default = default_for_non_specified_objects
  4.   add_stat('your_stat_name', hash_settings)
  5. end
  6.  
  7.  
Expand to see the code.


Now you will just need to call your_object.your_stat_name and it will return the value for that object.

Stat that curve
Content Hidden Spoiler
In your object class, add:
  1. class Your_Class
  2.   hash_settings = {object_id => [curve_type, curve_argument, ...], object_id => [curve_type, curve_argument, ...], ...}
  3.   hash_settings.default = [curve_type, curve_argument, ...]
  4.   add_stat_curve('your_stat_name', hash_settings)
  5. end
  6.  
  7.  
Expand to see the code.


Curve type and curve_arguments are listing in the curve generator module heading. If you need help, just ask.

Now you will just need to call your_object.your_stat_name and it will return a hash with your curve specified. (Key as "level" and value of stat at that level as the value)

FAQ

Examples:
Adding Luck & Rating Stats Spoiler
  1. class RPG::Actor
  2.   luck = {
  3.      1 => [0, 1, 99, 5, 1],
  4.      2 => [0, 1, 99, 4, 2],
  5.      7 => [0, 1, 99, 2, 4],
  6.      8 => [0, 1, 99, 1, 5],
  7.   }
  8.   luck.default = [0, 1, 99, 3, 3]
  9.   add_stat_curve('luck', luck)
  10.   rating = {
  11.      1=>1,
  12.      2=>2,
  13.      7=>2,
  14.      8=>1
  15.   }
  16.   rating.default = 3
  17.   add_stat('rating', rating)
  18. end
  19.  
  20. class Game_Actor
  21.   def luck
  22.      return $data_actors[@actor_id].luck[@level]
  23.   end
  24.   def rating
  25.      return $data_actors[@actor_id].rating
  26.   end
  27. end
Expand to see the code.

Compatibility

Shouldn't cause any incompatibility or issues anywhere.

Credits and Thanks

jjangjae for motivating me to finally do this.

Terms and Conditions

Free for any use or redistribution, just credit me.

Author's Notes

If anyone has any questions setting this up, please specify what you are trying to accomplish, and I can guide you through it.

As always, Enjoy :thumb:
Yeah, I'm not sure exactly how I use the script. o.o
Its a bit complicated I know, but its easy once you get the hand of it.

Ok. Post a stat you want to add, each actor id, and we'll start with a simple point-slope formula for each stat, so for each actor, their start value and the amount they gain each level.

I'll be back in a bit to help you set this up. I suggest taking a look at the example I provided and maybe you can figure it out.
actor_id: 001, 002, 003, 004, 005, 006, 007
Stats:
Strength- Determines stand-alone weapon attack power.
Vitality- Determines stand-alone weapon defense and a little bit of HP.
Dexterity- Determines accuracy and a bit of critical hit rate.
Agility- Determines speed and avoidability.
Intelligence- Determines stand-alone magical attack.
Spirit- Determines stand-alone magical defense and defense against special attacks.
Luck- Determines critical hit rate and some avoidability.

Is this what you need?
So basically I'm going to erase the default stats and replace them with this. Possible?
Ok. You will have to take care of algorithms and such, but this is how you could set it up. We'll use the early/late formula of the curve generator module.

Content Hidden Spoiler
  1. class RPG::Actor
  2.     str = {
  3.        1 => [1, 1, 99, min_value, max_value, early, late],
  4.        2 => [1, 1, 99, min_value, max_value, early, late],
  5.        3 => [1, 1, 99, min_value, max_value, early, late],
  6.        4 => [1, 1, 99, min_value, max_value, early, late],
  7.        5 => [1, 1, 99, min_value, max_value, early, late],
  8.        6 => [1, 1, 99, min_value, max_value, early, late],
  9.        7 => [1, 1, 99, min_value, max_value, early, late]
  10.     }
  11.     str.default = [1, 1, 99, min_value, max_value, early, late]
  12.  
  13.    vit = {
  14.      1 => [1, 1, 99, min_value, max_value, early, late],
  15.      2 => [1, 1, 99, min_value, max_value, early, late],
  16.      3 => [1, 1, 99, min_value, max_value, early, late],
  17.      4 => [1, 1, 99, min_value, max_value, early, late],
  18.      5 => [1, 1, 99, min_value, max_value, early, late],
  19.      6 => [1, 1, 99, min_value, max_value, early, late],
  20.      7 => [1, 1, 99, min_value, max_value, early, late]
  21.    }
  22.    vit.default = [1, 1, 99, min_value, max_value, early, late]
  23.  
  24.    dex = {
  25.      1 => [1, 1, 99, min_value, max_value, early, late],
  26.      2 => [1, 1, 99, min_value, max_value, early, late],
  27.      3 => [1, 1, 99, min_value, max_value, early, late],
  28.      4 => [1, 1, 99, min_value, max_value, early, late],
  29.      5 => [1, 1, 99, min_value, max_value, early, late],
  30.      6 => [1, 1, 99, min_value, max_value, early, late],
  31.      7 => [1, 1, 99, min_value, max_value, early, late]
  32.    }
  33.    dex.default = [1, 1, 99, min_value, max_value, early, late]  
  34.  
  35.    agi = {
  36.      1 => [1, 1, 99, min_value, max_value, early, late],
  37.      2 => [1, 1, 99, min_value, max_value, early, late],
  38.      3 => [1, 1, 99, min_value, max_value, early, late],
  39.      4 => [1, 1, 99, min_value, max_value, early, late],
  40.      5 => [1, 1, 99, min_value, max_value, early, late],
  41.      6 => [1, 1, 99, min_value, max_value, early, late],
  42.      7 => [1, 1, 99, min_value, max_value, early, late]
  43.    }
  44.    agi.default = [1, 1, 99, min_value, max_value, early, late]
  45.  
  46.    int = {
  47.      1 => [1, 1, 99, min_value, max_value, early, late],
  48.      2 => [1, 1, 99, min_value, max_value, early, late],
  49.      3 => [1, 1, 99, min_value, max_value, early, late],
  50.      4 => [1, 1, 99, min_value, max_value, early, late],
  51.      5 => [1, 1, 99, min_value, max_value, early, late],
  52.      6 => [1, 1, 99, min_value, max_value, early, late],
  53.      7 => [1, 1, 99, min_value, max_value, early, late]
  54.    }
  55.    int.default = [1, 1, 99, min_value, max_value, early, late]
  56.  
  57.    spr = {
  58.      1 => [1, 1, 99, min_value, max_value, early, late],
  59.      2 => [1, 1, 99, min_value, max_value, early, late],
  60.      3 => [1, 1, 99, min_value, max_value, early, late],
  61.      4 => [1, 1, 99, min_value, max_value, early, late],
  62.      5 => [1, 1, 99, min_value, max_value, early, late],
  63.      6 => [1, 1, 99, min_value, max_value, early, late],
  64.      7 => [1, 1, 99, min_value, max_value, early, late]
  65.    }
  66.    spr.default = [1, 1, 99, min_value, max_value, early, late]
  67.  
  68.    luck = {
  69.      1 => [1, 1, 99, min_value, max_value, early, late],
  70.      2 => [1, 1, 99, min_value, max_value, early, late],
  71.      3 => [1, 1, 99, min_value, max_value, early, late],
  72.      4 => [1, 1, 99, min_value, max_value, early, late],
  73.      5 => [1, 1, 99, min_value, max_value, early, late],
  74.      6 => [1, 1, 99, min_value, max_value, early, late],
  75.      7 => [1, 1, 99, min_value, max_value, early, late]
  76.    }
  77.    luck.default = [1, 1, 99, min_value, max_value, early, late]
  78.  
  79.    add_stat_curve('str', str)
  80.    add_stat_curve('vit', vit)
  81.    add_stat_curve('dex', dex)
  82.    add_stat_curve('agi', agi)
  83.    add_stat_curve('int', int)
  84.    add_stat_curve('spr', spr)
  85.    add_stat_curve(luck', luck)
  86. end
  87.  
  88. class Game_Actor
  89.  def str
  90.    return $data_actors[@actor_id].str[@level]
  91.  end
  92.  def vit
  93.    return $data_actors[@actor_id].vit[@level]
  94.  end
  95.  def dex
  96.    return $data_actors[@actor_id].dex[@level]
  97.  end
  98.  def agi
  99.    return $data_actors[@actor_id].agi[@level]
  100.  end
  101.  def int
  102.    return $data_actors[@actor_id].int[@level]
  103.  end
  104.  def spr
  105.    return $data_actors[@actor_id].spr[@level]
  106.  end
  107.  def luck
  108.    return $data_actors[@actor_id].luck[@level]
  109.  end
  110. end
Expand to see the code.


Now you will have to modify the min_value, max_value, early, late values for each stat, for each character. So:
  1.   luck = {
  2.      1 => [1, 1, 99, min_value, max_value, early, late],
Expand to see the code.

For actor 1, this is there luck stat setup. min_value is the value at level 1 (or whatever the 1 value is before the 99), max_value is the stat value at level 99 (or whatever the value is where 99 is). Early and late numbers I would test first. With the early and late values, I would try numbers between 0.5 and 1.5 (I believe, but you might have to tinker with this).

You will have to do that for each stat, for each actor. I would instead recommend using 4 of he default stats and just do this for 3 stats instead of redoing all seven.

If you want to see your values at each level, you can check with:
  1. p $data_actors[actor_id].stat
Expand to see the code.


Replace actor_id with 1-7, whichever actor you are checking and stat with str, vit, dex, agi, int, spr, or luck.

Hopefully that helped a little. I might make a system that shows a graph of values, so you can see them so you can choose the best setup.
Hey whoa, a script below 1000 lines of scripting from you... watch your health there, seems dangerous to me ;)

Either way, interesting thing, I can definately imagine a bunch of things doable with that addition.

As always, keep up the good work ^^
It was a quick 20 minute script, but something I probably should have done... 2-3 years ago.

I'w working on the table generator graph. Just some math and some window layout manipulation. Should have it done in a bit, depending if I go to bed like I should.
Wow. This is quite unlike you, Seph. I mean, posting an incorrect version of an already well established script? That's getting a little sloppy, if you ask me. If you aren't sure what I'm talking about, look at line 156 of the curve generator module, where it uses an undeclared variable. I'm not sure about the rest of the script, there may be other errors as well. Anyway, this is a vey interesting looking script. BTW, do you know how to get the curve generator module to work as though it were the actual RMXP curve generator? I figured out how to mimic the straight line, as well as the fastest curve, but it doesn't mimic anything else. (By fastest, I mean the default curve with the bar all the way to the left on the "fast" to "slow" scale)
Dumb question, but...

I'm assuming these "new" stats will require additional Scripts (below this one) in order to do things like display the "new" stats in the Menu>Status page. This just makes the new stats in the "background" and sets their progression, but it doesn't change any in-game displays or really do anything with the stats.

Right? Or am I dumb?

Because, the next logical question for me anyway, is how would you get any new stats to display properly in the Menu>Status page?
@Glitch: Yeah I noticed it. I just got back home and had next to little time to test this out. I pulled the module from an older project where I thought I fixed that, but apparently I didn't fix it in that project (so many damn project folders).

I am working on adding a few new curve generators, 1 being the exp growth and 2 being the base stat curves. I honestly haven't even looked at that module since Trickster and I developed it nearly two years ago.

@Nearly Infinite: Your right. This script simply adds a method that creates and reads curves, vs. doing it.

It depends on how you plan on using these attributes. For things like new stats for actors, you will have to add the stat in the RPG::Actor class, make a method to read the stat (usually depending on level, as shown in luck example from above and finally, reading that method and drawing it on the window. Using the example from the main post, you would go into Window_Status, and somewhere like under draw_actor_parameter(@actor, 96, 400, 6), you would have to add:
  1.    self.contents.font.color = system_color
  2.     self.contents.draw_text(96, 432, 120, 32, 'Luck')
  3.     self.contents.font.color = normal_color
  4.     self.contents.draw_text(96 + 120, 432, 36, 32, @actor.luck.to_s, 2)
Expand to see the code.


Because of the number of things this can be used for, it couldn't really auto-draw newly added stats, because you could add these stats to basically any object. This method is really just an over-complicated attr_reader type method.
Nearly Infinite wrote:
Dumb question, but...

I'm assuming these "new" stats will require additional Scripts (below this one) in order to do things like display the "new" stats in the Menu>Status page. This just makes the new stats in the "background" and sets their progression, but it doesn't change any in-game displays or really do anything with the stats.

Right? Or am I dumb?

Because, the next logical question for me anyway, is how would you get any new stats to display properly in the Menu>Status page?


Well, you are right. To get them to display in the stats page, you'll have to edit that script. That requires changing some coordinates to make room (or font sizes), then inserting similar code to show the new stats.

Edit: it looks like Sephy beat me to the punch. You do that a lot when I'm not really paying attention.
Awesome doesn't begin to describe this script. Though I haven't tried yet, would this also work in VX?
Thanks and Yes. It is more of a Ruby addition, designed for rpg maker.
SephirothSpawn wrote:
Ok. You will have to take care of algorithms and such, but this is how you could set it up. We'll use the early/late formula of the curve generator module.

Content Hidden Spoiler
  1. class RPG::Actor
  2.     str = {
  3.        1 => [1, 1, 99, min_value, max_value, early, late],
  4.        2 => [1, 1, 99, min_value, max_value, early, late],
  5.        3 => [1, 1, 99, min_value, max_value, early, late],
  6.        4 => [1, 1, 99, min_value, max_value, early, late],
  7.        5 => [1, 1, 99, min_value, max_value, early, late],
  8.        6 => [1, 1, 99, min_value, max_value, early, late],
  9.        7 => [1, 1, 99, min_value, max_value, early, late]
  10.     }
  11.     str.default = [1, 1, 99, min_value, max_value, early, late]
  12.  
  13.     vit = {
  14.        1 => [1, 1, 99, min_value, max_value, early, late],
  15.        2 => [1, 1, 99, min_value, max_value, early, late],
  16.        3 => [1, 1, 99, min_value, max_value, early, late],
  17.        4 => [1, 1, 99, min_value, max_value, early, late],
  18.        5 => [1, 1, 99, min_value, max_value, early, late],
  19.        6 => [1, 1, 99, min_value, max_value, early, late],
  20.        7 => [1, 1, 99, min_value, max_value, early, late]
  21.     }
  22.     vit.default = [1, 1, 99, min_value, max_value, early, late]
  23.  
  24.     dex = {
  25.        1 => [1, 1, 99, min_value, max_value, early, late],
  26.        2 => [1, 1, 99, min_value, max_value, early, late],
  27.        3 => [1, 1, 99, min_value, max_value, early, late],
  28.        4 => [1, 1, 99, min_value, max_value, early, late],
  29.        5 => [1, 1, 99, min_value, max_value, early, late],
  30.        6 => [1, 1, 99, min_value, max_value, early, late],
  31.        7 => [1, 1, 99, min_value, max_value, early, late]
  32.     }
  33.     dex.default = [1, 1, 99, min_value, max_value, early, late]  
  34.  
  35.     agi = {
  36.        1 => [1, 1, 99, min_value, max_value, early, late],
  37.        2 => [1, 1, 99, min_value, max_value, early, late],
  38.        3 => [1, 1, 99, min_value, max_value, early, late],
  39.        4 => [1, 1, 99, min_value, max_value, early, late],
  40.        5 => [1, 1, 99, min_value, max_value, early, late],
  41.        6 => [1, 1, 99, min_value, max_value, early, late],
  42.        7 => [1, 1, 99, min_value, max_value, early, late]
  43.     }
  44.     agi.default = [1, 1, 99, min_value, max_value, early, late]
  45.  
  46.     int = {
  47.        1 => [1, 1, 99, min_value, max_value, early, late],
  48.        2 => [1, 1, 99, min_value, max_value, early, late],
  49.        3 => [1, 1, 99, min_value, max_value, early, late],
  50.        4 => [1, 1, 99, min_value, max_value, early, late],
  51.        5 => [1, 1, 99, min_value, max_value, early, late],
  52.        6 => [1, 1, 99, min_value, max_value, early, late],
  53.        7 => [1, 1, 99, min_value, max_value, early, late]
  54.     }
  55.     int.default = [1, 1, 99, min_value, max_value, early, late]
  56.  
  57.     spr = {
  58.        1 => [1, 1, 99, min_value, max_value, early, late],
  59.        2 => [1, 1, 99, min_value, max_value, early, late],
  60.        3 => [1, 1, 99, min_value, max_value, early, late],
  61.        4 => [1, 1, 99, min_value, max_value, early, late],
  62.        5 => [1, 1, 99, min_value, max_value, early, late],
  63.        6 => [1, 1, 99, min_value, max_value, early, late],
  64.        7 => [1, 1, 99, min_value, max_value, early, late]
  65.     }
  66.     spr.default = [1, 1, 99, min_value, max_value, early, late]
  67.  
  68.     luck = {
  69.        1 => [1, 1, 99, min_value, max_value, early, late],
  70.        2 => [1, 1, 99, min_value, max_value, early, late],
  71.        3 => [1, 1, 99, min_value, max_value, early, late],
  72.        4 => [1, 1, 99, min_value, max_value, early, late],
  73.        5 => [1, 1, 99, min_value, max_value, early, late],
  74.        6 => [1, 1, 99, min_value, max_value, early, late],
  75.        7 => [1, 1, 99, min_value, max_value, early, late]
  76.     }
  77.     luck.default = [1, 1, 99, min_value, max_value, early, late]
  78.  
  79.     add_stat_curve('str', str)
  80.     add_stat_curve('vit', vit)
  81.     add_stat_curve('dex', dex)
  82.     add_stat_curve('agi', agi)
  83.     add_stat_curve('int', int)
  84.     add_stat_curve('spr', spr)
  85.     add_stat_curve(luck', luck)
  86. end
  87.  
  88. class Game_Actor
  89.    def str
  90.       return $data_actors[@actor_id].str[@level]
  91.    end
  92.    def vit
  93.       return $data_actors[@actor_id].vit[@level]
  94.    end
  95.    def dex
  96.       return $data_actors[@actor_id].dex[@level]
  97.    end
  98.    def agi
  99.       return $data_actors[@actor_id].agi[@level]
  100.    end
  101.    def int
  102.       return $data_actors[@actor_id].int[@level]
  103.    end
  104.    def spr
  105.       return $data_actors[@actor_id].spr[@level]
  106.    end
  107.    def luck
  108.       return $data_actors[@actor_id].luck[@level]
  109.    end
  110. end
  111.  
Expand to see the code.


Now you will have to modify the min_value, max_value, early, late values for each stat, for each character. So:
  1.     luck = {
  2.        1 => [1, 1, 99, min_value, max_value, early, late],
Expand to see the code.

For actor 1, this is there luck stat setup. min_value is the value at level 1 (or whatever the 1 value is before the 99), max_value is the stat value at level 99 (or whatever the value is where 99 is). Early and late numbers I would test first. With the early and late values, I would try numbers between 0.5 and 1.5 (I believe, but you might have to tinker with this).

You will have to do that for each stat, for each actor. I would instead recommend using 4 of he default stats and just do this for 3 stats instead of redoing all seven.

If you want to see your values at each level, you can check with:
  1. p $data_actors[actor_id].stat
Expand to see the code.


Replace actor_id with 1-7, whichever actor you are checking and stat with str, vit, dex, agi, int, spr, or luck.

Hopefully that helped a little. I might make a system that shows a graph of values, so you can see them so you can choose the best setup.


So let's say I modify luck. If I edit the code this way for explanation purposes:
x => [1, 1, 99, min_value, max_value, early, late]
2 => [1, 1, 99, min_value, max_value, early, late]

The 'x' would be the level of the character? And inside the brackets, the first number represents min_value, the second max_value, and the third what? I think if I knew what those represent I would understand it more clearly.
By the way, I'm not sure I see it in the script, but each attribute affects things like attack power, speed, defense, and so forth, correct?
x would be the actor id.

The numbers between the [] are all curve generators parameters. First number being the type, and the trailing numbers being specific algorithm parameters. You can see from the script heading:
  1. # #   Type : 0 - Point Slope
  2. #          1 - Early / Late
  3. #          2 - Early / Steady / Late + Curves
  4. #
  5. #   Args :
  6. #
  7. #    Type 0 : min_level, max_level, start value, inflation
  8. #    Type 1 : min_level, max_level, min_value, max_value, early, late
  9. #    Type 2 : min level, mid_level, max level, min value, mid_value,
  10. #             max value, early, late, steady, curve 1, curve 2, integer
Expand to see the code.


The first number (1) represents which curve generator algorithm you will be using (0- Point-Slope, 1-Early Late, 2-Early, Mid, Late)

So, if you are using 0, your [] will look like:
  1. x => [0, min_level, max_level, start value, inflation]
  2. If you are using 1, your [] will look like:
  3. [code]x => [1, min_level, max_level, min_value, max_value, early, late][/code]
  4. If you are using 2, your [] will look like:
  5. [code]x => [2, min level, mid_level, max level, min value, mid_value, max value, early, late, steady, curve 1, curve 2, integer]
Expand to see the code.


I suggest you just use type 0 or 1, as those will be better suited for you.

I am going to add the exp and stat base algorithms as soon as I can.
Demo or screenshot plz 😀 (im couche potato) :thumb:
Neither is appropriate for this script. The only thing close to a demo would be examples on usage, and there are a few in this thread.
Hemm I wanted to try out this script by using the luck example. But for some reason I get the error when I have an event on my map that calls $game_actors[1].stam ( I'm using the method print). The error being "undefined local variable or method 'hash_settings' for #<RPG::Actor:0x1505198>

This is my script thats right bellow the Curve Generator and Attribute Modifier scripts.
  1.  
  2. class RPG::Actor
  3.   stam = {
  4.      1 => [0, 1, 99, 5, 1],
  5.      2 => [0, 1, 99, 4, 2],
  6.      7 => [0, 1, 99, 2, 4],
  7.      8 => [0, 1, 99, 1, 5],
  8.   }
  9.   stam.default = [0, 1, 99, 3, 3]
  10.   add_stat_curve('stam', stam)
  11. end
  12.  
  13.  
  14. class Game_Actor
  15.   def stam
  16.      return $data_actors[@actor_id].stam[@level]
  17.   end   
  18. end
  19.  
Expand to see the code.


Did I put something in the wrong order? I can't figure out what could be causing the problem in the least. (Doesn't help I'm not the most experienced in Ruby)

EDIT: Here is an image of some info my companion in this endeavor printed that he says might shed some light on things.
I'll look into this. I may have messed something up when I updated it.
I'm the one who had that img posted a while ago. While troubleshooting the thing all over the place, I knoticed that *hash_settings wasn't being converted by name so I did the same thing you did in order to turn *hash_settings into *stam, but it's passing 4-5 arguments (I tried some variations) instead of 1, so it seems. So that's the main problem right there. It's Line 69 of Attribute_Modifier.

I hope that helps.
Quick question. how would I go about adding another min/max stat like HP or MP
HP isn't a stat by itself, it's a variable. MaxHP is a stat though, and you can do that with the stat creation feature. You'd have to create similar methods that handle the HP for your needs in other classes, like mainly Game_Actor, of course.
I MIGHT use this for my game, but I have to edit the XAS system so it works with the new variables and stats;) Nice work, though.
I know this might seem like a simple question, my scripting is seriously lacking. How can I call the attribute that I create through events and modify it (Luck +1, or -5, etc)? Can I call the attribute into a variable within an event? (variable 23 = luck) Please forgive me for necro-posting.

Edit: I answered my second question. I found I can call it with $game_variables[#] = $data_actors[@actor_id].skillname. I tried doing it the other way in an attempt to store the variables in the script (i.e. $data_actors[@actor_id].skillname = $game_variables[#]), but it returns an error.
Hello,
I was wondering, if I were to want to replace the default stats with the following:
Strength
Dexterity
Constitution
Intelligence
Wisdom
Charisma

How would I use your script to set up those stats. The reason I ask, is since I plan the stats to be static. Once made (at character creation, an in game menu) they do not change except with the effects of an item.
If one would be kind enough to help me by providing a script (even if it is a template) for how one is to set up a static stat that grows only by items, then I would be so very happy.

Thank you for your time.
I am sceptical on this but could the script be used on say a weapon or a piece of armour. If it can I would guess it would require an equipment level up/experience script correct?

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