RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[VXA] Random Encounters by Level

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Random Encounters by Level
Version: 1.0.0
Author: modern algebra
Date: 22 September 2012

Version History


  • <Version 1.0> 2012.09.22 - Original Release

Description


This script allows you to assign levels to enemies and have it so that enemy will only be randomly encountered when the player's level is within some range of that enemy's level. You can set the level range by map.

That might be confusing, so I will try to explain a little better by example. You 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 random 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 with this script you will only fight monster troops that are within level range of your heroes. You can set what that level range is as well, thus making some maps harder and others easier.

Features

  • Allows you to assign levels to every enemy in the database
  • The player is restricted to randomly encountering only enemies within his or her level range
  • Allows you to set the level range by map or in an event by script command
  • Can be disabled and re-enabled at will
  • Simple database configuration

Instructions

Paste the script into its own slot in the Script Editor, above Main but below Materials. For further instructions on configuration, see the header of the script.

Script


Code: [Select]
#==============================================================================
#    Random Encounters by Level
#    Version: 1.0.0
#    Author: modern algebra (rmrk.net)
#    Date: 22 September, 2012
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Description:
#   
#    This script allows you to assign levels to enemies and have it so that
#   enemy will only be randomly encountered when the player's level is within
#   some range of that enemy's level. You can set the level range by map.
#
#    That might be confusing, so I will try to explain a little better by
#   example. You 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
#   random 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 with this script you will only fight monster troops that are within
#   level range of your heroes. You can set what that level range is as well,
#   thus making some maps harder and others easier.
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Instructions:
#   
#    Paste this script into its own slot in the Script Editor, above Main but
#   below Materials.
#
#    To set the level of an enemy, all you need to do is place the following
#   code in its notebox:
#
#      \elvl[x]
#       
#   Replace the x with the level you want to assign to the enemy. As an example
#   if you wanted to set an enemy's level to 7, you would use the following
#   code:
#
#      \elvl[7]
#
#   If you do not give an enemy a level, then it will be encounterable at any
#   level. The level of any given troop is the average level of all its members.
#
#    By default, your party will only encounter troops that are within 5 levels
#   of your party. In other words, if the average level of your party is 7, you
#   will encounter troops with levels between 2 and 12. You can change the
#   level range in two ways.
#
#    Firstly, you can change it by map by placing the following code in the
#   notebox of a map:
#
#      \elvl[x, y]
#
#   Replace x and y with the minimum and maximum level difference. So, if you
#   have something like:
#
#      \elvl[-2, 8]
#
#   Then the parties will encounter enemy troops that are between 2 levels
#   below the party and 8 levels above the party. Alternately, if you did this:
#
#      \elvl[v1, v2]
#
#   Then it would set the minimum level to the value of variable 1 and the
#   maximum level to the value of variable 2.
#
#    Secondly, you can change the level range by placing the following code in
#   a Script event command:
#
#      set_encounter_level_range(x, y)
#
#   where, again, you replace x and y with the minimum and maximum level
#   diference.
#
#    You can turn this script off and on completely with the following code:
#
#      $game_map.marel_on = false    # <- OFF
#      $game_map.marel_on = true     # <- ON
#==============================================================================

$imported ||= {}
$imported[:MA_RandomEncounterByLevel] = true

#==============================================================================
# *** RPG
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    modified classes - Enemy; Troop; Map::Encounter
#==============================================================================

module RPG

#==============================================================================
# ** RPG::Enemy
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - marel_level
#==============================================================================

class Enemy
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Level
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def marel_level
    unless @marel_level
      @marel_level = note[/\\E[ _]?LE?VE?L\[\s*(\d+)\s*\]/i] ? $1.to_i : 0
    end
    @marel_level
  end
end

#==============================================================================
# ** RPG::Troop
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - marel_level
#==============================================================================

class Troop
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Level
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def marel_level
    unless @marel_level
      enemies = members.collect { |en| $data_enemies[en.enemy_id] }.compact
      total = enemies.inject(0) { |sum, en| sum + en.marel_level }
      size = enemies.select { |en| en.marel_level != 0 }.size
      @marel_level = size == 0 ? 0 : (total.to_f / size).ceil
    end
    @marel_level
  end
end

#==============================================================================
# ** RPG::Map::Encounter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - marel_level
#==============================================================================

class Map::Encounter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Level
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def marel_level
    return $data_troops[troop_id].marel_level if $data_troops && $data_troops[troop_id]
    return 0
  end
end

end

#==============================================================================
# ** Game_Map
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new attr_accessor - marel_min_level; marel_max_level; marel_on
#    aliased method - initialize; setup
#    new method -marel_encounter_range
#==============================================================================

class Game_Map
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Public Instance Variables
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  attr_accessor :marel_min_level
  attr_accessor :marel_max_level
  attr_accessor :marel_on
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Object Initialization
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias marel_initz_5ha6 initialize
  def initialize(*args, &block)
    @marel_on = true
    @marel_min_level = -5
    @marel_max_level = 5
    marel_initz_5ha6(*args, &block) # Call Original Method
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Setup
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias marel_setup_4bt7 setup
  def setup(*args, &block)
    marel_setup_4bt7(*args, &block) # Call Original Method
    if @map.note[/\\E[ _]?LE?VE?L\[\s*(V?)(-?\d+)[\s;,:]*(V?)(-?\d+)\s*\]/i]
      min = $1.empty? ? $2.to_i : $game_variables[$2.to_i.abs]
      max = $3.empty? ? $4.to_i : $game_variables[$4.to_i.abs]
      @marel_min_level, @marel_max_level = *[min, max].sort
    end
  end
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Marel Encounter Level Range
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def marel_encounter_level_range
    party = $game_party.battle_members
    avg = party.empty? ? 0 :
      (party.inject(0) { |sum, mem| sum + mem.level }) / party.size
    (avg + marel_min_level)..(avg + marel_max_level)
  end
end

#==============================================================================
# ** Game_Player
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    aliased method - encounter_ok?
#==============================================================================

class Game_Player
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Check if can encounter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  alias marel_enctrok_2cf9 encounter_ok?
  def encounter_ok?(encounter, *args, &block)
    return false if $game_map.marel_on && !(encounter.marel_level == 0 ||
      ($game_map.marel_encounter_level_range === encounter.marel_level))
    marel_enctrok_2cf9(encounter, *args, &block) # Call Original Method
  end
end

#==============================================================================
# ** Game_Interpreter
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#  Summary of Changes:
#    new method - set_encounter_level_range
#==============================================================================

class Game_Interpreter
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  # * Set Encounter Level Range
  #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  def set_encounter_level_range(min, max)
    $game_map.marel_min_level, $game_map.marel_max_level = *[min, max].sort
  end
end

Credit


  • modern algebra

Support


Please post in this topic at RMRK if you have any questions, suggestions, or error reports.

Terms of Use


I adopt RMRK's default Terms of Use.
« Last Edit: January 31, 2013, 09:47:43 PM by modern algebra »

***
Rep:
Level 77
RMRK Junior
I assume this could be doubled up with Yanfly's Enemy Levels somehow? You could make the enemies "evolve" then.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Yes, they very likely would work together, but I'm not sure what you mean by evolve. I assume that Yanfly's Enemy Levels script will make any enemy the same level as the party. To the extent that this Random Encounters by Level script is used, you could make it so that you stop fighting that particular enemy after the party reaches whatever level you specify, even though the enemy would otherwise always be the same level as the party.
« Last Edit: September 22, 2012, 01:32:26 PM by modern algebra »

**
Rep:
Level 65
Actually this is way easier to balance than Yanfly enemy levels. I'll try this out, thanks MA!