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.

Enemy Auto-Leveling [v 1.0]

This script modifies enemy stats based on game party's average level, so your enemies will always be a better matched challenge as you level up your actors. I wrote this, quite simply, as more of an exercize than a true script, but it works great so you can feel free to use it.

For games that have alot of intentionally weak enemies, you might want to find another script, because this one ensures your enemies are always somewhat challenging no matter what level you are (I hate one-hitter quitter enemies, they're a waste of time.)

This script doesn't have anything fancy, like additional enemy drops or public defined enemy stat modifiers, but I might add them later... however, you can look up Seph's Test Bed, because he's got a great script with all those extra features already, but I might try to write my own version later on if I get bored.

Code:
#===============================================================================
# ~* Enemy Auto-Leveling Script *~
#-------------------------------------------------------------------------------
# Written by  : Kain Nobel
# Version     : 1.0
# Last Update : 5/9/2008
# Created     : 5/8/2008
#===============================================================================
# Special Thanks to Arbiter and khmp for their knowledge and help.
#===============================================================================
# * Game_Enemy (Aliased)
#===============================================================================
class Game_Enemy < Game_Battler
  # Alias Method for Base Stats
  alias_method :kn_game_enemy_base_maxhp, :base_maxhp
  alias_method :kn_game_enemy_base_maxsp, :base_maxsp
  alias_method :kn_game_enemy_base_str, :base_str
  alias_method :kn_game_enemy_base_dex, :base_dex
  alias_method :kn_game_enemy_base_agi, :base_agi
  alias_method :kn_game_enemy_base_int, :base_int
  alias_method :kn_game_enemy_base_atk, :base_atk
  alias_method :kn_game_enemy_base_pdef, :base_pdef
  alias_method :kn_game_enemy_base_mdef, :base_mdef
  alias_method :kn_game_enemy_base_eva, :base_eva
  # Alias Method for Gold, Exp and Drops
  alias_method :kn_game_enemy_exp, :exp
  alias_method :kn_game_enemy_gold, :gold
  #------------------------
  # * Initialization Method
  #------------------------
  #def initialize(troop_id, member_index) #<--Included in origional method.
    #kn_game_enemy_initialize
    #
  #end
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     troop_id     : troop ID
  #     member_index : troop member index
  #--------------------------------------------------------------------------
  def initialize(troop_id, member_index)
    super()
    # Super's variables
    @troop_id = troop_id
    @member_index = member_index
    # Troop Data
    troop = $data_troops[@troop_id]
    @enemy_id = troop.members[@member_index].enemy_id
    enemy = $data_enemies[@enemy_id]
    # KN: Added average_level to initialize
    @avg_level = average_level
    @battler_name = enemy.battler_name
    @battler_hue = enemy.battler_hue
    @hp = maxhp
    @sp = maxsp
    @hidden = troop.members[@member_index].hidden
    @immortal = troop.members[@member_index].immortal
  end
  #---------------------------------
  # * Get Game_Party's Average Level
  #---------------------------------
  def average_level
    avg = 0
    $game_party.actors.each {|actor| avg += actor.level }
    return avg / $game_party.actors.size 
  end
  #-----------------------
  # * Define Average MaxHP
  #-----------------------
  def base_maxhp
    return kn_game_enemy_base_maxhp + (100 * @avg_level).to_i
  end
  #-----------------------
  # * Define Average MaxSP
  #-----------------------
  def base_maxsp
    return kn_game_enemy_base_maxsp + (10 * @avg_level).to_i
  end
  #-----------------------
  # * Define Average Str
  #-----------------------
  def base_str
    return kn_game_enemy_base_str + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average Dex
  #---------------------
  def base_dex
    return kn_game_enemy_base_dex + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average Agi
  #---------------------
  def base_agi
    return kn_game_enemy_base_agi + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average Int
  #---------------------
  def base_int
    return kn_game_enemy_base_int + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average Atk
  #---------------------
  def base_atk
    return kn_game_enemy_base_atk + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average PDef
  #---------------------
  def base_pdef
    return kn_game_enemy_base_pdef + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average MDef
  #---------------------
  def base_mdef
    return kn_game_enemy_base_mdef + (1 * @avg_level).to_i
  end
  #---------------------
  # * Define Average Eva
  #---------------------
  def base_eva
    return kn_game_enemy_base_eva + (1 * @avg_level).to_i
  end
  #------------------
  # * Def Average Exp
  #------------------
  def exp
    return kn_game_enemy_exp + (1 * @avg_level).to_i
  end
  #-------------------
  # * Def Average Gold
  #-------------------
  def gold
    return kn_game_enemy_gold + (1 * @avg_level).to_i
  end
end
 
You know, if you wrote this for VX, you'd might get more responses, although I'm unsure. It sounds like a good idea, although could you make it so that if any monster with [Boss] (for example) in it's name isn't altered?

Other than that, I think this is a pretty good script, good job! =)
-Krobe
 
How exactly does it work? Are the stats modified by their database stats, so a common slime or something isn't equal to a dragon/demon/boss?
 
This script would be great, if you're only using the default stats in the database. For example, I lowered all the stats for my heroes and enemies so they start lower (level 1 is 100 HP, etc). I tested it with a single monster at multiple levels is that although the HP manages itself nicely, the enemy's stats get far too high. I took a hero with base stats around 20-25 for STR, AGI, etc, etc and a monster with base stats between 17 and 20. In the early levels it worked great, the player and the monster were evenly matched. But I noticed right around the higher levels the monsters were getting too strong/fast to even hit. So, looking at the code, specifically the average lines:

#-----------------------
  # * Define Average Str
  #-----------------------
  def base_str
    return kn_game_enemy_base_str + (1 * @avg_level).to_i
  end


That would mean at level 40, when my hero has a base STR of about 45, that monster with base STR 17 at level 1 now has a STR of 57, far higher than the player. At level 50 my hero has a base STR of 53, and the monster would be 67.  Eventually the AGI got so high I couldn't even hit anything.

Do you think there is any way to alter the script so that instead of adding the average level to it, it can take the hero's current stat and add 2 or 3 points to it? For example:

At level 50, instead of the formula being Enemy Base + 50, the value becomes Hero STR + 3?
 
I've been looking for something like this for a long time, and I didn't really understand how to use SephirothSpawn's Dynamic Enemies. My project's stats are like Aeiras's, so if you could address this it would be spectacular.
 
tofurkey":315a7t01 said:
I've been looking for something like this for a long time, and I didn't really understand how to use SephirothSpawn's Dynamic Enemies. My project's stats are like Aeiras's, so if you could address this it would be spectacular.

I did some messing around and I might have it. If you change
Code:
return kn_game_enemy_base_str + (1 * @avg_level).to_i

to

Code:
return kn_game_enemy_base_str + (@avg_level / 2).to_i

Then you should get a situation where (using my level 50 scenario) the monster would then have a STR of 17+25 = 42 which is around what my hero had, making it a perfectly even match. I'm testing it out right now, try it on yours and see how that works.

UPDATE: It's working fine for me now with that method, guess I should have tried to fix it myself before asking in a topic ^^; But anyway, if you just change the (1* @avg_level) lines to (@avg_level / 2) it will work ok, I changed some of my numbers to make a basic enemy still beatable.

Note: The higher the number you divide @avg_level by, the lower the end result you'll get. Just play around and see what works for you tofu.
 
Yes, This that i was looking for, thanks you so much for sharing this neat script to us. It's really "Challanging" when you used this with FMBS by xrxs battle system
 
This script is amazing, you did a good job on it, now my game is more challenging and you don't one-hit everything...
Anyway, good job!  :thumb:
 

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