11 hours ago
Active Bound-Area Events
Version: 1.0
Version: 1.0
Introduction
Utilizing the area-defining mechanics of "Expanded Encounter Areas", you can now create events that move about randomly, but only within areas which you have defined. Monsters may never leave their hunting area, guards may be forced to stay within their posts, and a throng of wild party animals might find they never leave the opulant dance floor.
Its up to you.
Screenshots
Picture a guy running into an invisible wall and taking a step backwards...
Demo
Nope.
Script
FUN STUFF HERE
Code:
#==============================================================================
# ** Active Bound-Area Events
# Add-On for Expanded Encounter Areas
#------------------------------------------------------------------------------
# by DerVVulfman
# version 1.0
# 02-07-2025 (MM-DD-YYYY)
# RGSS / RMXP
# Requires: Expanded Encounter Areas
#==============================================================================
#
# Utilizing the area-defining mechanics of "Expanded Encounter Areas", you
# can now create events that move about randomly, but only within areas which
# you have defined. Monsters may never leave their hunting area, guards may
# be forced to stay within their posts, and a throng of wild party animals
# might find they never leave the opulant dance floor.
#
# Its up to you.
#
#
#------------------------------------------------------------------------------
#
# I will not go into details into how to set up an 'area' where your events
# are to be contained. Instead, I will focus on this script and how to make
# events that are essentially TRAPPED by the areas created with that work.
#
# Okay, setting up an event to be STUCK in an area (or areas).
#
# This is done by adding comments within the 'Event commands' window. The
# first comment is one that informs the script that the event is indeed to
# be trapped in an area (or areas). The comment is merely one word, and is
# the word "EEA" by default (no quotes). When I say its 'by default' I mean
# you can change that word in the simple config section of ths script.
#
# But for now, the trigger word that identifies the event as one stuck in an
# area is "EEA". ^_^
#
# Following this, the second comment you add contains the word "EEA_Areas"
# followed by either a number or an array of numbers. The number(s) are the
# ID keys to the "AREA" hashes you have setup in "Expanded Encounter Areas".
# So if you have a comment read "EEA_Areas 4", then the event is stuck with-
# in AREA[4] in your system. And the comment is like "EEA_Areas [5,6,9]",
# then your event will only be able to walk about within those three defined
# areas. Of course, I am going to assume there's some overlap between these
# as the event can't very well HOP distances.
#
# Actually, the JUMP event will work in that instance. ^_^
#
# The last comment is more optional, but understandingly so. It defines the
# way the event behaves when it tries to exit out of the area. By default,
# the event merely backs up (walks backwards) one tile. Otherwise, you have
# access to five other reactions to an attempted area border crossing.
#
# 0 = steps backwards 1 tile (default)
# 1 = steps backwards 2 tiles
# 2 = turns and walks forward 1 tile (away from border)
# 3 = turns and walks forward 2 tiles (away from border)
# 4 = Walks/Moves to the vent's origin point (may be hindered by objects)
# 5 = Appears at the event's origin point
#
# You may neglect to add the "EEA_Return" comment as it has a default, but
# you do need to add the "EEA" trigger word and the "EEA_Areas" otherwise it
# will not finish defining the event.
#
#
#------------------------------------------------------------------------------
#
# Something you may not have considered. The EEA commands only work within
# event pages where they are defined. That is to say, you can make an event
# with multiple pages, and each page can have its own set of EEA commands to
# control what areas it may traverse, or have pages where they don't exist.
#
# Being able to set different EEA commands or have them non-existent on some
# pages should give you even MORE control than you might have expected!
#
#
#------------------------------------------------------------------------------
#
# The Configuration section (below) is present solely so you can choose the
# words that you use when you create your event. Its only present for those
# who use another language and for their convenience. Otherwise, its hardly
# ever going to get touched.
#
# NOTE: The EEA Trigger word is case sensitive, so it must be exactly the
# same in your event comments. The others are case inseneitive, and
# do not care if you use upper and/or lowercase characters.
#
#
#==============================================================================
#
# COMPATABILITY:
#
# Designed solely for RPGMaker XP and the Expanded Encounter Areas script.
#
# All contents have been aliased, or had code attached to existing methods
# without rewrites.
#
#
#==============================================================================
#
# TERMS AND CONDITIONS
#
# Free for use, even in commercial projects. Only due credit for myself and
# Ace_V who suggested a like feature is required.
#
#
#==============================================================================
module EncArea
# The Expanded Encounter Area Trigger
# ===================================
# This word needs to be read first by the system to inform the script that
# the event is an EEA controlled event. The word is case sensitive, so if
# your 'replacement' for EEA has upper and lowercase characters, so too it
# must be in your comments.
#
EEA_FLAG = "EEA"
# The Expanded Areas Array
# ========================
# This word informs the system that it will be followed by either the ID of
# an area defined in the "Expanded Encounter Areas" script, or by an array
# filled with multiple IDs. Unlike the EEA_Flag, it is case insensitive.
#
AREA_FLAG = "EEA_Areas"
# The Expanded Areas Return Type
# ==============================
# This word informs the system that you have chosen the manner in which the
# event will back away and remain within the enclosed area. Again, this is
# also a case insensitive word.
#
RETURN_FLAG = "EEA_RETURn"
end
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# This class deals with events. It handles functions including event page
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias dervv_event_eea_init initialize
alias dervv_event_eea_refresh refresh
alias dervv_event_eea_update update
#--------------------------------------------------------------------------
# * Aliased and Attached Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Object Initialization
# map_id : map ID
# event : event (RPG::Event)
#--------------------------------------------------------------------------
def initialize(map_id, event)
#
dervv_event_eea_init(map_id, event) # Perform the original method
#
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
#
@eea_areas = [] # Clear EEA area IDs
@eea_return = 0 # Reset EEA return trigger
dervv_event_eea_refresh # Perform the original method
refresh_eea_events(@list) # Perform checks on event
#
end
#--------------------------------------------------------------------------
# * Determine if Passable (from Game_Character)
# x : x-coordinate
# y : y-coordinate
# d : direction (0,2,4,6,8)
# * 0 = Determines if all directions are impassable (for jumping)
#--------------------------------------------------------------------------
def passable?(x, y, d)
#
eea_area_exceeded?(x, y, d) # Test if event exceeds area
return super(x, y, d) # Exit with superclass result
#
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
#
update_eea_event_return # Force return on trigger
dervv_event_eea_update # Perform the original method
#
end
#--------------------------------------------------------------------------
# * Attached Methods - Direct link to Aliased Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Refresh (when retrieving comment commands)
# list : list of event commands
#--------------------------------------------------------------------------
def refresh_eea_events(list)
#
return if list.nil? # Exit if there's no cmd list
#
parameters = [] # Create Array for comments
word1 = EncArea::EEA_FLAG # Get EEA word (case sensitive)
word2 = (EncArea::AREA_FLAG).upcase # Get Area array word
word3 = (EncArea::RETURN_FLAG).upcase # Get Event reaction word
#
# Cycle through list
update_eea_event_return # Force return on trigger
for item in list # Cycle through the commands
unless [108, 408].include?(item.code) # If it isn't a comment
next # Skip to next item
end
parameters.push(item.parameters[0]) # Push item into comment array
end
#
return if parameters == [] # Exit if no comments
return unless parameters.include?(word1) # Exit if no EEA word/flag
#
for param in parameters # Cycle through comments
check = param.split # Split each comment in two
next if check[1].nil? # Exit if second half empty
#
trigger = check[0].upcase # Get comment trigger
if trigger == word2 # If it's an area array trigger
refresh_eea_event_area(check[1]) # Obtain area IDs for the event
end
if trigger == word3 # If it's a event return trigger
refresh_eea_event_return(check[1]) # Obtain return for event
end
end
#
end
#--------------------------------------------------------------------------
# * Determine if Encounter Area exceeded
# x : x-coordinate
# y : y-coordinate
# d : direction (0,2,4,6,8)
# * 0 = Determines if all directions are impassable (for jumping)
#--------------------------------------------------------------------------
def eea_area_exceeded?(x, y, d)
#
nx = (x+1) + (d == 6 ? 1 : d == 4 ? -1 : 0) # Get new x coords (start at 1)
ny = (y+1) + (d == 2 ? 1 : d == 8 ? -1 : 0) # Get new y coords (start at 1)
#
return if @eea_areas.nil? # Exit on invalid areas
return if @eea_areas == [] # Exit if event areas is empty
#
effective = false # Assume not in a defined area
#
for area in @eea_areas # Cycle through event's areas
next if area.nil? # Skip if area is empty
if $game_map.eea_map_area?(nx, ny, area) # If the event is IN the area
effective = true # Set the effective flag
end
end
#
return if effective == true # Exit if still in the area(s)
#
@eea_trigger = true # Set trigger - event outside!
#
end
#--------------------------------------------------------------------------
# * Frame Update (when moving the event back across the border)
#--------------------------------------------------------------------------
def update_eea_event_return
#
return unless @eea_trigger == true # Exit unless triggered
@eea_trigger = false # Clear the trigger
eea_event_motion(@eea_return) # Force the event to move
#
end
#--------------------------------------------------------------------------
# * New Methods
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
# * Refresh event areas defined
# value : area list value
#--------------------------------------------------------------------------
def refresh_eea_event_area(value)
#
val = eval(value) # Get evaluated value
#
if val.is_a?(Array) # If it is an array
@eea_areas = val # Merely accept the value
end
if val.is_a?(Integer) # If it is a single integer
@eea_areas = [val] # Set the value in an array
end
#
end
#--------------------------------------------------------------------------
# * Refresh event return condition
# value : movement return value
#--------------------------------------------------------------------------
def refresh_eea_event_return(value)
#
@eea_return = eval(value).to_i # Set return to evaluated value
@eea_return = 0 if @eea_return < 0 # Return is no lower than 0
@eea_return = 5 if @eea_return > 5 # Return is no higher than 5
#
end
#--------------------------------------------------------------------------
# * Perform event movtion based on Encounter area
# value : movement return value
#--------------------------------------------------------------------------
def eea_event_motion(value)
#
# NOTE: Required 1 additional movement to counter attempted crossing.
#
case value # Branch on move value
when 1 ; eea_b ; eea_b; eea_b # Step backwards twice
when 2 ; turn_180 ; eea_f ; eea_f # Turn & step forward
when 3 ; turn_180 ; eea_f ; eea_f; eea_f # Turn & two steps forward
when 4 ; @x, @y = @event.x, @event.y # Move to origin
when 5 ; moveto(@event.x, @event.y) # Appear at origin
else ; eea_b ; eea_b # Step backwards
end
#
end
#--------------------------------------------------------------------------
# * Shortcut to Game_Character: move_backward
#--------------------------------------------------------------------------
def eea_b
move_backward
end
#--------------------------------------------------------------------------
# * Shortcut to Game_Character: move_forward
#--------------------------------------------------------------------------
def eea_f
move_forward
end
endInstructions
Plenty, and in the script. But most of the work is in the parent script this requires.
Compatibility
Designed solely for RPGMaker XP and the Expanded Encounter Areas script.
Credits and Thanks
Gotta thank Ace_V for giving me the idea.
Terms and Conditions
Free for use, even in commercial projects. Only due credit for myself and Ace_V who suggested a like feature 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)