+- 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.0
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.
Script
˂Paste the actual code here, using the CODE tag. This section is optional if you have a demo, but highly recommended for simple to moderately complex scripts.˃
The Script
Code:
#==============================================================================
# ** Expanded Encounter Areas
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 07-19-2020 (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.
#
# Each AREA hash is givena 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 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.
#
#
#==============================================================================
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 encoutner occurs.
#
# AREA Map(s) Rectangle Area St Troops
# ======= ===== =============== === ========
AREA[1] = [ [1], [ 4, 4, 14, 11], 10, [12,13,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
#--------------------------------------------------------------------------
# * Get Encounter List
#--------------------------------------------------------------------------
def encounter_list
# Acquire default troops
list = @map.encounter_list
# Add additional troops available
list += expanded_encounter_troops
# Display if debug defined
p list if $DEBUG && EncArea::DEBUG_SHOW == true
return list
end
#--------------------------------------------------------------------------
# * Get Encounter Steps
#--------------------------------------------------------------------------
def encounter_step
# Acquire default steps
steps = @map.encounter_step
# Acquire change in steps for area
new_steps = expanded_encounter_steps
# Change steps if valid
steps = new_steps if new_steps >= 1
# Display if debug defined
p "Steps Changed to: " + steps.to_s if $DEBUG && EncArea::DEBUG_SHOW == true
return steps
end
#--------------------------------------------------------------------------
# * Get additional troops in expanded encounter area
#--------------------------------------------------------------------------
def expanded_encounter_troops
# Define empty array
extra_troops = []
# Cycle throough all arrays
for key in EncArea::AREA.keys
# Skip unless test passes
next unless expanded_encounter_test?(key)
# Now add troops
extra_troops += EncArea::AREA[key][3]
end
# Return
return extra_troops
end
#--------------------------------------------------------------------------
# * Get change in expanded encounter's steps
#--------------------------------------------------------------------------
def expanded_encounter_steps
# Define empty array
different_steps = 0
# Cycle throough all arrays
for key in EncArea::AREA.keys
# Skip unless test passes
next unless expanded_encounter_test?(key)
# Now change steps
different_steps = EncArea::AREA[key][2]
end
# Return
return different_steps
end
#--------------------------------------------------------------------------
# * Test for valid expanded area
# key : key
#--------------------------------------------------------------------------
def expanded_encounter_test?(key)
# Skip if not the map in the defined area
return false unless EncArea::AREA[key][0].include?(@map_id)
# Get area zone
area_scan = EncArea::AREA[key][1]
# Return false if not in the defined zone
return false if $game_player.x < area_scan[0]
return false if $game_player.x > area_scan[2]
return false if $game_player.y < area_scan[1]
return false if $game_player.y > area_scan[3]
# Return true
return true
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.0
# 08-08-2020 (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.
#
#==============================================================================
#==============================================================================
# ** 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) + (self.green.to_i * 10) + 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_encctrl_gmmap_init initialize
alias seph_encctrl_gmmap_update update
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
# Original Initialization
seph_encctrl_gmmap_init
# Creates Flash Data Table & Flash Tile Flag
@tilemap.flash_data = Table.new($game_map.width, $game_map.height)
@sncounter_flash_flag = false
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Original Update
seph_encctrl_gmmap_update
# Colorize the area
update_colored_encounter_area
end
#--------------------------------------------------------------------------
# * Frame Update : Handling developer's input for debug mode
#--------------------------------------------------------------------------
def update_colored_encounter_area
# Only function in Debug mode
return unless $DEBUG
# Only function if A button (Shift) Is Pressed
return unless Input.trigger?(Input::A)
# Clear colored area if color area flag is true
return clear_colored_map_area if @sncounter_flash_flag
# Set up color array to prevent color duplication
@area_colors = []
# Display colored areas
show_colored_map_area
# set colored area flag to true
@sncounter_flash_flag = true
end
#--------------------------------------------------------------------------
# * Frame Update : Clearing the colored areas
#--------------------------------------------------------------------------
def clear_colored_map_area
# De-Color the map area
for x in 0...$game_map.width
for y in 0...$game_map.height
@tilemap.flash_data[x, y] = 0
end
end
# Turn color area flag off
@sncounter_flash_flag = false
end
#--------------------------------------------------------------------------
# * Frame Update : Color the defined areas
#--------------------------------------------------------------------------
def show_colored_map_area
# Cycle through all area data
for key in EncArea::AREA.keys
process_individual_area(key)
end
end
#--------------------------------------------------------------------------
# * Apply color to an individual area
# key : key
#--------------------------------------------------------------------------
def process_individual_area(key)
# Exit if not for current map
return unless EncArea::AREA[key][0].include?($game_map.map_id)
# Acquire area rectangle from config
area = EncArea::AREA[key][1]
# Acquire area color
color = get_random_color while color.nil? || @area_colors.include?(color)
# Colorize individual area
for x in area[0]-1...area[2]
for y in area[1]-1...area[3]
@tilemap.flash_data[x, y] = 2000 #color.to_hex
end
end
end
#--------------------------------------------------------------------------
# * Get Random Color
#--------------------------------------------------------------------------
def get_random_color
return Color.new(rand(17) * 15, rand(17) * 15, rand(17) * 15)
end
end[/code]
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.