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.
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 Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
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


Code: [Select]
#==============================================================================
# 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


  • modern algebra

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 :P


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
« Last Edit: February 11, 2010, 09:55:18 PM by Modern Algebra »

*
Rep:
Level 102
2014 Biggest Narcissist Award2014 Biggest Forum Potato2014 Best Non-RM Creator2013 Best Game Creator (Non-RM)2013 Best IRC ChatterboxParticipant - GIAW 112012 Most Successful Troll2012 Funniest Member2012 Best Use Of Avatar and Signature space2012 Best IRC ChatterboxSecret Santa 2012 ParticipantProject of the Month winner for November 2009For being a noted contributor to the RMRK Wiki2010 Most Successful Troll2010 Biggest Forum Couch Potato2010 Best IRC Chatterbox
Great script! Sounds very useful.

*
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 Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
UPDATE::

Easier in-database configuration and enemy-specific levels

Now, just set this code in the Notes Field of an Enemy in the database:

\ELVL[level]

********
Shadow Knight
Rep:
Level 91
Ruin that brick wall!
Project of the Month winner for October 2008
This script is important for a long game.
Nice one! ;8
Be kind, everyone you meet is fighting a hard battle.

*
Rep: +0/-0Level 72
RMRK Junior
ur script is awesome :) but i have trouble copying the script.u see,when i copy and paste they appear in one line.every leeters in one line.can u help me pls?its urgent  :'( Thanks  ;)

***
Rep:
Level 82
IT ALL ENDED.
ur script is awesome :) but i have trouble copying the script.u see,when i copy and paste they appear in one line.every leeters in one line.can u help me pls?its urgent  :'( Thanks  ;)
DUDE, you just posted on a topic 2 years old!

*
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 Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
It doesn't matter that the topic is old, since it is a resource topic. It's far better to have it asked and answered here than in some new topic. Necroing is only bad when it makes sense for it to be bad.

Anyway, the problem is your browser. You are using IE. For some reason, code boxes do not copy correctly when using IE and you will need to use some other browser like Chrome or Firefox. In case you don't have access to another, I have attached a copy of the script as a .txt document.

****
Rep:
Level 69
What's the scope of this, can u set it like \ELVL[1-99]  for if you always want to fight a mob (in note) or do u put the call script on a parallel process with min and max mob lvl as an event with it?

*
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 Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
No, you'd have to either turn the feature off by changing $game_system.level_boolean to false or else change the level range by altering the values of $game_system.min_level and $game_system.max_level.

There is currently no way to make some enemies encounterable regardless of level.

****
Rep:
Level 69
Sorry I figured it out, what I was trying to do earlier was set a mob so it would always show up because when I started using the script I set the lvls and it wasn't working but it is now. I don't know what i messed up it's good now xD