Advanced Areas
Version: 1.5
Author: modern algebra
Date: September 26, 2008
Version History
- Version 1.5 - September 26, 2008 - added the ability to contain randomly moving events to an area
- Version 1.0 - March 12, 2008
Description
Adds a couple of options to areas. If anyone has any ideas for more, please tell me.
Features
- NEW - Allows you to contain an event to an area or group of areas
- Allows you to marry an in-game switch to an area, thus allowing it to be turned on and off at will. This can be useful if say, after some event in your game, like a volcano erupting, you want different monsters to pop up
- Allows you to set an encounter step for each area. Where two areas conflict, it takes the smallest encounter step
Screenshots
N/A
Instructions
See inside the script
Script
#==============================================================================
# Advanced Areas
# Version 1.5
# Author: modern algebra (rmrk.net)
# Date: September 26, 2008
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
# Set up the database below in the Editable Regions. Both are set up in the
# same way, and they look like this:
#
# when id
# rate/switch = value
#
# You only need to set it if it is not default. If an area has no switch,
# then don't set it up. If you want the encounter step to be the same as
# the parent map, then do not set it up. In any case, just so we are clear,
# I provided a few examples in the Editable Regions. Feel free to
# replace/delete them once you know what you're doing.
#
# To restrict events so that they cannot move outside of a given area or
# areas, then all you need to do is place a comment on the first line of any
# page of the event you want to restrict, and in that comment put this:
# \AREA[area id]. If you want him to be able to move freely in more than one
# area, then you can put as many of those codes there as there are areas he
# can move in. Thus, if an event had this in his comment:
#
# \Area[1]\AreA[5]\AREA[9]
#
# Then that event would have free passage in the Areas 1, 5, and 9, but
# would not be able to move outside of them.
#==============================================================================
#==============================================================================
# ** RPG::Area
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of changes:
# new methods - encounter_step, active?
#==============================================================================
class RPG::Area
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Encounter Rate
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def encounter_step
rate = $game_map.encounter_step
# Branch by ID
case @id
#----------------------------------------------------------------------
# EDITABLE REGION
#----------------------------------------------------------------------
when 1
rate = 10
when 3
rate = 15
#----------------------------------------------------------------------
# END EDITABLE REGION
#----------------------------------------------------------------------
end
return rate
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Active?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def active?
switch = 0
case @id
#----------------------------------------------------------------------
# EDITABLE REGION
#----------------------------------------------------------------------
when 1
switch = 1
when 4
switch = 1
#----------------------------------------------------------------------
# END EDITABLE REGION
#----------------------------------------------------------------------
end
return true if switch == 0
return $game_switches[switch]
end
end
#==============================================================================
# ** Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased method - encounter_step
#==============================================================================
class Game_Map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Encounter Step
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_advncd_areas_step_encntr encounter_step
def encounter_step
# Get original Map Encounter Step
encounter_rates = [modalg_advncd_areas_step_encntr]
# Get all the areas the player is in. For ne
$data_areas.values.each { |i| encounter_rates.push (i.encounter_step) if i.map_id == @map && $game_player.in_area? (i) }
return encounter_rates.min
end
end
#==============================================================================
# ** Game_Player
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased methods - in_area?
#==============================================================================
class Game_Player
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * In Area?
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_advnced_areas_area_in? in_area?
def in_area? (area)
return false unless area.active?
modalg_advnced_areas_area_in? (area)
end
end
==============================================================================
# ** Game_Event
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased methods - setup, passable?
# new method - in_area?
#==============================================================================
class Game_Event < Game_Character
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Event page setup
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_stp_advarea_contain_nfg5 setup
def setup(new_page)
@areas.nil? ? @areas = [] : @areas.clear
# If new page is real
if new_page != nil
first_command = new_page.list[0].dup
# If first line is a comment
if first_command.code == 108
loop do
slice = first_command.parameters[0].slice! (/\\AREA\[(\d+)\]/i) { "" }
slice == nil ? break : @areas.push ($1.to_i)
end
end
end
modalg_stp_advarea_contain_nfg5 (new_page)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Determine if Passable
# x : x-coordinate
# y : y-coordinate
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_contain_areas_adv_pass_hfe passable?
def passable?(x, y)
return modalg_contain_areas_adv_pass_hfe (x, y) if @areas == nil || @areas.empty?
in_area = false
@areas.each { |i|
# If within one of the areas, it is passable
in_area = in_area? ($data_areas[i], x, y)
break if in_area
}
return in_area && modalg_contain_areas_adv_pass_hfe (x, y)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Determine if in Area (Transferred from Game_Player
# area : Area data (RPG::Area)
# x : x-coordinate
# y : y-coordinate
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def in_area?(area, x, y)
return false if area == nil
return false unless area.active?
return false if $game_map.map_id != area.map_id
return false if x < area.rect.x
return false if y < area.rect.y
return false if x >= area.rect.x + area.rect.width
return false if y >= area.rect.y + area.rect.height
return true
end
end
Credit
Thanks
Support
Just post here if you have any errors. I will try to fix them. If you have any ideas about good options to add to the areas, please post here and if I think they are good I will write them in.
Known Compatibility Issues
No known compatibility issues.
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.