07-19-2020, 08:29 PM
(This post was last modified: 4 hours ago by DerVVulfman.)
Expanded Encounter Areas
Version: 1.1
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.
Demo
CLICK HERE
Script
The Script
Code:
#==============================================================================
# ** 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
#--------------------------------------------------------------------------
# * Aliased Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * 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
endInstructions
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
endCompatibility
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.
Up is down, left is right and sideways is straight ahead. - Cord "Circle of Iron", 1978 (written by Bruce Lee and James Coburn... really...)
Above are clickable links


![[Image: QrnbKlx.jpg]](https://i.imgur.com/QrnbKlx.jpg)
![[Image: sGz1ErF.png]](https://i.imgur.com/sGz1ErF.png)
![[Image: liM4ikn.png]](https://i.imgur.com/liM4ikn.png)
![[Image: fdzKgZA.png]](https://i.imgur.com/fdzKgZA.png)
![[Image: sj0H81z.png]](https://i.imgur.com/sj0H81z.png)
![[Image: QL7oRau.png]](https://i.imgur.com/QL7oRau.png)
![[Image: uSqjY09.png]](https://i.imgur.com/uSqjY09.png)
![[Image: GAA3qE9.png]](https://i.imgur.com/GAA3qE9.png)
![[Image: 2Hmnx1G.png]](https://i.imgur.com/2Hmnx1G.png)
![[Image: BwtNdKw.png%5B]](https://i.imgur.com/BwtNdKw.png%5B)


![[Image: SP1-Scripter.png]](https://www.save-point.org/images/userbars/SP1-Scripter.png)
![[Image: SP1-Writer.png]](https://www.save-point.org/images/userbars/SP1-Writer.png)
![[Image: SP1-Poet.png]](https://www.save-point.org/images/userbars/SP1-Poet.png)
![[Image: SP1-Reporter.png]](https://i.postimg.cc/GmxWbHyL/SP1-Reporter.png)

