Changing Encounters
Version: 1.0
Author: Logan Forrests
Date: July 26, 2011
Version History
- <Version 1.0> 2011.07.26 - Original Release
Planned Future Versions
- <Version 1.1> Allow changing of encounter rate of battles
- <Version 1.2> Allow multiple maps to be changed simultaneously
Description
This script allows you to change what monster troops are encountered on any given field map in the game. Changes are made through simple calls using the "Script..." command in an Event or a Common Event.
Features
Change the Enemy Troops encountered on any given map by:
- Setting a completely new encounter list - this will take priority over the default encounter list set in Map Properties.
- Adding Enemy Troops to a custom set encounter list or even the default encounter list if you so wished - perhaps you wanted to add a random boss encounter during a specific part of your game.
- Removing Enemy Troops from a custom set encounter list or even the default encounter list if you so wished - you want that random boss encounter to no longer happen.
- Restore default encounter list.
- No More Encounters - makes it so that the player will not encounter any more enemies on a specified map.
Instructions
Script contains a Description section.
Script
#-------------------------------------------------------------------------
#Logan Forrests' Changing Encounters Script for RMXP
#
# Date Created : 26 July 2011
# Date Finished : 26 July 2011
# Last Updated : 26 July 2011
# Latest Version : 1.0
#
#--------------------------------------------------------------------------
# Version History
#--------------------------------------------------------------------------
# v 1.0
# Allows for customization of the encounters faced on field maps.
#
#--------------------------------------------------------------------------
# Description
#--------------------------------------------------------------------------
# This script allows you to change what monster troops are encountered
# on any given field map in the game. The only information required
# for this script to work is an array of Battle Troop IDs. Optional
# information includes providing a map ID, should you wish to change a
# specific map's encounter list.
#
# These calls can be made using the "Script..." in an Event or Common Event.
#
# There are 5 different operations that can be peformed:
# set_encs(troop_ids, map_id)
# - lets you set an array of Troop IDs
# add_encs(troop_ids, map_id)
# - add Troop IDs to encoutner list (be it custom or default)
# remove_encs(troop_ids, map_id)
# - remove Troop IDs from encoutner list (be it custom or default)
# restore_encs(map_id)
# - restores the default list of encounters for specified map
# Note: this means the default encounter list will be used
# no_encs (map_id)
# - no encounters will occur on the specified map
#
# * troop_ids are required and must be provided in the form of an array.
# ** map_ids for these calls are optional. If no map id is specified, the
# map id for the current map will be used.
#
# Examples:
# Assuming Map001 (map_id == 1) has the default encounter list with
# Troop IDs [1, 2, 3] (meaning that Troops with database IDs 1, 2 and 3
# can be encountered on Map001):
#
# set_encs([1, 3, 4, 5], 1)
# : This call will make it so that Troops with database IDs 1, 3, 4, 5
# can be encounted. Troop with ID 2 will not be encountered until
# it is either added to the list using the add_encs call or
# delete_encs(1) is called (where 1 is the map_id we want to remove
# the custom entry).
#
# add_encs([4, 5], 1)
# : This call will make it so that Troops with database IDs, 1, 2, 3
# 4 and 5 can now be encountered on Map001.
#
# remove_encs([1, 2], 1)
# : This call will remove Troop IDs 1 and 2 from the encounter list.
# Thus, Map001 will only contain Troop with ID 3 as an encounterable
# Troop.
#
# restore_encs(1)
# : This call will delete the custom encounter list for Map001.
# If this is used after remove_encs([1, 2], 1) has been called,
# the player will then be able to encounter troops from the default
# list - thus they will now encounter Troops 1, 2 and 3 again.
#
# no_encs(1)
# : This will remove any custom encounter list for Map001.
# Unlike restore_encs, however, it will also prevent the player
# from encountering any troops in the default list. Thus they will
# not get any encounters on Map001.
# To restore the default encounter list after no_encs has been used,
# you can simply use restore_encs to return to the default list.
#
# Please Note:
# Because this data is stored in $game_system, it will be saved whenever the
# player uses a save point. Thus, as the game developer it is advised that you
# take careful notes of which maps have had their default encounter lists
# changed, in the event that you require to restore them or change them at a
# later stage of the game.
#
# If at any time during the game you need to know what changes have been made
# to the encounters list you can use the "Script..." command in an
# Event/Common Event and calling:
# show_map_encs
#
# This will display the hash contents. They will be shown in the form:
# map_id => [troop_ids]
#--------------------------------------------------------------------------
# Script Installation
#--------------------------------------------------------------------------
# In materials above Main.
#
#--------------------------------------------------------------------------
# Support
#--------------------------------------------------------------------------
# The script has been written and tested with no other scripts in place. As
# such, if you encounted any issues with regards to other scripts,
# first try to resolve the problem by moving this script around. If you are
# still unable to resolve the problem, feel free to contact me on rmrk.net
# under the name LoganForrests (no spaces involved) with the name of the
# script(s) you find no longer work when this script is included and the
# nature of the problem(s) so that I can begin to work on the problem(s)
# being caused.
#
#--------------------------------------------------------------------------
# Thanks
#--------------------------------------------------------------------------
# For the idea to write the script:
# cometstar
#--------------------------------------------------------------------------
# Changing Encounters for RMXP by Logan Forrests is licensed under a
# Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#--------------------------------------------------------------------------
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
class Game_System
attr_accessor :custom_map_enc_h #Hash holding Map Encounter Lists that differ
# From the predefined list set in Map Props.
# Key = Map ID
# Value = Array of Battle Troop IDs
alias lf_init_gs initialize
def initialize
#run original method
lf_init_gs
#Perform additional tasks
#Create an empty hash for reader variable @custom_map_enc_h
@custom_map_enc_h = Hash.new
end
#-----
# Sets a new key and value in @custom_map_enc_h hash
# If key already exists, key is deleted and new key + value added
#-----
def set_encounter_list(troops, map_id_l)
@custom_map_enc_h.delete(map_id_l) if @custom_map_enc_h.include?(map_id_l)
@custom_map_enc_h[map_id_l] = troops
end
#-----
# Adds additional troops to current custom list. If not defined,
# set_encounter_list is called to create a new entry using the default
# encounter list as base list.
#-----
def add_to_encounter_list(troops, map_id_l)
if @custom_map_enc_h.include?(map_id_l) #if defined
old_troops = @custom_map_enc_h[map_id_l]
else #otherwise, make a new list with default as base
#load map data into local variable
map = load_data(sprintf("Data/Map%03d.rxdata", map_id_l))
#get default encounter list and add troops to make new_troops
old_troops = map.encounter_list
end
new_troops = old_troops + troops
set_encounter_list(new_troops, map_id_l)
end
#-----
# Removes specified troops from encounter list. If no custom list has already
# been defined, it will create a new custom entry using the default as base
# and removing specified troops from this base list.
#-----
def remove_from_encounter_list(troops, map_id_l)
if @custom_map_enc_h.include?(map_id_l)
old_troops = @custom_map_enc_h[map_id_l]
else
#load map data into local variable
map = load_data(sprintf("Data/Map%03d.rxdata", map_id_l))
#get default encounter list and add troops to make new_troops
old_troops = map.encounter_list
end
new_troops = old_troops - troops
set_encounter_list(new_troops, map_id_l)
end
#-----
# Deletes the custom list entry belonging to the specified map_id. If not
# defined, returns and does nothing more.
#-----
def restore_custom_encounter_entry(map_id_l)
return unless @custom_map_enc_h.include?(map_id_l)
@custom_map_enc_h.delete(map_id_l)
end
#-----
# Simulates no encounters by deleting any custom entry for the map_id and
# assigning an empty array
#-----
def no_encounters(map_id_l)
@custom_map_enc_h.delete(map_id_l) if @custom_map_enc_h.include?(map_id_l)
@custom_map_enc_h[map_id_l] = []
end
end #class Game_System
class Game_Map
alias lf_encounter_list_gm encounter_list
def encounter_list
#Check whether @custom_map_enc_h contains map id and thus a different
#encounter list to return
if $game_system.custom_map_enc_h.include?(map_id)
return $game_system.custom_map_enc_h[map_id]
else
#run original method to get default/preset enc list
lf_encounter_list_gm
end #if/else
end #def
end #class Game_Map
class Interpreter
#If no map_id is specified, the current map the player is on is used.
#Creates entry - deletes entry if one exists before creating new entry
def set_encs(troops, map_id = $game_map.map_id)
$game_system.set_encounter_list(troops, map_id)
end
#Adds troops to encounter list
# If entry exists, adds troops to current list
# If no entry exists, adds troops to default map encounters and makes new entry
def add_encs(troops, map_id = $game_map.map_id)
$game_system.add_to_encounter_list(troops, map_id)
end
#Removes troops from encounter list
# If entry exists, removes troops from current list
# If no entry exists, removes troops from default map encounters and makes new
# entry
def remove_encs(troops, map_id = $game_map.map_id)
$game_system.remove_from_encounter_list(troops, map_id)
end
#Deletes the entry from custom_map_enc_h hash in $game_system
# Does nothing if entry does not exist.
# ONLY AFFECTS CUSTOM ENTRY ! DOES NOT AFFECT DEFAULT MAP ENCOUNTERS
def restore_encs(map_id = $game_map.map_id)
$game_system.restore_custom_encounter_entry(map_id)
end
#Makes an empty value entry for the specified map
# If entry exists, removes all troops from associated list
# If no entry exists, makes an empty encounter list for the specified map
def no_encs(map_id = $game_map.map_id)
$game_system.no_encounters(map_id)
end
#Prints out the encounter list entries
def show_map_encs
p "Map ID => [Troop IDs]", $game_system.custom_map_enc_h
end
end
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
# D O N O T E D I T A N Y T H I N G I N T H I S S C R I P T
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - #
Credit
Thanks
- Cometstar - original request/idea
Support
See the Support section of the script.
Known Compatibility Issues
None Known at this time.
Demo
None included - it'd be mostly a lot of printed out windows if anything.
Author's Notes
First script released for XP. It works as intended as far as I can see/tell from my own tests. There's a few places I'd like to tidy up, but that'll be saved for a future update, should I get around to them.
I'll likely convert it over to VX too, as it may be useful for my own project.
Restrictions
Changing Encounters by Logan Forrests is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.