+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: Expanded Encounter Areas (/thread-8102.html)
Expanded Encounter Areas - DerVVulfman - 07-19-2020
Expanded Encounter Areas
Version: 1.1
Introduction
This script allows the game developer to designate areas within one or more field maps to have designated areas where additional enemy troops may be encountered by way of random encounters.
It allows for a change of the number of steps required to trigger any such random encounters and is compatible with Big Maps by DerVVulfman.
#==============================================================================
# ** Expanded Encounter Areas
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.1
# 02-07-2025 (MM-DD-YYYY)
# RGSS / RMXP
#
#==============================================================================
#
# INTRODUCTION:
#
# This script allows the game developer to designate areas within one or more
# field maps to have designated areas where additional enemy troops may be
# encountered by way of random encounters.
#
# It allows for a change of the number of steps required to trigger any such
# random encounters and is compatible with Big Maps by DerVVulfman.
#
#------------------------------------------------------------------------------
#
# Each defined AREA hash must have a unique key. If two or more AREA hashes
# have the same key, the last one will take prescedent.
#
# If there are two individual AREAs defined for the same map, and the areas
# overlap, the overlapped area will have the contents of both.
#
# Each AREA hash is given a four-parameter array. This four-parameter array
# holds the following data: map(s), rectangle area, steps, and troops.
#
# * Maps: An array holding the map (or maps) in which this works. You may
# have two identical maps that can use this same area. Or it is a
# vital requirement to list all maps in question if it is part of
# a Big Maps array.
#
# * Area: This is the area of the map: (Start X, Start Y, End X, End Y).
# If a Big Map, please remember to accommodate the coordinates
# for additional map widths and heights.
#
# * Steps: This is the change of steps required. Must be 1 or greater.
#
# * Troops: This is an array holding a list of troops by their ID.
#
#
#==============================================================================
#
# COMPATABILITY:
#
# Designed solely for RPGMaker XP.
#
# This system attaches code to the 'encounter_list' and 'encounter_steps'
# methods within Game_Map.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS
#
# Free for use, even in commercial projects. Only due credit is required.
#
#
#==============================================================================
module EncArea
# Creates the Area hash. Do not remove. -----------------------------------
AREA = {} # Do not touch ---------------------------------------------------
# --------------------------------------------------------------------------
# DEBUG SHOW
# ==========
# If true, it brings up the updated encounter list and the number of steps
# before an encoutner occurs.
#
DEBUG_SHOW = true
# DEFINED AREAS
# =============
# If true, it brings up the updated encounter list and the number of steps
# before an encounter occurs. Rectangle Areas are not x,y,width,height but
# are start x/y to end x/y tiles on the map (top-left is 1,1).
#
# AREA Map(s) Rectangle Area St Troops
# ======= ===== =============== === ========
AREA[1] = [ [1], [ 4, 4, 14, 11], 10, [12,13,14] ]
AREA[2] = [ [1], [ 12, 10,18, 14] ]
end
#==============================================================================
# ** Game_Map
#------------------------------------------------------------------------------
# This class handles the map. It includes scrolling and passable determining
# functions. Refer to "$game_map" for the instance of this class.
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias dervv_map_eea_encounter_list encounter_list
alias dervv_map_eea_encounter_step encounter_step
#--------------------------------------------------------------------------
# * Get Encounter List
#--------------------------------------------------------------------------
def encounter_list
#
data = dervv_map_eea_encounter_list # Perform the original method
data = eea_encounter_list_update(data) # Update encounter list
return data # Return updated list
#
end
#--------------------------------------------------------------------------
# * Get Encounter Steps
#--------------------------------------------------------------------------
def encounter_step
#
data = dervv_map_eea_encounter_step # Perform the original method
data = eea_encounter_steps_update(data) # Update encounter step
return data # Return updated list
#
end
#--------------------------------------------------------------------------
# * Attached Methods - Direct link to Aliased Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Get Encounter List Updated
# data : encounter list
#--------------------------------------------------------------------------
def eea_encounter_list_update(data)
#
data += expanded_encounter_troops # Add any new troops if defined
#
if $DEBUG && EncArea::DEBUG_SHOW == true # If showing the area in debug
p data # Show the current list
end
#
return data # Return new contents
#
end
#--------------------------------------------------------------------------
# * Get Encounter Step Updated
# data : encounter step
#--------------------------------------------------------------------------
def eea_encounter_steps_update(data)
#
new_data = expanded_encounter_steps # Acquire in change in steps
data = new_data if new_data >= 1 # Update if change is valid
#
if $DEBUG && EncArea::DEBUG_SHOW == true # Ifshowing the area in debug
p "Steps Changed to: " + data.to_s # Show the current step change
end
#
return data # Return new steps
#
end
#--------------------------------------------------------------------------
# * New Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Get additional troops in expanded encounter area
#--------------------------------------------------------------------------
def expanded_encounter_troops
#
temp_array = [] # Define temp array
x = $game_player.x # Get test target y-coordinates
y = $game_player.y # Get test target y-coordinates
#
for key in EncArea::AREA.keys # Cycle through arrays
passed = eea_map_test?(x, y, key) # Get valid area test result
next unless passed # Skip unless in valid area
next if EncArea::AREA[key][3].nil? # Skip if nil
temp_array += EncArea::AREA[key][3] # Add troops into array
end
#
return temp_array # Exit with troop-filled array
#
end
#--------------------------------------------------------------------------
# * Get change in expanded encounter's steps
#--------------------------------------------------------------------------
def expanded_encounter_steps
#
temp_step = 0 # Define temporary step value
x = $game_player.x # Get test target y-coordinates
y = $game_player.y # Get test target y-coordinates
#
for key in EncArea::AREA.keys # Cycle through arrays
passed = eea_map_test?(x, y, key) # Get valid area test result
next unless passed # Skip unless in valid area
next if EncArea::AREA[key][2].nil? # Skip if nil
temp_step = EncArea::AREA[key][2] # Reset temporary step value
end
#
return temp_step # Exit with new step value
#
end
#--------------------------------------------------------------------------
# * Test for valid expanded area
# x : x-coordinate
# y : y-coordinate
# key : key
#--------------------------------------------------------------------------
def eea_map_test?(x, y, key)
#
keys = EncArea::AREA[key][0] # Get valid map IDs for area
return false unless keys.include?(@map_id) # Exit if not in valid map
return eea_map_area?(x, y, key) # Exit with map test result
#
end
#--------------------------------------------------------------------------
# * Test within expanded area
# x : x-coordinate
# y : y-coordinate
# key : key
#--------------------------------------------------------------------------
def eea_map_area?(x, y, key)
#
areas = EncArea::AREA[key][1] # Get map area to test
#
return false if x < areas[0] # Fail if too far to the left
return false if x > areas[2] # Fail if too far to the right
return false if y < areas[1] # Fail if too far up
return false if y > areas[3] # Fail if too far down
#
return true # Exit with success
#
end
end
Instructions
Contained within the script.
FAQ
If compared to other scripts of this nature, it is much less invasive.
Add-On Tool: Colored Encounter Areas
This script allows you to press the [SHIFT] key to highlight any area you define on the map. Helpful so you know where your expanded areas really are. Paste it below Expanded Encounter Areas for it to work.
Colored Encounter Areas
Code:
#==============================================================================
# ** Colored Encounter Areas
# Add-On for Expanded Encounter Areas
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.1
# 02-07-2025 (MM-DD-YYYY)
# RGSS / RMXP
# Requires: Expanded Encounter Areas
#==============================================================================
#
# Essentially, this add-on allows you to press the [Shift] key when on a map
# where you had defined 'areas' that have new and updated random encounters.
#
# The areas become highlighted on the map, vital if you wish to visually see
# what you had configured in your game.
#
# Just paste this script below 'Expanded Encounter Areas' for it to work.
#
#==============================================================================
# Thanks to SephirothSpawn for the Tilemap Flash Data.
#==============================================================================
#==============================================================================
# ** Color
#------------------------------------------------------------------------------
# The RGBA color class. Each component is handled with a floating point
# value (Float).
#==============================================================================
class Color
#--------------------------------------------------------------------------
# * To Hexidecimal
#--------------------------------------------------------------------------
def to_hex
#
n = (self.red.to_i * 100)
n += (self.green.to_i * 10)
n += self.blue.to_i
return eval "0x#{n.to_s(16)}"
#
end
end
#==============================================================================
# ** Spriteset_Map
#------------------------------------------------------------------------------
# This class brings together map screen sprites, tilemaps, etc.
# It's used within the Scene_Map class.
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias seph_colored_enc_smap_initialize initialize
alias seph_colored_enc_smap_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
#
seph_colored_enc_smap_initialize # Perform the original method
#
wd = $game_map.width # Get current map width
ht = $game_map.height # Get current map height
#
@tilemap.flash_data = Table.new(wd, ht) # Make flash data for map
@sncounter_flash_flag = false # Set inactive flash flag
#
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
#
seph_colored_enc_smap_update # Perform the original method
update_colored_encounter_area # Colorize the area
#
end
#--------------------------------------------------------------------------
# * Frame Update : Handling developer's input for debug mode
#--------------------------------------------------------------------------
def update_colored_encounter_area
#
return unless $DEBUG # Exit unless in Debug mode
return unless Input.trigger?(Input::A) # Exit unless pressing shift
#
if @sncounter_flash_flag # If flash flag is ON
return clear_colored_map_area # Clear the area and exit
end
#
@area_colors = [] # Recreate a fresh color array
show_colored_map_area # Display colored areas
@sncounter_flash_flag = true # And set the flash flag ON
#
end
#--------------------------------------------------------------------------
# * Frame Update : Clearing the colored areas
#--------------------------------------------------------------------------
def clear_colored_map_area
#
for x in 0...$game_map.width # Cycle through map width
for y in 0...$game_map.height # Cycle through map height
@tilemap.flash_data[x, y] = 0 # And de-colorize/remove flash
end
end
#
@sncounter_flash_flag = false # Set the flash flag OFF
#
end
#--------------------------------------------------------------------------
# * Frame Update : Color the defined areas
#--------------------------------------------------------------------------
def show_colored_map_area
#
for key in EncArea::AREA.keys # Cycle through all area data
process_individual_area(key) # And process each area
end
#
end
#--------------------------------------------------------------------------
# * Apply color to an individual area
# key : key
#--------------------------------------------------------------------------
def process_individual_area(key)
#
id = $game_map.map_id # Get current map ID
unless EncArea::AREA[key][0].include?(id) # If area not for current map
return # Exit method
end
#
area = EncArea::AREA[key][1] # Get area rectangle from config
#
clr = get_random_color while clr.nil? || # Get new area color if nil
@area_colors.include?(clr) # and different from last
#
for x in area[0]-1...area[2] # Cycle through area width
for y in area[1]-1...area[3] # Cycle through area height
color = clr.to_hex # Convert hex to flash color
@tilemap.flash_data[x, y] = color # Set color to flash
end
end
#
end
#--------------------------------------------------------------------------
# * Get Random Color
#--------------------------------------------------------------------------
def get_random_color
#
rr = rand(17) * 15 # Randomize red (17-255)
gg = rand(17) * 15 # Randomize green (17-255)
bb = rand(17) * 15 # Randomize blue (17-255)
return Color.new(rr, gg, bb) # Make color with random values
#
end
end
Compatibility
Designed solely for RPGMaker XP.
This system rewrites the 'encounter_list' and 'encounter_steps' methods within Game_Map.
Terms and Conditions
Free for use, even in commercial projects. Only due credit is required.
RE: Expanded Encounter Areas - kyonides - 07-19-2020
# Each defined AREA hash must have a unique key. If two or more AREA hashes
# have the same key, the last one will take prescedent.
Perhaps you should word it in a different manner like "the latter will replace the former" because that's the default hash class behavior. If it's actually using hashes, people should know that they SHOULD NOT REPEAT KEYS unless they need to replace such a value on purpose.
By the way, your comments have got several typos.
As a side note, people, this script overwrites methods, alias trashed the original ones and replaced them with a redefinition, I used in my KMap scripts so be careful and place this script above mine. I do think I've aliased them so my changes should not alter the final outcome.
RE: Expanded Encounter Areas - DerVVulfman - 07-19-2020
I prefer wording my instructions in my manner. I certainly give more information than some on how a script is to be used.
Quote:By the way, your comments got several typos.
It is: By the way, your comments have several typos. Good grammar...
This requires a forced change to these methods. But I had identified such changes, and added quite descriptive and helpful comments as to their functions. And no, I will not receive any 'suggestions' towards any changes to the methods. Any suggestions would be deemed as argumentative and erased.
RE: Expanded Encounter Areas - DerVVulfman - 08-09-2020
An unobtrusive
UPDATE
has been made.
The script itself had not been altered. There is no reason to do so. However, the topic was altered to include a helpful developer's tool.
This tool is a simple little script allows you to visually 'see' the areas you define within 'Expanded Encounter Areas'. When installed, you can simply press the [Shift] key on a map and the defined areas will be highlighted in various random colors.
It does nothing else but show the rectangular areas. Still, it should prove useful.
RE: Expanded Encounter Areas - DerVVulfman - 02-08-2026
A bit of a
HOUSECLEANING UPDATE
has been made.
The underlying functionality of both Expanded Encounter Areas and the Colored Encounter Areas scripts have not been touched. For the most part, they had sections rewritten in my current style to make them more compatible with other scripts that may seek to add content to methods which these two had aliased.
Ergo, nothing of the actual configuration section had been changed except for a couple minor notes. If an end user is updating their copy of this script, they have naught to worry about.
What had been changed was the breakdown of some methods and a more appropriate naming convention. Simultaneousply, one method was broken in twain (wow... twain?). Indeed, a portion of the script that checked to see if the player was within an defined area was quite crucial to a new add-on script that I will soon be releasing. There was no reason to create a whole new script with all the area-defining mechanics when just a plug-in using content from Expanded Encounter Areas would suffice.
And of the Colored Encounter Areas... I just found out that I nerfed the random color-area feature on its initial release. Now it should let you see the different rectangles on the map in different colors rather than the same fixed off-green.