silver wind
Member
What does the script do?
- It Makes the encounter list depend on terrain tags.
you can define which monsters appear on land, water, and so on.
Each map has 7 areas (area1 = all tiles with tag 1).
- lets you change the encounter list in an event call (v1.2)
for more info, read the instructions in the code.
version 1.2
[rgss]
#===========================================================
# ** Monster Area
#-----------------------------------------------------------
# by silver wind
# V1.2
#
# This script brings back a feature from RM2K3.
# It lets you define areas on the map.
# each area has different monsters (encounter list).
#
# * Define a new area :
# use a tile with terrain tag (other than 0)
# and simply draw with it on the map.
# notes:
# - use tags 1-7. tag 0 means no encounters
# - may not work with events with a tile graphic.
# - you can use a white tile on layer 3,
# so the area is invisible.
#
# * Define monsters in each map :
# see 'configure' below.
#
# * change the encouners in an area using a script :
# script call: Encounters.set(hash)
# the hash should contain 1 or more lines of the form:
# tag_number => list of troop names
# ie: Encounters.set( {1=>'Ghost*2'} )
#===========================================================
class Area
attr_reader :id
attr_accessor :monster_list
def initialize(id,list)
@id = id
@monster_list = list
end
end
class Map_Area
def initialize(map_id)
@id = map_id
@areas = {}
end
# i : area id
def [](i)
# return the area's monster list
return [] if @areas.nil?
@areas.monster_list
end
# i : area id
def add(area)
i = area.id
@areas = area
end
def empty?(tag)
# is the troop list empty?
list = self[tag]
return list.size == 0
end
def add_monster(area,id)
return unless legal?(area)
i = area
# make a new area
if (@areas)==nil
new_area = Area.new( i, [] )
add(new_area)
end
# add to area
@areas.monster_list << id
end
def legal?(area)
(area >= 1 or area <= 7)
end
end
class Monster_Area
def get_map
$game_map.map_id
end
def initialize
@areas = {}
for i in map_list
@areas = Map_Area.new(i)
end
setup
end
def [](area_id)
# return the area's monster list
# of the current map
i = get_map
j = area_id
@areas[j]
end
def map_list
maps = load_data('Data/MapInfos.rxdata')
return maps.keys
end
# if you wish to know a map's id:
def get_map_id( name )
maps = load_data('Data/MapInfos.rxdata')
maps.each_key {|key|
m = maps[key]
return key if m.name == name
}
return nil
end
# id = the area number, which is the terain tag's number
def new_area(map, id, monsters )
ar = Area.new( id, monsters )
@areas[map].add(ar)
end
def setup # new, data was a normal array
@data = { 0=>[],
#=============================================================
# Configure
#-------------------------------------------------------------
#
# Each line defines the areas in one map.
# genarally, use:
# [ [area001_troops], [area002_troops] (and so on)],
# for example, the line [ [1,2], [3,4] ]
# means troops 1&2 in area 001, 3&4 in area 002.
#
# * maps not set below will have no monsters in them.
# * this can be set in an event on the map.
#-------------------------------------------------------------
# map 1
1=>[],
# map 2
2=>[],
17=>[]
# add more lines if you need
}
#=============================================================
@data.each { |map,list|
# for each map in data
for i in 0...list.size
foes = list
# i+1 gives tags 1~7
tag = i+1
new_area(map, tag, foes)
end
}
end
def get_troop
# get current area
area = $game_player.terrain_tag
return nil unless (area >= 0 and area <= 7)
# get monster list
list = self[area]
return nil if list.size==0
n = rand(list.size)
troop_id = list[n]
# If troop is valid
if $data_troops[troop_id] != nil
return troop_id
end
end
def empty_area?
area = $game_player.terrain_tag
return true unless (area >= 0 and area <= 7)
map = get_map
@areas[map].empty?(area)
end
def add(area, troop) # new - add encounters in an event
i = get_map
id = troop
@areas.add_monster(area,id)
end
end
class Scene_Title
alias areas_new_game command_new_game
def command_new_game
$monster_area = Monster_Area.new
areas_new_game
end
end
class Scene_Map
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
#=======================================================
# my edit
if $game_player.encounter_count == 0
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
#
troop_id = $monster_area.get_troop
if troop_id != nil
# Set battle calling flag
$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
#=======================================================
# 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
end
#================================================
# * Encounters
#================================================
module Encounters
module_function
def get_troop_id(name)
for id in (1...$data_troops.length)
troop = $data_troops[id]
return id if troop.name == name
end
return nil
end
def set(hash)
hash.each {|tag,troop|
for name in troop
# get id
id = get_troop_id(name)
# if such troop doesn't exist
next if id.nil?
# else
$monster_area.add(tag,id)
end
}
end
end
[/rgss]
older version (1.1)
[rgss]
#===========================================================
# ** Monster Area
#-----------------------------------------------------------
# by silver wind
# V1.0
#
# This script uses terrain tags to define areas on the map.
# each area has different monsters (encounter list).
#
# * Define a new area :
# use a tile with terrain tag (other than 0)
# simply draw on the map with it.
# notes:
# - use tags 1-7. tag 0 means no encounters
# - may not work with events with a tile graphic.
# - you can use a white tile on layer 3,
# so the area is invisible.
#
# * Add monsters to an area :
# see 'configure' below.
#===========================================================
class Area
attr_reader :id
attr_reader :monster_list
def initialize(id,list)
@id = id
@monster_list = list
end
end
class Map_Area
def initialize(map_id)
@id = map_id
@areas = {}
end
# i : area id
def [](i)
# return the area's monster list
return nil if @areas.nil?
@areas.monster_list
end
# i : area id
def add(area)
i = area.id
@areas = area
end
end
class Monster_Area
def get_map
$game_map.map_id
end
def initialize
@areas = {}
for i in map_list
@areas = Map_Area.new(i)
end
setup
end
def [](area_id)
# return the area's monster list
# of the current map
i = get_map
j = area_id
@areas[j]
end
def map_list
maps = load_data('Data/MapInfos.rxdata')
return maps.keys
end
# returns a map's id:
def get_map_id( name )
maps = load_data('Data/MapInfos.rxdata')
maps.each_key {|key|
m = maps[key]
return key if m.name == name
}
return nil
end
# id = the area number, which is the terain tag's number
def new_area(map, id, monsters )
ar = Area.new( id, monsters )
@areas[map].add(ar)
end
def setup
data = [ [],
#=============================================================
# Configure
#-------------------------------------------------------------
#
# Each line defines the areas in one map.
# genarally, use:
# [ [area001_troops], [area002_troops] (and so on)],
# for example, the line [ [1,2], [3,4] ]
# means troops 1&2 in area 001, 3&4 in area 002.
# map 1
[ [2], [3,4] ],
# map 2
[],
# add more lines if you need
]
#=============================================================
for i in 1...data.size
foes = data
for j in 0...foes.size
foe_list = foes[j]
# turn 0-7 to 1-8
k = j+ 1
new_area(i, k, foe_list)
end
end
end
def get_troop
# get current area
area = $game_player.terrain_tag
return nil unless (area >= 0 and area <= 7)
# get monster list
list = self[area]
n = rand(list.size)
troop_id = list[n]
# If troop is valid
if $data_troops[troop_id] != nil
return troop_id
end
end
end
class Scene_Title
alias areas_new_game command_new_game
def command_new_game
$monster_area = Monster_Area.new
areas_new_game
end
end
class Scene_Map
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
#=======================================================
# my edit
if $game_player.encounter_count == 0
unless $game_system.map_interpreter.running? or
$game_system.encounter_disabled
#
troop_id = $monster_area.get_troop
if troop_id != nil
# Set battle calling flag
$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
#=======================================================
# 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
end
[/rgss]
If you have any questions, feel free to ask