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.

Random stat gains on level up

As the title suggests, I'd like to have a system that would allow for random stat gains (customizable by me in the script) on level up. It would need to be customizable for each individual actor, with no limit to the number of actors it can have.

I have tried searching for this kind of script, and I have not found one resulting in my search criteria. So if one exists, I apologize in advance.
 
What you are trying to do is to create a script that increases the player's permanent stats when they level up, only a little more randomly? To be more specific, are you looking for one where when an actor levels up, they might be, say, 15 below to 15 above the prespecified number they would have for that level? In other words, if Actor 1 (Aluxes) levels up from level 12 to level 13, and he is supposed to now have 123 AGI, he might actually have anywhere from 108 to 138 AGI? And if you want Actor 2, Basil, to have from 5 above to 15 below, then when he levels from 3 to 4, he could have anywhere from 27 to 47 INT? (This is only based on the default stats, btw)

EDIT: Is this RMXP, or RMVX?
 
Yeah, I am using VX.

To answer your other question, I want the stats to be more random on leveling. So like, let's say that Ralph is level 1, and he levels to 2, his gains could be between 1-5 for hp, 0-3 for mp.. etc for the other stats, but those random numbers I want to be able to specify to anything in the script.

Thanks for replying.
 
OK, I have your script. I think it was kind of fun to make, but that may just be me. Inscructions are included below.

Code:
#==============================================================================
# ** Glitchfinder's Randomized Stats on Level Up (Alternate)
#------------------------------------------------------------------------------
#  This script is meant to help randomize an actor's stats upon
# levelling up.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * 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 Mana, entry 3 is Attack, entry
#   4 isDefense, 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 Stat_Change_Variance and the
# Min_Stat_Change arrays in the Stats module, using the rules above
# as well as the following rules:
#
#    The value in each entry in the Min_Stat_Change array is the
#   minimum amount that a stat may change.
#
#    The value in each entry in the Stat_Change_Variance array is
#   the maximum that the new stat may exceed the minimum change by.
#   
#    To find the maximum amount that a specific stat may change on
#   levelling up or down, simply add the stat's value in the
#   Stat_Change_Variance array to the stat's value in the
#   Min_Stat_Change array.
#
#  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
# scrips, and vice-versa if you delete actors.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * Advice
#  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
#  Do not make the values in the Min_Stat_Change or the
# Min_Stat_Change arrays too high. This can result in a game
# becoming too easy for the player, due to stats that are too high.
# For most stats, 0, 1, or 2 should be more than enough for a
# minimum, and 3 should be the highest variance. (Although HP
# should be significantly higher.
#
#  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.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# * Usage
#  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
#  This script may be used in any commercial or non-commercial
# project.
#
#  Please credit Glitchfinder if you use this script.
#==============================================================================

#==============================================================================
# ** Stats
#------------------------------------------------------------------------------
#  This module handles actors' stats and their changes. Its used
# within the Game_Actor class.
#==============================================================================

module Stats
  #--------------------------------------------------------------------------
  # * Store Actor Stats
  #--------------------------------------------------------------------------
  Actor_Stats = [
    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
  ]
  #--------------------------------------------------------------------------
  # * Store Actor Stat Change Variance
  #--------------------------------------------------------------------------
  Stat_Change_Variance = [
    18, 7, 6, 6, 8, 9,
    17, 6, 4, 4, 6, 4,
    13, 6, 4, 6, 5, 5,
    14, 9, 5, 4, 6, 6,
    15, 7, 4, 4, 4, 8,
    16, 5, 6, 3, 6, 9,
    18, 5, 6, 4, 8, 7,
    13, 7, 4, 4, 6, 8
  ]
  #--------------------------------------------------------------------------
  # * Store Actor Stat Change Minimums
  #--------------------------------------------------------------------------
  Min_Stat_Change = [
    60, 8, 0, 0, 1, 1,
    75, 5, 0, 0, 0, 0,
    33, 6, 0, 0, 0, 0,
    37, 6, 0, 0, 0, 0,
    40, 4, 0, 0, 0, 1,
    48, 3, 0, 0, 0, 1,
    80, 3, 0, 0, 1, 0,
    24, 4, 0, 0, 0, 1
  ]
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
  #--------------------------------------------------------------------------
  # * Get Basic Maximum HP
  #--------------------------------------------------------------------------
  def base_maxhp
    n = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 2)
    return Stats::Actor_Stats[n.to_i].to_i
  end
  #--------------------------------------------------------------------------
  # * Get basic Maximum MP
  #--------------------------------------------------------------------------
  def base_maxmp
    n = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 1)
    return Stats::Actor_Stats[n.to_i].to_i
  end
  #--------------------------------------------------------------------------
  # * Get Basic Attack
  #--------------------------------------------------------------------------
  def base_atk
    n = (4 * @actor_id) + (2 * (@actor_id - 2))
    n = Stats::Actor_Stats[n.to_i].to_i
    for item in equips.compact do n += item.atk end
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Basic Defense
  #--------------------------------------------------------------------------
  def base_def
    n = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 1)
    n = Stats::Actor_Stats[n.to_i].to_i
    for item in equips.compact do n += item.def end
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Basic Spirit
  #--------------------------------------------------------------------------
  def base_spi
    n = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 2)
    n = Stats::Actor_Stats[n.to_i].to_i
    for item in equips.compact do n += item.spi end
    return n
  end
  #--------------------------------------------------------------------------
  # * Get Basic Agility
  #--------------------------------------------------------------------------
  def base_agi
    n = (4 * @actor_id) + ((2 * (@actor_id - 2)) + 3)
    n = Stats::Actor_Stats[n.to_i].to_i
    for item in equips.compact do n += item.agi end
    return n
  end
  #--------------------------------------------------------------------------
  # * Level Up
  #--------------------------------------------------------------------------
  def level_up
    @level += 1
    actor_locator = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 2)
    new_hp = rand(Stats::Stat_Change_Variance[actor_locator].to_i)
    new_hp = new_hp + Stats::Min_Stat_Change[actor_locator].to_i
    new_hp = new_hp + Stats::Actor_Stats[actor_locator].to_i
    Stats::Actor_Stats[actor_locator] = new_hp
    new_mp = rand(Stats::Stat_Change_Variance[actor_locator + 1].to_i)
    new_mp = new_mp + Stats::Min_Stat_Change[actor_locator + 1].to_i
    new_mp = new_mp + Stats::Actor_Stats[actor_locator + 1].to_i
    Stats::Actor_Stats[actor_locator + 1] = new_mp
    new_attack = rand(Stats::Stat_Change_Variance[actor_locator + 2].to_i)
    new_attack = new_attack + Stats::Min_Stat_Change[actor_locator + 2].to_i
    new_attack = new_attack + Stats::Actor_Stats[actor_locator + 2].to_i
    Stats::Actor_Stats[actor_locator + 2] = new_attack
    new_defense = rand(Stats::Stat_Change_Variance[actor_locator + 3].to_i)
    new_defense = new_defense + Stats::Min_Stat_Change[actor_locator + 3].to_i
    new_defense = new_defense + Stats::Actor_Stats[actor_locator + 3].to_i
    Stats::Actor_Stats[actor_locator + 3] = new_defense
    new_spirit = rand(Stats::Stat_Change_Variance[actor_locator + 4].to_i)
    new_spirit = new_spirit + Stats::Min_Stat_Change[actor_locator + 4].to_i
    new_spirit = new_spirit + Stats::Actor_Stats[actor_locator + 4].to_i
    Stats::Actor_Stats[actor_locator + 4] = new_spirit
    new_agility = rand(Stats::Stat_Change_Variance[actor_locator + 5].to_i)
    new_agility = new_agility + Stats::Min_Stat_Change[actor_locator + 5].to_i
    new_agility = new_agility + Stats::Actor_Stats[actor_locator + 5].to_i
    Stats::Actor_Stats[actor_locator + 5] = new_agility
    for learning in self.class.learnings
      learn_skill(learning.skill_id) if learning.level == @level
    end
  end
  #--------------------------------------------------------------------------
  # * Level Down
  #--------------------------------------------------------------------------
  def level_down
    @level -= 1
    actor_locator = (4 * @actor_id) + ((2 * (@actor_id - 2)) - 2)
    new_hp = rand(Stats::Stat_Change_Variance[actor_locator].to_i)
    new_hp = new_hp + Stats::Min_Stat_Change[actor_locator].to_i
    new_hp = Stats::Actor_Stats[actor_locator].to_i - new_hp
    Stats::Actor_Stats[actor_locator] = new_hp
    new_mp = rand(Stats::Stat_Change_Variance[actor_locator + 1].to_i)
    new_mp = new_mp + Stats::Min_Stat_Change[actor_locator + 1].to_i
    new_mp = Stats::Actor_Stats[actor_locator + 1].to_i - new_mp
    Stats::Actor_Stats[actor_locator + 1] = new_mp
    new_attack = rand(Stats::Stat_Change_Variance[actor_locator + 2].to_i)
    new_attack = new_attack + Stats::Min_Stat_Change[actor_locator + 2].to_i
    new_attack = Stats::Actor_Stats[actor_locator + 2].to_i - new_attack
    Stats::Actor_Stats[actor_locator + 2] = new_attack
    new_defense = rand(Stats::Stat_Change_Variance[actor_locator + 3].to_i)
    new_defense = new_defense + Stats::Min_Stat_Change[actor_locator + 3].to_i
    new_defense = Stats::Actor_Stats[actor_locator + 3].to_i - new_defense
    Stats::Actor_Stats[actor_locator + 3] = new_defense
    new_spirit = rand(Stats::Stat_Change_Variance[actor_locator + 4].to_i)
    new_spirit = new_spirit + Stats::Min_Stat_Change[actor_locator + 4].to_i
    new_spirit = Stats::Actor_Stats[actor_locator + 4].to_i - new_spirit
    Stats::Actor_Stats[actor_locator + 4] = new_spirit
    new_agility = rand(Stats::Stat_Change_Variance[actor_locator + 5].to_i)
    new_agility = new_agility + Stats::Min_Stat_Change[actor_locator + 5].to_i
    new_agility = Stats::Actor_Stats[actor_locator + 5].to_i - new_agility
    Stats::Actor_Stats[actor_locator + 5] = new_agility
  end
end


First, copy this to where the program says to put custom scripts, or "Materials".

The instructions are really quite simple. The only things you edit are the first three arrays at the top. They are formatted like this:

  Array_Name = [
    Actor_1_HP, Actor_1_MP, Actor_1_Attack, Actor_1_Defense, Actor_1_Spirit, Actor_1_Agility,
    Actor_2_HP, Actor_2_MP, Actor_2_Attack, Actor_2_Defense, Actor_2_Spirit, Actor_2_Agility
  ]

In the first array (Actor_Stats), you put their actual stat for starting at level 1.
In the second array (Max_Stat_Gains), you put mow much the stat's addition can vary. (it will vary between 0 and 1 below that number)
In the third array (Min_Stat_Gains), you put the minimum increase for each stat.

To find the maximum increase for each stat, take the stat in the second array (Max_Stat_Gains), subtract 1 from it, and then add it to the stat in the third array. (Min_Stat_Gains). For example, to find the maximum increase for Actor 1's MP, you take 7, subtract 1, and add the result to 8, giving you a total of 14.

I have added a semblance of the stats for the default actors, as an example. Also, just so you know, this script does not support stat curves. That would require some serious modification.

Finally, if you add your own actors, you must add their own line to each of the arrays, and if subtract them, their lines must be removed from the arrays. The lines are in the same actor order as the Actors database. Remember, if you delete an actor, you must delete their line, otherwise the next actor now has the stats of the one you just deleted. (So, idf you delete Oscar in the database, but not his lines in the script, Vera now has Oscar's stats and Elmer now has Vera's)

Finally, if you do modify the number of actors, always remember that every stat value must have a comma after it. The only exception is the last actor's Agility values.
 
Oh my god. That works freaking amazingly, I was hoping it would be this simple. This is phenomenal, I love it. Thanks so much.


EDIT: I take that back, it worked great for when I was doing 1 digit (0-9) stat increases, but when I changed it to double digit (10+) stat increases, it 1) stopped being random, and 2) didn't increase the stats anymore after level 3.

I think you might need to explain to me a little more what you mean by the whole figuring the max gains.. I'm not sure what I'm supposed to do with that '14' that you came up with in your example..
 
psiclone":31d4fzi6 said:
Oh my god. That works freaking amazingly, I was hoping it would be this simple. This is phenomenal, I love it. Thanks so much.

You're welcome. I liked the script enough that I posted a tweaked version on the main script board. I think I'll post a link to this thread there, because there are several differences between the two scripts at this point.

Also, you might want to copy the newest version in my post. (in this thread). I removed a completely unnecessary bit of script, and so it actually will work a little better. I might update it again later with commented insctructions.
 
Ok, well nevermind. I found the problem was in a level-up display script I was using. Somehow it was conflicting with the gains. It works just fine, there never was a problem in the first place.

Again, thanks.
 
psiclone":1lv7w4s3 said:
Ok, well nevermind. I found the problem was in a level-up display script I was using. Somehow it was conflicting with the gains. It works just fine, there never was a problem in the first place.

Again, thanks.

Actually, it might have been editing one of the methods that I edited. Probably the level up method toward the bottom of the script.
 
psiclone":2ebnzmsb said:
Yeah, I tried to combine the two, but I couldn't figure it out, heh. I just got rid of that level-up display. I'd SO much rather have this script than that display.

Why not post that script? I might be able to merge them...

Also, I just edited the script again, so that it is more efficient, and so that it has detailed instructions included in the header.
 

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