Glitchfinder
Staff
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.