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.

Randomized Stats on Level Up 2.20 (Updated 03/16/11!)

Randomized Stats on Level Up Version: 2.20
By: Glitchfinder


Introduction

Well, I finished an interesting script for a request a couple of hours ago, and the concept really intrigued me. So, I took that script, and I simplified it so that it is easier to use with the default database. (although it no longer fits the request) It is actually a script that will partially randomize a character's stat gains once they level up, or if they must level down. All of the instructions are included in the header. Anyway, on to the script!

Features

  • Adds variation to an otherwise dull portion of the game!
  • Allows the programmer to set how much the stats can vary!
  • takes the base values from the database!

Screenshots

Since this script has no visual elements, a screenshot cannot be taken.

Script

RMXP Edition
Code:
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

# ** Glitchfinder's Randomized Stats on Level Up                 [RPG Maker XP]

#    Version 2.20

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

#  This script is meant to help randomize an actor's stats upon leveling up.

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

# * Version History

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#   Version 1.00 ------------------------------------------------- (2008-07-11)

#     - Initial version

#     - Author: Glitchfinder

#   Version 2.00 ------------------------------------------------- (2008-07-13)

#     - Script completely rewritten to use hashes

#     - Author: Glitchfinder

#    Version 2.10 ------------------------------------------------ (2008-07-14)

#      - Fixed various errors

#      - Cleaned code

#      - Author: Glitchfinder

#    Version 2.20 ----=------------------------------------------- (2011-03-16)

#      - Added better documentation

#      - Fixed crash on F12

#      - Added missing return value to base_sp()

#      - Modified stat calculations for clarity

#      - Author: Glitchfinder

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

# * Instructions

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Place this script above Main, and below the default scripts. (I realize this

#  is obvious to most, but some people don't get it.)

#

#  To modify the basic starting stats of a character, you must edit the

#  Actor_Stats array in the Stats module, using the following rules:

#    * Line 1 is the stats of the first actor in the database. (Aluxes is the

#      default) Line 2 is the second actor (Basil), etc.

#    * The statistics are in order on each line, where the first entry is

#      maximum HP, entry 2 is maximum MP, entry 3 is Strength, entry 4 is

#      Dexterity, entry 5 is Agility, and entry 6 is Intelligence.

#

#  To modify the variation of an actor's statistics upon changing levels, you

#  must edit the Stats hash in the Stats module, using the following rules:

#    * The value in each entry is the maximum that the new stat may vary from

#      the default increase or decrease defined for that stat in the Database.

#      (Calculated by subtracting the default value of the new level from the

#      default value of the original level) In other words, if the default

#      change is three, and you have the variation set to two, then the stat

#      can go up anywhere between one and five points.

#    * When leveling up, a stat cannot go down, although it may also remain

#      unchanged. This is because if the random number chosen by the script is

#      negative when levelling up, the stat is left unchaged instead of being

#      changed in the opposite direction of that intended.

#

#  If you modify the default actors within the game, you must also modify this

#  script, so that the actors will all have their correct stats. If you add

#  actors, you must add new lines to this script, and vice-versa if you delete

#  actors. These new lines should be in the Actor_Stats array and the Stats

#  hash within the Stats module.

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

# * Advice

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  This script is meant for people with at least basic scripting knowledge. It

#  may be difficult to use, and thus, if you are unsure of your abilities, it

#  may be simpler to avoid using this script.

#

#  Do not make the values in the Stats hash too high. This can result in a game

#  becoming too easy or difficult for the player, due to stats that are either

#  too high or too low. For most stats, 2 or 3 should be more than enough

#  variance.

#

#  Edit the default values that I have placed in this script. Although it may

#  be difficult to properly balance a character, it is certain that at least

#  some of the characters will be unbalanced if they are using the default

#  values I placed within the Stats hashes.

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

# * Contact

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Glitchfinder, the author of this script, may be contacted through his

#  website, found at [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#

#  You may also find Glitchfinder at [url=http://www.hbgames.org]http://www.hbgames.org[/url]

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

# * Usage

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  This script may be used with the following terms and conditions:

#

#    1. This script is free to use in any noncommercial project. If you wish to

#       use this script in a commercial (paid) project, please contact

#       Glitchfinder at his website.

#    2. This script may only be hosted at the following domains:

#         [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#         [url=http://www.hbgames.org]http://www.hbgames.org[/url]

#    3. If you wish to host this script elsewhere, please contact Glitchfinder.

#    4. If you wish to translate this script, please contact Glitchfinder. He

#       will need the web address that you plan to host the script at, as well

#       as the language this script is being translated to.

#    5. This header must remain intact at all times.

#    6. Glitchfinder remains the sole owner of this code. He may modify or

#       revoke this license at any time, for any reason.

#    7. Any code derived from code within this script is owned by Glitchfinder,

#       and you must have his permission to publish, host, or distribute his

#       code.

#    8. This license applies to all code derived from the code within this

#       script.

#    9. If you use this script within your project, you must include visible

#       credit to Glitchfinder, within reason.

#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

 

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

# ** Stats

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

#  This module handles actors' stats and their changes. Its used

# within the Game_Actor class.

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

 

module Stats

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

  # * Store Actor Stats

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

  Actor_Stats = [

    # HP,  SP,  STR, DEX, AGI, INT

      741, 534, 67,  54,  58,  36,

      695, 591, 60,  65,  62,  31,

      747, 435, 76,  56,  52,  37,

      546, 590, 41,  73,  72,  32,

      590, 570, 50,  79,  62,  48,

      656, 531, 51,  62,  50,  33,

      486, 661, 43,  55,  55,  64,

      422, 606, 31,  30,  46,  71

  ]

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

  # * Name Actor Stats

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

  Stat_Names = ['hp', 'sp', 'str', 'dex', 'agi', 'int']

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

  # * Set Actor Stat Variance

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

  Stats = {}

  # Actor 1 setup

  Stats[1] = {

    'hp' => 26,

    'sp' => 4,

    'str' => 3,

    'dex' => 3,

    'agi' => 2,

    'int' => 2

  }

  # Default actor setup

  Stats.default = {

    'hp' => 24,

    'sp' => 3,

    'str' => 2,

    'dex' => 2,

    'agi' => 2,

    'int' => 2

  }

end

 

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

# ** Game_Actor

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

#  This class handles the actor. Its used within the Game_Actors class

#  ($game_actors) and refers to the Game_Party class ($game_party).

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

class Game_Actor < Game_Battler

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

  # * Convert Stat Names to their System Numbers

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

  Stat_Numbers = {

    'hp' => 0,

    'sp' => 1,

    'str' => 2,

    'dex' => 3,

    'agi' => 4,

    'int' => 5

  }

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

  # * Alias Methods

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

  # If the setup method has not been aliased

  unless method_defined?(:randomstatgains_setup)

    # Alias the enemy selection method

    alias randomstatgains_setup setup

  end

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

  # * Setup

  #     actor_id : actor ID

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

  def setup(actor_id)

    # Create an empty stat hash

    @stat_gains = {}

    # Iterate through all stats

    for stat in Stats::Stat_Names

      # Add the stat gain to the hash

      @stat_gains[stat] = []

    end

    # Setup stat gains

    randomstatgains_setup(actor_id)

  end

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

  # * Get Basic Maximum HP

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

  def base_maxhp

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 2)

    # Get the actor's stat

    n =  Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['hp'].sum

    return n

  end

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

  # * Get basic Maximum MP

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

  def base_maxmp

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 1)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['sp'].sum

    return n

  end

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

  # * Get Basic Strength

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

  def base_str

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + (2 * (@actor_id - 2))

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['str'].sum

    # Get the current weapon and armor data

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    # Add the weapon and armor stat boosts

    n += weapon != nil ? weapon.str_plus : 0

    n += armor1 != nil ? armor1.str_plus : 0

    n += armor2 != nil ? armor2.str_plus : 0

    n += armor3 != nil ? armor3.str_plus : 0

    n += armor4 != nil ? armor4.str_plus : 0

    # Return the stat value, with a maximum of 999 and a minimum of 1

    return [[n, 1].max, 999].min

  end

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

  # * Get Basic Dexterity

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

  def base_dex

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 1)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['dex'].sum

    # Get the current weapon and armor data

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    # Add the weapon and armor stat boosts

    n += weapon != nil ? weapon.dex_plus : 0

    n += armor1 != nil ? armor1.dex_plus : 0

    n += armor2 != nil ? armor2.dex_plus : 0

    n += armor3 != nil ? armor3.dex_plus : 0

    n += armor4 != nil ? armor4.dex_plus : 0

    # Return the stat value, with a maximum of 999 and a minimum of 1

    return [[n, 1].max, 999].min

  end

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

  # * Get Basic Agility

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

  def base_agi

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 2)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['agi'].sum

    # Get the current weapon and armor data

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    # Add the weapon and armor stat boosts

    n += weapon != nil ? weapon.agi_plus : 0

    n += armor1 != nil ? armor1.agi_plus : 0

    n += armor2 != nil ? armor2.agi_plus : 0

    n += armor3 != nil ? armor3.agi_plus : 0

    n += armor4 != nil ? armor4.agi_plus : 0

    # Return the stat value, with a maximum of 999 and a minimum of 1

    return [[n, 1].max, 999].min

  end

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

  # * Get Basic Intelligence

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

  def base_int

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 3)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['int'].sum

    # Get the current weapon and armor data

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    # Add the weapon and armor stat boosts

    n += weapon != nil ? weapon.int_plus : 0

    n += armor1 != nil ? armor1.int_plus : 0

    n += armor2 != nil ? armor2.int_plus : 0

    n += armor3 != nil ? armor3.int_plus : 0

    n += armor4 != nil ? armor4.int_plus : 0

    # Return the stat value, with a maximum of 999 and a minimum of 1

    return [[n, 1].max, 999].min

  end

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

  # * Change EXP

  #     exp : new EXP

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

  def exp=(exp)

    # Force experience within bounds

    @exp = [[exp, 9999999].min, 0].max

    # Level up

    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0

      # Increase the actor level

      @level += 1

      # Iterate through each stat

      Stats::Stat_Names.each do |stat_name|

        # Calculate the new stat gain

        n = random_gain(@actor_id, stat_name)

        # Add the new gain to the actor's stat gains

        @stat_gains[stat_name] << n

      end

      # Iterate through the class skill list

      for skill in $data_classes[@class_id].learnings

        # If the actor learned a new skill

        if skill.level == @level

          # Teach the actor the new skill

          learn_skill(skill.skill_id)

        end

      end

    end

    # Level down

    while @exp < @exp_list[@level]

      # Decrease the actor level

      @level -= 1

      # Iterate through each stat

      Stats::Stat_Names.each do |stat_name|

        # Remove the latest gains from the stat

        @stat_gains[stat_name].pop

      end

    end

    # Correct the actor's maximum HP and maximum SP

    @hp = [@hp, self.maxhp].min

    @sp = [@sp, self.maxsp].min

  end

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

  # * Determine Random Stat Gain

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

  def random_gain(actor_id, stat_name)

    # Begin error checking

    begin

      # Get the stat number

      s_number = Stat_Numbers[stat_name].to_i

      # Get the default stat change

      default_change = ($data_actors[actor_id].parameters[s_number, @level] -

        $data_actors[actor_id].parameters[s_number, @level - 1])

      # Calculate the stat changes

      change = rand(Stats::Stats[actor_id][stat_name])

      # Calculate a random number

      random = rand(2)

      # If the random number is even

      if (1 != (random % 2))

        # Set the random change to a negative value

        change *= -1

      end

      # Add the default change to the random change

      change += default_change

      # If the change is negative

      if change <= 0

        # Set the change to 0

        return 0

      # If the change is positive

      else

        # Return the newly calculated stat change

        return change

      end

    # If an error occurs

    rescue

      # Print an error message

      p 'Undefined stat_name: ' + stat_name + ' for actor: ' + actor_id.to_s

      # Return that no stat change has occurred

      return 0

    end

  end

end

 

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

# ** Array

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

#  This hidden class handles arrays. It is used within many other

# classes to store data for future retrieval.

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

 

class Array

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

  # * Name      : Sum

  #   Info      : Sums all values in the array

  #   Author    : Trickster

  #   Call Info : No Arguments

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

  def sum

    # Initialize local variable n

    n = 0

    # Sum Up Values in Array

    each {|num| n += num}

    # Return number

    return n

  end

end

RMVX Edition
Code:
#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

# ** Glitchfinder's Randomized Stats on Level Up                 [RPG Maker VX]

#    Version 2.20

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

#  This script is meant to help randomize an actor's stats upon levelling up.

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

# * Version History

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#   Version 1.00 ------------------------------------------------- (2008-07-11)

#     - Initial version

#     - Author: Glitchfinder

#   Version 2.00 ------------------------------------------------- (2008-07-13)

#     - Script completely rewritten to use hashes

#     - Author: Glitchfinder

#    Version 2.10 ------------------------------------------------ (2008-07-14)

#      - Fixed various errors

#      - Cleaned code

#      - Author: Glitchfinder

#    Version 2.20 ----=------------------------------------------- (2011-03-16)

#      - Added better documentation

#      - Fixed crash on F12

#      - Added missing return value to base_mp()

#      - Modified stat calculations for clarity

#      - Author: Glitchfinder

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

# * Instructions

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Place this script above Main, and below the default scripts. (I realize this

#  is obvious to most, but some people don't get it.)

#

#  To modify the basic starting stats of a character, you must edit the

#  Actor_Stats array in the Stats module, using the following rules:

#    * Line 1 is the stats of the first actor in the database. (Ralph is the

#      default) Line 2 is the second actor (Ulrika), etc.

#    * The statistics are in order on each line, where the first entry is

#      maximum HP, entry 2 is maximum MP, entry 3 is Attack, entry 4 is

#      Defense, entry 5 is Spirit, and entry 6 is Agility.

#

#  To modify the variation of an actor's statistics upon changing levels, you

#  must edit the Stats hash in the Stats module, using the following rules:

#    * The value in each entry is the maximum that the new stat may vary from

#      the default increase or decrease defined for that stat in the Database.

#      (Calculated by subtracting the default value of the new level from the

#      default value of the original level) In other words, if the default

#      change is three, and you have the variation set to two, then the stat

#      can go up anywhere between one and five points.

#    * When leveling up, a stat cannot go down, although it may also remain

#      unchanged. This is because if the random number chosen by the script is

#      negative when leveling up, the stat is left unchaged instead of being

#      changed in the opposite direction of that intended.

#

#  If you modify the default actors within the game, you must also modify this

#  script, so that the actors will all have their correct stats. If you add

#  actors, you must add new lines to this script, and vice-versa if you delete

#  actors. These new lines should be in the Stats hash within the Stats module.

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

# * Glitchfinder's Advice

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Do not make the values in the Stats hash too high. This can result in a game

#  becoming too easy or difficult for the player, due to stats that are either

#  too high or too low. For most stats, 2 or 3 should be more than enough

#  variance.

#

#  Edit the default values that I have placed in this script. Although it may

#  be difficult to properly balance a character, it is certain that at least

#  some of the characters will be unbalanced if they are using the default

#  values I placed within the Stat_Change_Variance array.

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

# * Contact

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  Glitchfinder, the author of this script, may be contacted through his

#  website, found at [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#

#  You may also find Glitchfinder at [url=http://www.hbgames.org]http://www.hbgames.org[/url]

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

# * Usage

#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#  This script may be used with the following terms and conditions:

#

#    1. This script is free to use in any noncommercial project. If you wish to

#       use this script in a commercial (paid) project, please contact

#       Glitchfinder at his website.

#    2. This script may only be hosted at the following domains:

#         [url=http://www.glitchkey.com]http://www.glitchkey.com[/url]

#         [url=http://www.hbgames.org]http://www.hbgames.org[/url]

#    3. If you wish to host this script elsewhere, please contact Glitchfinder.

#    4. If you wish to translate this script, please contact Glitchfinder. He

#       will need the web address that you plan to host the script at, as well

#       as the language this script is being translated to.

#    5. This header must remain intact at all times.

#    6. Glitchfinder remains the sole owner of this code. He may modify or

#       revoke this license at any time, for any reason.

#    7. Any code derived from code within this script is owned by Glitchfinder,

#       and you must have his permission to publish, host, or distribute his

#       code.

#    8. This license applies to all code derived from the code within this

#       script.

#    9. If you use this script within your project, you must include visible

#       credit to Glitchfinder, within reason.

#≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡

 

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

# ** Stats

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

#  This module handles actors' stats and their changes. It's used within the

#  Game_Actor class.

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

 

module Stats

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

  # * Store Actor Stats

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

  Actor_Stats = [

    # HP,  MP,  ATK, DEF, SPI, AGI

      466, 70,  17,  17,  21,  23,

      594, 70,  22,  16,  11,  20,

      391, 98,  12,  17,  20,  15,

      275, 107, 14,  13,  42,  16,

      466, 70,  13,  19,  15,  13,

      444, 59,  16,  12,  15,  23,

      523, 63,  17,  14,  15,  21,

      362, 56,  13,  12,  15,  27

  ]

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

  # * Name Actor Stats

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

  Stat_Names = ['hp', 'mp', 'atk', 'defense', 'spi', 'agi']

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

  # * Set Actor Stat Variance

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

  Stats = {}

  # Actor 1 setup

  Stats[1] = {

    'hp' => 26,

    'mp' => 4,

    'atk' => 3,

    'defense' => 3,

    'spi' => 2,

    'agi' => 2

  }

  # Default actor setup

  Stats.default = {

    'hp' => 24,

    'mp' => 3,

    'atk' => 2,

    'defense' => 2,

    'spi' => 2,

    'agi' => 2

  }

end

 

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

# ** Game_Actor

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

#   This class handles actors. Its used within the Game_Actors class

# ($game_actors) and referenced by the Game_Party class ($game_party).

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

 

class Game_Actor < Game_Battler

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

  # * Convert Stat Names to their System Numbers

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

  Stat_Numbers = {

    'hp' => 0,

    'mp' => 1,

    'atk' => 2,

    'defense' => 3,

    'spi' => 4,

    'agi' => 5

  }

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

  # * Alias Methods

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

  # If the setup method has not been aliased

  unless method_defined?(:randomstatgains_setup)

    # Alias the enemy selection method

    alias randomstatgains_setup setup

  end

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

  # * Setup

  #     actor_id : actor ID

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

  def setup(actor_id)

    # Create an empty stat hash

    @stat_gains = {}

    # Iterate through all stats

    for stat in Stats::Stat_Names

      # Add the stat gain to the hash

      @stat_gains[stat] = []

    end

    # Setup stat gains

    randomstatgains_setup(actor_id)

  end

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

  # * Get Basic Maximum HP

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

  def base_maxhp

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 2)

    # Get the actor's stat

    n =   Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['hp'].sum

    return n

  end

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

  # * Get basic Maximum MP

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

  def base_maxmp

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 1)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['mp'].sum

    return n

  end

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

  # * Get Basic Attack

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

  def base_atk

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + (2 * (@actor_id - 2))

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['atk'].sum

    # Add item attack values to the stat

    for item in equips.compact do n += item.atk end

    return n

  end

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

  # * Get Basic Defense

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

  def base_def

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 1)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['defense'].sum

    # Add item defense values to the stat

    for item in equips.compact do n += item.def end

    return n

  end

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

  # * Get Basic Spirit

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

  def base_spi

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 2)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['spi'].sum

    # Add item spirit values to the stat

    for item in equips.compact do n += item.spi end

    return n

  end

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

  # * Get Basic Agility

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

  def base_agi

    # Calculate the array index of the stat

    stat = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 3)

    # Get the actor's stat

    n = Stats::Actor_Stats[stat.to_i].to_i

    # Add the stat gains to the value

    n += @stat_gains['agi'].sum

    # Add item agility values to the stat

    for item in equips.compact do n += item.agi end

    return n

  end

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

  # * Level Up

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

  def level_up

    # Increase the level by one

    @level += 1

    # Iterate through each stat

    Stats::Stat_Names.each do |stat_name|

      # Calculate the new stat gain

      n = random_gain(@actor_id, stat_name)

      # Add the new gain to the actor's stat gains

      @stat_gains[stat_name] << n

    end

    # Iterate through the class skill list

    for learning in self.class.learnings

      # Teach the actor new skills they have learned

      learn_skill(learning.skill_id) if learning.level == @level

    end

  end

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

  # * Level Down

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

  def level_down

    # Subtract one from the actor level

    @level-= 1

    # Iterate through each stat

    Stats::Stat_Names.each do |stat_name|

      # Remove the latest gains from the stat

      @stat_gains[stat_name].pop

    end

  end

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

  # * Determine Random Stat Gain

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

  def random_gain(actor_id, stat_name)

    # Begin error checking

    begin

      # Get the stat number

      s_number = Stat_Numbers[stat_name].to_i

      # Get the default stat change

      default_change = (actor.parameters[s_number, @level] -

        actor.parameters[s_number, @level - 1])

      # Calculate the stat changes

      change = rand(Stats::Stats[actor_id][stat_name])

      # Calculate a random number

      random = rand(2)

      # If the random number is even

      if (1 != (random % 2))

        # Set the random change to a negative value

        change *= -1

      end

      # Add the default change to the random change

      change += default_change

      # If the change is negative

      if change <= 0

        # Set the change to 0

        return 0

      # If the change is positive

      else

        # Return the newly calculated stat change

        return change

      end

    # If an error occurs

    rescue

      # Print an error message

      p 'Undefined stat_name: ' + stat_name + ' for actor: ' + actor_id.to_s

      # Return that no stat change has occurred

      return 0

    end

  end

end

 

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

# ** Array

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

#   This hidden class handles arrays. It is used within many other

# classes to store data for future retrieval.

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

 

class Array

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

  # * Name        : Sum

  #     Info      : Sums all values in the array

  #     Author    : Trickster

  #     Call Info : No Arguments

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

  def sum

    # Initialize local variable n

    n = 0

    # Sum Up Values in Array

    each {|num| n += num}

    # Return number

    return n

  end

end

Instructions
(These are taken from the VX Version. Stat and Character names vary in the XP version.)

Place this script above Main, and below the default scripts. (I realize this is obvious to most, but some people don't get it.)

To modify the basic starting stats of a character, you must edit the Actor_Stats array in the Stats module, using the following rules:
  • Line 1 is the stats of the first actor in the database. (Ralph is the default) Line 2 is the second actor (Ulrika), etc.
  • The statistics are in order on each line, where the first entry is maximum HP, entry 2 is maximum MP, entry 3 is Attack, entry 4 is Defense, entry 5 is Spirit, and entry 6 is Agility.

To modify the variation of an actor's statistics upon changing levels, you must edit the Stats hash in the Stats module, using the following rules:
  • The value in each entry is the maximum that the new stat may vary from the default increase or decrease defined for that stat in the Database. (Calculated by subtracting the default value of the new level from the default value of the original level) In other words, if the default change is three, and you have the variation set to two, then the stat can go up anywhere between one and five points.
  • When leveling up, a stat cannot go down, although it may also remain unchanged. This is because if the random number chosen by the script is negative when leveling up, the stat is left unchaged instead of being changed in the opposite direction of that intended.

If you modify the default actors within the game, you must also modify this script, so that the actors will all have their correct stats. If you add actors, you must add new lines to this script, and vice-versa if you delete actors. These new lines should be in the Stats hash within the Stats module.

FAQ

Due to some misunderstandings on what I meant by "partially randomize", I will attempt to explain in a little more detail. What I meant is that this script will take the default amount that a stat will go up when you level up (as defined in the database), and it will then use another value (defined by the user within the script) to change the amount that stat will go up. To give an example, if the default increase for Ralph's HP when going to level 2 is 67, and you set the amount it can vary to 26, then his HP can go up by anywhere between 41 and 93 points. It can be anything between the default increase minus the variance to the default increase plus the variance.

Credits and Thanks

Thanks to psiclone for making the original request, because otherwise I wouldn't have a script to share.

Also, thanks to SephirothSpawn for helping me clean up this script and make it much more efficient. (Although a bit more complex...)

Author's Notes

Version 2.0 was released to make the script more efficient. It features some changes in the operation of the script, and thus is a little more complex. If anyone would like to see the original script for the request, they can look here. Be warned, as this version is actually more complex, and much less efficient.

Terms and Conditions

  • This script is free to use in any noncommercial project. If you wish to use this script in a commercial (paid) project, please contact Glitchfinder at his website.
  • This script may only be hosted at the following domains:
    http://www.glitchkey.com
    http://www.hbgames.org
  • If you wish to host this script elsewhere, please contact Glitchfinder.
  • If you wish to translate this script, please contact Glitchfinder. He will need the web address that you plan to host the script at, as well as the language this script is being translated to.
  • The script header must remain intact at all times.
  • Glitchfinder remains the sole owner of this code. He may modify or revoke this license at any time, for any reason.
  • Any code derived from code within this script is owned by Glitchfinder, and you must have his permission to publish, host, or distribute his code.
  • This license applies to all code derived from the code within this script.
  • If you use this script within your project, you must include visible credit to Glitchfinder, within reason.
 

ikos

Member

What do you mean by "partially randomize"?
It's a little distracting. Do you mean if follows some path from the database's assigned values? Please elaborate, I might be interested. :D
 
I went to post something last night, but never finished it. I have a few comments/suggestions to greatly improve the way this script works.

I could go through all your code, and comment about alot of things you have done, but that wouldn't be as helpful. I honestly hope you take the advice below and greatly revise your code. If you wish to here my thoughts on your original code, I can share a few thoughts over PM. I am not trying to be rude, but I see potential and would just like to help.



To start off, lets re-think the script. You are going to be randomizing stat gains each level, with the option to set the random values for each actor and each stat. Now, this is going to be very repetitive unless we use some quick code blocks to search through efficient organized data. First, since we will be customizing it for each actor for each stat, arrays really aren't the way to go. We should use a multi-dimension hash instead. I also created a constant to hold the each stat name we will be using in the script (this will later serve for loop patterns).

Code:
module RandomStatGains
  Stat_Names = ['hp', 'sp', 'str', 'dex', 'int', 'agi']
  # Stats[actor_id] = {stat_name => n, ...}
  Stats = {}
  # Actor 1 setup
  Stats[1] = {'hp' => 100, 'sp' => 30, 'str' => 5, 'dex' => 4, 'int' => 3, 'agi' => 3}
  # Default actor setup
  Stats.default ={'hp' => 50, 'sp' => 25, 'str' => 3, 'dex' => 3, 'int' => 3, 'agi' => 3}
end

Now, we might as well create a method in this module to get the random stat gain for each actor in each stat. This will simply code later.
Code:
module RandomStatGains
  def self.random_gain(actor_id, stat_name)
    begin
      return rand(Stats[actor_id][stat_name])
    rescue
      p 'Undefined stat_name: ' + stat_name + ' for actor: ' + actor_id.to_s
    end
  end
end
(The above begin, rescue code just is an error catcher in case someone defines something wrong)

Now, how about the stat gains per level. The best way for this is to create an instance variable in each Game_Actor class (in your previous version, you modified a constant, something you should never do mid-code. Plus, that would not have saved if your game was reloaded or reset). To add this instance, we will create it upon creation of all actors. I suggest a hash, with the keys being the stat names and values being an array of values gain each level. We can add and remove these values for each level up.

Code:
class Game_Actor
  alias_method :glitchfinder_randstatgains_setup, :setup
  def setup(actor_id)
    @stat_gains = {}
    for stat in RandomStatGains::Stat_Names
      @stat_gains[stat] = []
    end
    glitchfinder_randstatgains_setup(actor_id)
  end
end

Now, before we get to the stat reading, lets just finish the gaining stats when we level_up and level_down. We will use our module method here for adding a random value to our stat hash, and removing the last bonus of each array for each stat when leveling down. So our stat gains hash will look like:
Code:
# After 2 level gains
@stat_gains = {
  'hp' => [39, 21],
  'sp' => [15, 13],
  'str' => [3, 1],
  'dex' => [3, 4],
  'int' => [2, 2],
  'agi' => [3, 1]
}
# After a level down
@stat_gains = {
  'hp' => [39],
  'sp' => [15],
  'str' => [3],
  'dex' => [3],
  'int' => [2],
  'agi' => [3]
}


So here is our code:
Code:
class Game_Actor
  alias_method :glitchfinder_randstatgains_levelu, :level_up
  alias_method :glitchfinder_randstatgains_leveld, :level_down
  def level_up
    # Pass through each stats
    RandomStatGains::Stat_Names.each do |stat_name|
      n = RandomStatGains.random_gain(@actor_id, stat_name)
      @stat_gains[stat_name] << n
    end
    glitchfinder_randstatgains_levelu
  end
  def level_down
    RandomStatGains::Stat_Names.each do |stat_name|
      @stat_gains[stat_name].pop
    end
    glitchfinder_randstatgains_leveld
  end
end

So now all we have to do for each stat is add our stat gain sum for each stat gain. Now, arrays don't have a sum method, so we have to create one. There is one in the MACL 2.3, so we can just use that.
Code:
class Array
  #---------------------------------------------------------------------------
  # * Name      : Sum
  #   Info      : Sums all values in the array
  #   Author    : Trickster
  #   Call Info : No Arguments
  #---------------------------------------------------------------------------
  def sum
    # Initialize local variable n
    n = 0
    # Sum Up Values in Array
    each {|num| n += num}
    # Return number
    return n
  end
end


Ok, now, we just need to add these to each stat total. An example of the first one can be done below.
Code:
class Game_Actor
  alias_method :glitchfinder_randstatgains_hasehp, :base_hp
  def base_hp
    # gets original value
    n = glitchfinder_randstatgains_hasehp
    # adds total stat gains
    n += @stat_gains[stat_name].sum
    # return n
    return n
  end
end


Now put it all together, do that for each stat (or more if you wish). If you wish to do this and need any help, just ask.

I look forward to seeing a completed product. :)
 
Well, as you just proved, I am still learning to code. First off, I was never really sure what a hash is. Would you be able to explain that in easier terms than the help files do? Next, I greatly appreciate the help, and, as soon as I can figure out what all of your suggestions do, I'll try to incorporate them. Thanks! (I just realized that tutorials on hashes/arrays/other complicated and semi-complicated ruby would be helpful to new scripters...)

Edit: I think I'm figuring out the hashes. It looks similar to arrays, in that it stores data, just with a different format. (And it appears to store arrays as well...) I'm also not sure what your purpose was in keeping some of my old methods, like the levelup or leveldown ones. From what I can tell, you pretty much eliminated any need for them.

Edit2: I just tried to put it all together, and realized you were writing for RMXP. Also, when I modified the other parts to work with rmvx, the MACL's definition of a sum for arrays turned up with a nil:NilClass error.
 
A hash is just like an array, but instead of the indexing being based of integers that go from 0 to x, the indexing is based off any Ruby object.

Array = [object, object, object]
Hash = {object => object, object => object, object => object}

Array = [object1, object2, object3]
Hash = {0 => object1, 1 => object2, 2 => object3}

Hashes are extremely useful when creating data for existing objects like the $data and $game classes. Hashes also have a .default method, which instead of returning nil when you try to read from a non-defined index, it will return the default. For instance:
Code:
hash = {1 => 2, 3 => 4}
hash[1] -> 2
hash[5] -> nil
hash.default = 0
hash[5] -> 0

Not sure what you mean by "I'm also not sure what your purpose was in keeping some of my old methods, like the levelup or leveldown ones. From what I can tell, you pretty much eliminated any need for them." We still need these methods to know when we level up and level down.

I didn't explain one thing, the alias_method. When you call alias_method, you are renaming an existing method.

alias_method :new_method_name, :eek:ld_method_name

This allows us to add processing before an existing method call and/or after an existing method call.

Lets say you write a method that returns a name that is passed:
Code:
def return_string(string = '')
  return "Name: #{string}"
end

Well, what if we want to add () after it for whatever reason. We alias the method and proceed from there.
Code:
alias_method :old_return_string, :return_string
def return_string(string = '')
  n = old_return_string(string)
  return "#{n} ()"
end

Our return_string method will now be called as it always has, but the original return_string method will be called from our new method now.

When I did it with that level_up and level_down method, we want to keep everything that happens in the original level_up/down methods, just add to it. By using the alias_method, more scripts can work together without conflict.

Everything should work just fine in VX. Your code should look something like this:
Code:
module RandomStatGains
  Stat_Names = ['hp', 'sp', 'str', 'dex', 'int', 'agi']
  # Stats[actor_id] = {stat_name => n, ...}
  Stats = {}
  # Actor 1 setup
  Stats[1] = {'hp' => 100, 'sp' => 30, 'str' => 5, 'dex' => 4, 'int' => 3, 'agi' => 3}
  # Default actor setup
  Stats.default ={'hp' => 50, 'sp' => 25, 'str' => 3, 'dex' => 3, 'int' => 3, 'agi' => 3}
  def self.random_gain(actor_id, stat_name)
    begin
      return rand(Stats[actor_id][stat_name])
    rescue
      p 'Undefined stat_name: ' + stat_name + ' for actor: ' + actor_id.to_s
    end
  end
end

class Game_Actor
  alias_method :glitchfinder_randstatgains_setup, :setup
  alias_method :glitchfinder_randstatgains_levelu, :level_up
  alias_method :glitchfinder_randstatgains_leveld, :level_down
  alias_method :glitchfinder_randstatgains_hasemaxhp, :base_maxhp
  def setup(actor_id)
    @stat_gains = {}
    for stat in RandomStatGains::Stat_Names
      @stat_gains[stat] = []
    end
    glitchfinder_randstatgains_setup(actor_id)
  end
  def level_up
    # Pass through each stats
    RandomStatGains::Stat_Names.each do |stat_name|
      n = RandomStatGains.random_gain(@actor_id, stat_name)
      @stat_gains[stat_name] << n
    end
    glitchfinder_randstatgains_levelu
  end
  def level_down
    RandomStatGains::Stat_Names.each do |stat_name|
      @stat_gains[stat_name].pop
    end
    glitchfinder_randstatgains_leveld
  end
  def base_maxhp
    # gets original value
    n = glitchfinder_randstatgains_hasemaxhp
    # adds total stat gains
    n += @stat_gains[stat_name].sum
    # return n
    return n
  end
end

class Array
  #---------------------------------------------------------------------------
  # * Name      : Sum
  #   Info      : Sums all values in the array
  #   Author    : Trickster
  #   Call Info : No Arguments
  #---------------------------------------------------------------------------
  def sum
    # Initialize local variable n
    n = 0
    # Sum Up Values in Array
    each {|num| n += num}
    # Return number
    return n
  end
end

I have included everything you need right there. You just need to finish your remaining stats you wish to include. Just make sure you remember to alter your Stat_Names = ['hp', 'sp', 'str', 'dex', 'int', 'agi'] constant. Again, let me know if you need any help.
 
Well, I'm trying the script you gave me, and as soon as I entered the stats I wanted, it started to give me the nil:NilClass error for the sum method you added to the array class. I absolutely hate that error, as it never seems to mean what it actually says. Anyway, heres the modified version of the script you gave me. (Also, I already knew what aliasing was. I just wasn't sure exactly how the hashes functioned. I meant that it seemed like you were eliminating the need for most of the levelup and leveldown functions I had written, and that all you really needed were the changes to the level variable. I looked closer after you posted, and realized I had made some mistakes in my assumptions)

Code:
module RandomStatGains
  Stat_Names = ['hp', 'sp', 'atk', 'defense', 'spi', 'agi']
  # Stats[actor_id] = {stat_name => n, ...}
  Stats = {}
  # Actor 1 setup
  Stats[1] = {
  'hp' => 100, 'sp' => 30, 'atk' => 5, 'defense' => 4, 'spi' => 3, 'agi' => 3}
  # Default actor setup
  Stats.default ={
  'hp' => 50, 'sp' => 25, 'atk' => 3, 'defense' => 3, 'spi' => 3, 'agi' => 3}
  def self.random_gain(actor_id, stat_name)
    begin
      return rand(Stats[actor_id][stat_name])
    rescue
      p 'Undefined stat_name: ' + stat_name + ' for actor: ' + actor_id.to_s
    end
  end
end

class Game_Actor
  alias_method :glitchfinder_randstatgains_setup, :setup
  alias_method :glitchfinder_randstatgains_levelu, :level_up
  alias_method :glitchfinder_randstatgains_leveld, :level_down
  alias_method :glitchfinder_randstatgains_base_maxhp, :base_maxhp
  alias_method :glitchfinder_randstatgains_base_maxmp, :base_maxmp
  alias_method :glitchfinder_randstatgains_base_atk, :base_atk
  alias_method :glitchfinder_randstatgains_base_def, :base_def
  alias_method :glitchfinder_randstatgains_base_spi, :base_spi
  alias_method :glitchfinder_randstatgains_base_agi, :base_agi
  def setup(actor_id)
    @stat_gains = {}
    for stat in RandomStatGains::Stat_Names
      @stat_gains[stat] = []
    end
    glitchfinder_randstatgains_setup(actor_id)
  end
  def level_up
    # Pass through each stats
    RandomStatGains::Stat_Names.each do |stat_name|
      n = RandomStatGains.random_gain(@actor_id, stat_name)
      @stat_gains[stat_name] << n
    end
    glitchfinder_randstatgains_levelu
  end
  def level_down
    RandomStatGains::Stat_Names.each do |stat_name|
      @stat_gains[stat_name].pop
    end
    glitchfinder_randstatgains_leveld
  end
  def base_maxhp
    # gets original value
    n = glitchfinder_randstatgains_base_maxhp
    # adds total stat gains
    n += @stat_gains[hp].sum
    # return n
    return n
  end
  def base_maxmp
    # gets original value
    n = glitchfinder_randstatgains_base_maxmp
    # adds total stat gains
    n += @stat_gains[mp].sum
    # return n
    return n
  end
  def base_atk
    # gets original value
    n = glitchfinder_randstatgains_base_atk
    # adds total stat gains
    n += @stat_gains[atk].sum
    # return n
    return n
  end
  def base_def
    # gets original value
    n = glitchfinder_randstatgains_base_def
    # adds total stat gains
    n += @stat_gains[defense].sum
    # return n
    return n
  end
  def base_spi
    # gets original value
    n = glitchfinder_randstatgains_base_spi
    # adds total stat gains
    n += @stat_gains[spi].sum
    # return n
    return n
  end
  def base_agi
    # gets original value
    n = glitchfinder_randstatgains_base_agi
    # adds total stat gains
    n += @stat_gains[agi].sum
    # return n
    return n
  end
end

class Array
  #---------------------------------------------------------------------------
  # * Name      : Sum
  #   Info      : Sums all values in the array
  #   Author    : Trickster
  #   Call Info : No Arguments
  #---------------------------------------------------------------------------
  def sum
    # Initialize local variable n
    n = 0
    # Sum Up Values in Array
    each {|num| n += num}
    # Return number
    return n
  end
end
 
Got a little slight problem with your modified version. I get an error that says "undefined method: 'sum' for nil class"

Any ideas?
 
psiclone":2logg0t6 said:
Got a little slight problem with your modified version. I get an error that says "undefined method: 'sum' for nil class"

Any ideas?

That's what I was trying to figure out. That error is a catchall for other errors. It has even told me that things like +, -, * and / are undefinded. Once, it even told me that nil was undefined.
 
Cool, thanks! I'll update the first post a little later with the newer version! (as well as a better description)

Edit: I'm trying to make the script take the default stat gain for the current level change (as specified by the game builder in the database), and then use that to modify the stat changes as you've defined them. I was hoping that it could use the following formula:

default_gain + Stats::Radom_Gain - Stats::Random_Gain, where there is no change if the random gain is <= 0, and the change is recorded as 0.

Unfortunately, I'm having quite a bit of trouble figuring out how to make it work in an even partially efficient manner.
 
Not sure what you are asking...

Algebraically speaking... a + b - b = a

And the random gains are from 0 to your random game number you set. So it should never be less than 0, but the 0s will be required when leveling down.
 
Heh, I've found the error about that 'sum'.. at:
Code:
  def base_maxmp
    # gets original value
    n = glitchfinder_randstatgains_base_maxmp
    # adds total stat gains
    n += @stat_gains['mp'].sum
    # return n
    return n
  end

And at the beginning of the code, you've got:

Code:
  Stat_Names = ['hp', 'sp', 'atk', 'defense', 'spi', 'agi']

You don't have 'mp' defined or whatever it is. I changed the 'mp' to 'sp' in the first block, and it works just fine.. to a degree, unless I don't get the random part. It's not really doing the random within the number I specify, it seems to be adding it's own numbers different times. One point level 2 added 1 'hp', then level 3 added 23, then the next time I ran a test level 2 added 14 hp, level 3 added 1.. not sure what to do next, I can't write code to save my life, but I feel I can read it just fine.

I hope that finding that error in the 'mp' section helped you since I can't figure out the rest..

EDIT: Well, I figured out the 'random' part, I just put the random numbers in the wrong section, and it works just fine.

EDIT2: I don't get what 'default actor setup' is.. it doesn't seem to do anything, no matter what number(s) I put in there.

EDIT3: And.. random gains also seems to go backwards, too.. even on a level up. I started with 9 atk, but upon leveling, I had 7..
 
SephirothSpawn":s6xdz1j4 said:
Not sure what you are asking...

Algebraically speaking... a + b - b = a

And the random gains are from 0 to your random game number you set. So it should never be less than 0, but the 0s will be required when leveling down.

Since b is a random number, it is more likely to be a + b - c = d. What I was trying to do is calculate how much the predefined change was for that levelup, and then add that into the formula I just gave you as a. (I would also have an if statement thatr would catch it so that if a stat change would be negative, it is 0 instead)

psiclone":s6xdz1j4 said:
You don't have 'mp' defined or whatever it is. I changed the 'mp' to 'sp' in the first block, and it works just fine.. to a degree, unless I don't get the random part. It's not really doing the random within the number I specify, it seems to be adding it's own numbers different times. One point level 2 added 1 'hp', then level 3 added 23, then the next time I ran a test level 2 added 14 hp, level 3 added 1.. not sure what to do next, I can't write code to save my life, but I feel I can read it just fine.

I hope that finding that error in the 'mp' section helped you since I can't figure out the rest..

EDIT: Well, I figured out the 'random' part, I just put the random numbers in the wrong section, and it works just fine.

EDIT2: I don't get what 'default actor setup' is.. it doesn't seem to do anything, no matter what number(s) I put in there.

EDIT3: And.. random gains also seems to go backwards, too.. even on a level up. I started with 9 atk, but upon leveling, I had 7..

Well, the only code in this thread that functions at any level I like is the one in the first post. If I get these suggestions working, then I will add them into that code. And abbout the random portion, that is what I'm hoping to fix in the update I'm working on.

Edit: I've just updated the script with SephirothSpawn's suggestions, as well as an edit of my own. It should function properly again. It's all in the first post. Alos, SephirothSpawn, I would greatly appreciate your suggestions for the original script, as well. Finally, I'm planning to add a new version for RMXP, that uses the RMXP formulae.
 

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