=begin #=============================================================================== Title: Custom Map Encounters Author: Hime Date: Jan 29, 2015 URL: -------------------------------------------------------------------------------- ** Change log Jan 29, 2015 - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Credits to Hime Works in your project * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to customize random encounters on your maps during the game. For example, initially there might be slime and rats wandering around the map, but after certain events take place in the game, the rats disappear and there will only be slime left. To accomplish this, you would start with slime and rats as possible random encounters, but then afterwards you would remove the rat encounter from the list. -------------------------------------------------------------------------------- ** Installation In the script editor, place this script below Materials and above Main -------------------------------------------------------------------------------- ** Usage -- Encounter ID -- You will need to understand the concept of an "encounter ID". This is basically a number or a name that you give to your encounters. By default, this script uses numbers to assign ID's. The encounters that you have assigned to the map in the editor are the default encounters, and they are given ID's based on the order they appear on the list. The first encounter is ID 1, the second is ID 2, and so on. Custom encounters are encounters that you add during the game via script calls. You can give them any ID you want. For example, if you have an encounter with two slimes, you can literally call it "two slimes". The purpose of the encounter ID is to make it easier for you to reference the encounter later on such as if you wanted to delete it. -- Adding Encounters -- To create an encounter, make the script call add_encounter(enc_id, troop_id, weight) add_encounter(enc_id, troop_id, weight, regions) add_encounter(enc_id, troop_id, weight, regions, map_id) `enc_id` is the ID of the encounter. `troop_id` is the ID of the troop that the player will battle if they run into this encounter `weight` is the chance that this encounter will be selected, as a weighted probability. `regions` is a list of regions that this encounter will appear in. You can limit the encounter to only appear in the regions. If the regions are omitted, then it assumes you can encounter them anywhere on the map. `map_id` is the map you want to add this encounter to. If this is omitted, it assumes you are adding it to the current map -- Removing Encounters -- To remove an encounter, make the script call remove_encounter(enc_id) remove_encounter(enc_id, map_id) This will remove the encounter specified by your enc_id. If the map ID is omitted, it assumes you are removing the encounter from the current map. #------------------------------------------------------------------------------- ** Example Suppose your map initially has no encounters. You then decide to add troop 1 as an encounter, appearing only in the swamp (region 1) with a weight of 50 Let's give it the ID "swamp_monster" You would make the script call add_encounter("swamp_monster", 1, 50, [1]) If you want to remove this encounter, you can make the script call remove_encounter("swamp_monster") And you will not encounter it again in the swamp. Let's say you wanted to add troop 2 as an encounter, appearing anywhere, with a weight of 20. The idea here is that if you're walking in the swamp, there is a higher chance of encountering troop 1. We'll just give it an ID of 12 because it's a random number that is not taken. add_encounter(12, 2, 20) Here, we omitted the regions because we don't need it. Again, if you want to remove this encounter, you can use the script call remove_encounter(12) #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_CustomMapEncounters"] = true #=============================================================================== # Rest of Script #=============================================================================== class Game_System def encounters(map_id) @encounters ||= {} @encounters[map_id] ||= Data_MapEncounters.new end end class Data_MapEncounters attr_reader :initialized attr_accessor :encounter_step def initialize @initialized = false @encounter_step = 0 @encounters = {} end def setup(map) @initialized = true @encounter_step = map.encounter_step map.encounter_list.each_with_index do |enc, id| @encounters[id+1] = enc end end def add(id, troop_id, weight, regions) enc = RPG::Map::Encounter.new enc.troop_id = troop_id enc.weight = weight enc.region_set = regions @encounters[id] = enc end def remove(id) @encounters.delete(id) end def encounter_list @encounters.values end end class Game_Map # Overwrite def encounter_list @encounter_data.encounter_list end # Overwrite def encounter_step @encounter_data.encounter_step end alias :th_custom_map_encounters_setup :setup def setup(map_id) th_custom_map_encounters_setup(map_id) setup_encounters(map_id) end def setup_encounters(map_id) @encounter_data = $game_system.encounters(map_id) unless @encounter_data.initialized @encounter_data.setup(@map) end end end class Game_Interpreter def add_encounter(id, troop_id, weight, regions=[], map_id=$game_map.map_id) $game_system.encounters(map_id).add(id, troop_id, weight, regions) end def remove_encounter(id, map_id=$game_map.map_id) $game_system.encounters(map_id).remove(id) end def add_encounter_step(val) $game_system.encounters(map_id).encounter_step += val end def set_encounter_step(val) $game_system.encounters(map_id).encounter_step = val end end