Encounter Levels
Version: 1.5
Author: modern algebra
Date: July 12, 2008
Description
This script allows the game maker to give monsters levels, and then based on those levels, it determines what enemy troops can be attacked by the player at his current level. That is kind of confusing, so I will try to explain a little better by example. The maker can set up a map with possible enemies being Angels, Cherubims, and Seraphims. You can enter this map at any time, and so you want the encounters to reflect what level the hero party is. You don't want the party attacking Seraphims when they are level 1, because they will be crushed, and you don't want them to fight Angels when they are level 99, because it's too easy. Thus, you just set up in the script what levels the enemies are and an average among each troop is calculated, and with this script you will only be able to fight monster troops that are within level range of your heroes. You can set the level range as well, thus making some maps harder and others easier
Features
- Allows you to set the levels for each enemy in the database
- Only allows the player to fight monster troops within his level range
- Allows you to set what the level range is at any time with a simple call script
- Can be disabled and re-enabled at will
- Easy database configuration
Instructions
See the inside of the script for Instructions. They are located in the header and in the Editable Region at line 58
Script
#==============================================================================
# Encounter Levels Script
# Version: 1.5
# Author: Modern Algebra (rmrk.net)
# Date: February 5, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
#
# To give enemies levels, all that you need to do is go to the Notes box of
# the Enemy in the database and add this code:
#
# \elvl[<level>]
#
# If you do not, then the level defaults to be the same as the enemy's ID.
#
# Then, set up the regular map encounter lists (areas included) with all the
# monsters that you ever want to appear in that area or map.
#
# The system basically works by giving monsters levels and by setting a
# level range within which all encounters must reside. Then, for each troop,
# an average is calculated from all the enemies in the troop. Thus, that
# number acts as the troop level, and the script works by making it so that
# number must be in a certain range of the party's average level for that
# troop to be encountered. By default, this level range is between (Actor's
# Average Level - 5) and (Actor's Average Level + 5). The range can be changed
# at any time to make certain maps harder or easier by using the following
# code in a call script:
#
# $game_system.min_level = x
# $game_system.max_level = y
#
# Where x, y are the values you are changing them to.
# Keep in mind that min level, like max level, is added to the party's average
# level. So, if you set $game_system.min_level = 5, then the minimum level of
# encounters would be party's average level + 5, not party's average level - 5.
#
# You can also turn the levelling feature on and off completely at will, using
# this code:
#
# $game_system.level_boolean = true (to turn it on)
# $game_system.level_boolean = false (to turn it off)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Compatibility:
# It ought to be compatible with any script that does not modify the
# make_encounter_troop_id method of Game_Player (and I can't think of any
# script that would want to besides one like this).
#==============================================================================
# ** RPG::Troop
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# new method - level
#==============================================================================
class RPG::Troop
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Level
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def level
return @level unless @level == nil
avg = 0
@members.each { |mem|
e_data = $data_enemies[mem.enemy_id]
avg += e_data.note[/\\elvl\[(\d+)\]/i] != nil ? $1.to_i : mem.enemy_id
}
@level = avg / @members.size
return @level
end
end
#==============================================================================
# ** Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased method - initialize
# new instance variables - level_boolean, min_level, max_level
#==============================================================================
class Game_System
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Public Instance Variables
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
attr_accessor :level_boolean # Turns on and off the level range function
attr_accessor :min_level # The lower limit of the encounter range
attr_accessor :max_level # The upper limit of the encounter range
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Object Initialization
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias ma_initialize_levels_regions initialize
def initialize
ma_initialize_levels_regions
@min_level = -5
@max_level = 5
@level_boolean = true
end
end
#==============================================================================
# ** Game_Player
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# overwritten methods - make_encounter_troop_id
#==============================================================================
class Game_Player
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Make Encounter Troop ID
# Returns the troop to be encountered
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def make_encounter_troop_id
encounter_list = $game_map.encounter_list.clone
# Add area encounters to the list
$data_areas.values.each {|i| encounter_list += i.encounter_list if in_area?(i)}
# If level feature active
if $game_system.level_boolean
encounters = []
# Calculate Party Level Average
average_level = 0
$game_party.members.each {|i| average_level += i.level}
average_level /= $game_party.members.size
# Set Range
min = [average_level + $game_system.min_level,1].max
max = [average_level + $game_system.max_level,99].min
unless min > max
# Test average agains all troops in the list
encounter_list.each {|i|
# Add to the returning array If troop level within range
encounters.push (i) if $data_troops[i].level.between? (min, max)
}
end
else
# Return the full encounter list
encounters = encounter_list
end
# If there are no encounters
if encounters.empty?
make_encounter_count
return 0
end
return encounters[rand(encounters.size)]
end
end
Credit
Support
I will fix any bugs that arise and make it compatible with other scripts if any compatibility issues arise. Post in this topic at rmrk for the swiftest response.
Known Compatibility Issues
It ought to be compatible with any script that does not modify the make_encounter_troop_id method of Game_Player (and I can't think of any script that would want to besides one like this).
Author's Notes
Based off the original script I wrote for XP. If you are wondering why it does not retain the Encounter Areas portion of my XP script, that is because areas are a built-in function to VX
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.