DerVVulfman
Sponsor
RM2K Defined Encounters Areas
Version: 1.1
by RPG Advocate
Not by DerVVulfman
Introduction
This script allows you to set up rectangular areas with different encounters like the map editor functionality of RPG Maker 2000 and 2003.
Screenshots
Meh... It's a map feature.
Demo
HERE ya go!
I drew some tiles surrounding my defined areas in the demo map, just so you can see where ya are.
Script
The script is in two components, a parallel map event and the RGSS script itself.
Instructions
The 1st thing to look at is the 'Event' code:
The next thing to look at is the actual RGSS Script:
Where to edit in the script?: Sure... I'll tell ya.
FAQ
This script was posted at http://www.phylomortis.com, but had a minor glitch that the 'example' image file (that showed how to set encounters) was missing.
Compatibility
As the CENTRAL portion of this script is a rewrite of Scene_Map's Update routine, any script that rewrites this portion will have problems. IF you're using a script that ALIASes Scene_Map, I recommend pasting this ABOVE that script.
Credits and Thanks
Obviously to RPG Advocate for returning this system to RMXP.
Author's Notes
Sorry, I ain't the author... just the guy who figured it out. :D
Version: 1.1
by RPG Advocate
Not by DerVVulfman
Introduction
This script allows you to set up rectangular areas with different encounters like the map editor functionality of RPG Maker 2000 and 2003.
Screenshots
Meh... It's a map feature.
Demo
HERE ya go!
I drew some tiles surrounding my defined areas in the demo map, just so you can see where ya are.
Script
The script is in two components, a parallel map event and the RGSS script itself.
The parallel process map event runs as long as the character is ON a map. It holds the lists of enemy troops. Here's an example:
@>Wait: 10 frame(s)
@>Comment: I set variable #1 to tell me what AREA the player is in.
@>Control Variables: [0001] = 0
@>Comment: This routine assigns an AREA value to my variable
@>Script: if $scene.is_a?(Scene_Map)
: : $scene.get_world_map_area_id
: : end
@>Comment: If not in a defined area
@>Conditional Branch: Variable [0001] == 0
@>Script: $game_map.enum_encounter_list = []
@>
: Branch End
@>Comment: If within the bounds of rectangle 1...
@>Conditional Branch: Variable [0001] == 0
@>Script: $game_map.enum_encounter_list = [1, 2]
@>
: Branch End
@>Comment: If within the bounds of rectangle 2...
@>Conditional Branch: Variable [0001] == 0
@>Script: $game_map.enum_encounter_list = [4, 5]
@>
: Branch End
Code:
#==============================================================================
# *** RM2K Defined Encounter Areas
#------------------------------------------------------------------------------
# Script by RPG_Advocate
# Original date unknown (before Dec. 2005)
#==============================================================================
#==============================================================================
# ** 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
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :enum_encounter_list
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias enc_initialize initialize
def initialize
@enum_encounter_list = []
enc_initialize
end
#--------------------------------------------------------------------------
# * End of Class
#--------------------------------------------------------------------------
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# This class performs map screen processing.
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Loop
loop do
# Update map, interpreter, and player order
# (this update order is important for when conditions are fulfilled
# to run any event, and the player isn't provided the opportunity to
# move in an instant)
$game_map.update
$game_system.map_interpreter.update
$game_player.update
# Update system (timer), screen
$game_system.update
$game_screen.update
# Abort loop if player isn't place moving
unless $game_temp.player_transferring
break
end
# Run place move
transfer_player
# Abort loop if transition processing
if $game_temp.transition_processing
break
end
end
# Update sprite set
@spriteset.update
# Update message window
@message_window.update
# If game over
if $game_temp.gameover
# Switch to game over screen
$scene = Scene_Gameover.new
return
end
# If returning to title screen
if $game_temp.to_title
# Change to title screen
$scene = Scene_Title.new
return
end
# If transition processing
if $game_temp.transition_processing
# Clear transition processing flag
$game_temp.transition_processing = false
# Execute transition
if $game_temp.transition_name == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$game_temp.transition_name)
end
end
# If showing message window
if $game_temp.message_window_showing
return
end
# The revised random encounter routine
# If 'encounter count' is 0 ('STEPS COUNTER' from Map Properties uses this)
if $game_player.encounter_count == 0
# If we have an encounter list (original OR area defined)
if $game_map.encounter_list != [] || $game_map.enum_encounter_list != []
# As long as the map is running and encounters are on...
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
if $game_map.enum_encounter_list != []
n = rand($game_map.enum_encounter_list.size)
troop_id = $game_map.enum_encounter_list[n]
else
n = rand($game_map.encounter_list.size)
troop_id = $game_map.encounter_list[n]
end
# If it's a valid enemy troop
if $data_troops[troop_id] != nil
# Set the battle flags
$game_temp.battle_calling = true
$game_temp.battle_troop_id = troop_id
$game_temp.battle_can_escape = true
$game_temp.battle_can_lose = false
$game_temp.battle_proc = nil
end
end
end
end
# If B button was pressed
if Input.trigger?(Input::B)
# If event is running, or menu is not forbidden
unless $game_system.map_interpreter.running? or
$game_system.menu_disabled
# Set menu calling flag or beep flag
$game_temp.menu_calling = true
$game_temp.menu_beep = true
end
end
# If debug mode is ON and F9 key was pressed
if $DEBUG and Input.press?(Input::F9)
# Set debug calling flag
$game_temp.debug_calling = true
end
# If player is not moving
unless $game_player.moving?
# Run calling of each screen
if $game_temp.battle_calling
call_battle
elsif $game_temp.shop_calling
call_shop
elsif $game_temp.name_calling
call_name
elsif $game_temp.menu_calling
call_menu
elsif $game_temp.save_calling
call_save
elsif $game_temp.debug_calling
call_debug
end
end
end
#--------------------------------------------------------------------------
# * Get World Map Area (Editable Area
#--------------------------------------------------------------------------
def get_world_map_area_id
area = 0
flag = 0
# HERE we define the area rectangles...
rect1 = [1, 1, 7, 7] # My 1st rectangle...
rect2 = [8, 8, 14, 14] # My 2nd rectangle... (I could make more :) )
# HERE, we combine the area rectangles
area_rects = [rect1, rect2] # I just put all the rectangles in here.
x = $game_player.x
y = $game_player.y
for i in 0..area_rects.size - 1
if x >= area_rects[i][0]
if y >= area_rects[i][1]
if x <= area_rects[i][2]
if y <= area_rects[i][3]
area = i + 1
flag += 1
end
end
end
end
end
if flag >= 2
print("Warning. Declared areas are not mutually exclusive.")
end
# THIS assigns the AREA to variable #1
$game_variables[1] = area
end
#--------------------------------------------------------------------------
# * End of Class
#--------------------------------------------------------------------------
end
Instructions
The 1st thing to look at is the 'Event' code:
This is a map event (set to parallel process) that checks every-so-often whether the player is in a defined area (defined in the script). When it checks, it fills a variable (I chose variable #1 [0001]) with the number of a defined rectangular area... or '0' if the hero is NOT in a defined area.
When that is done, it then goes through if conditions, one after the other. Each one does almost the same thing... it calls an RGSS script:
$game_map.enum_encounter_list = [ list of enemy troop ids ]
And, that's all the map event does. Sees where the player is on the map, uses a user-defined variable to check what script-defined rectangle he/she's in (if any), and store a list of enemy encounters in a value ($game_map.enum_encounter_list).
I created 2 rectangle areas in my demo, so the value it would return would be 0, 1 or 2... again, a '0' would mean the player is NOT in one of the two rectangle areas.
When that is done, it then goes through if conditions, one after the other. Each one does almost the same thing... it calls an RGSS script:
$game_map.enum_encounter_list = [ list of enemy troop ids ]
My first list that HOLDS troops is... = [1, 2]
This holds troop numbers 1 and 2 (ie Ghost*2 and Ghost*3 in the default setup).
And, that's all the map event does. Sees where the player is on the map, uses a user-defined variable to check what script-defined rectangle he/she's in (if any), and store a list of enemy encounters in a value ($game_map.enum_encounter_list).
The next thing to look at is the actual RGSS Script:
This script should be pasted above MAIN... or more importantly, above ANY script that messes with Scene_Map's update It's a complete rewrite... or more to the point, line 100 down to line 126 replaces the original random-encounter section of Scene_Map.
Where to edit in the script?: Sure... I'll tell ya.
Go to the bottom of the script... the get_world_map_area_id area.
Here, you define the rectangle(s) where the enemy troops are encountered, and copy ALL the defined areas into an array. As an example, consider this:
The first rectangle I defined is kinda small, it starts at the top left corner of the map and is 7 tiles high and 7 tiles wide.
The second rectangle starts at tile 8 across and 8 down. It TOO is 7 tiles high and 7 tiles wide (not 14!).
After designing the two rectangles (I coulda added more rectangles), I put 'em both in my area_rects array.
Now, the first rectangle (rect1) is checked every so often by the map 'event' (the 'event' instructions above), and if the player is in THIS rectangle, the number 1 is returned. Likewise, if the player is found to be within the area defined in the second rectangle (rect2), the number 2 is returned (value based on it's order in area_rects).
Now, the next section to edit... if need be... is at the bottom of the script.
Tells us that we're gonna use variable #1 [0001] to store the area in question. This is the same variable being read in the 'map event' above. If, you change it to:
You'd have to change the variable in the map events to match.
That's pretty much it. The script section creates the rectangle areas (only) and tells us which variable we're gonna use in the conditional branches in the map event above.
Here, you define the rectangle(s) where the enemy troops are encountered, and copy ALL the defined areas into an array. As an example, consider this:
Code:
rect1 = [1, 1, 7, 7]
rect2 = [8, 8, 14, 14]
area_rects = [rect1, rect2]
The second rectangle starts at tile 8 across and 8 down. It TOO is 7 tiles high and 7 tiles wide (not 14!).
After designing the two rectangles (I coulda added more rectangles), I put 'em both in my area_rects array.
Now, the first rectangle (rect1) is checked every so often by the map 'event' (the 'event' instructions above), and if the player is in THIS rectangle, the number 1 is returned. Likewise, if the player is found to be within the area defined in the second rectangle (rect2), the number 2 is returned (value based on it's order in area_rects).
Now, the next section to edit... if need be... is at the bottom of the script.
Code:
$game_variables[1] = area
Code:
$game_variables[23] = area
That's pretty much it. The script section creates the rectangle areas (only) and tells us which variable we're gonna use in the conditional branches in the map event above.
FAQ
This script was posted at http://www.phylomortis.com, but had a minor glitch that the 'example' image file (that showed how to set encounters) was missing.
Compatibility
As the CENTRAL portion of this script is a rewrite of Scene_Map's Update routine, any script that rewrites this portion will have problems. IF you're using a script that ALIASes Scene_Map, I recommend pasting this ABOVE that script.
Credits and Thanks
Obviously to RPG Advocate for returning this system to RMXP.
Author's Notes
Sorry, I ain't the author... just the guy who figured it out. :D