Map : Change Encounters

Map : Change Encounters
Version: 3.5
By: Kain Nobel

Introduction

I just created this so you can change map encounter list and step values... normally, you'd probably find yourself copy/pasting duplicate maps to have different encounters, but now you don't have to! It'll give your project just a little less weight, as far as 'duplicate maps' go...

Features

  • $game_map.encounter_list = [...] will change encounter list on current map
  • $game_map.encounter_step = number will change encounter steps on current map
  • $game_map.encounter_list = nil will reset encounter list to default
  • $game_map.encounter_step = nil will reset encounter step to default
  • $game_map.encounters[map_id].list = [...] will change encounter list on specified map
  • $game_map.encounters[map_id].step = number will change encounter steps on specified map
  • $game_map.encounters[map_id].list = nil will reset specified map's encounter list to default
  • $game_map.encounters[map_id].step = nil will reset specified map's encounter step to default
  • Changes to encounters and steps are effective the second you call it!
  • Enough said... wow the features are your instructions, how odd?

Script

Map : Change Encounters Spoiler
  1. #===============================================================================
  2. # ** Map : Change Encounters
  3. #===============================================================================
  4.  
  5. #-------------------------------------------------------------------------------
  6. # * SDK Log
  7. #-------------------------------------------------------------------------------
  8. if Object.const_defined?(:SDK)
  9.   SDK.log('Map.ChangeEncounters', 'Kain Nobel ©', 3.5, '2009.06.17')
  10. end
  11.  
  12. #===============================================================================
  13. # ** Game_Map::Encounter_List
  14. #===============================================================================
  15.  
  16. class Game_Map::Encounters
  17.   #-----------------------------------------------------------------------------
  18.   # * Public Instance Variables
  19.   #-----------------------------------------------------------------------------
  20.   attr_accessor :list
  21.   attr_accessor :step
  22.   #-----------------------------------------------------------------------------
  23.   # * Object Initialization
  24.   #-----------------------------------------------------------------------------
  25.   def initialize
  26.     @list = nil
  27.     @step = nil
  28.   end
  29. end
  30.  
  31. #===============================================================================
  32. # ** Game_Map
  33. #===============================================================================
  34.  
  35. class Game_Map
  36.   #-----------------------------------------------------------------------------
  37.   # * Public Instance Variables
  38.   #-----------------------------------------------------------------------------
  39.   attr_reader :encounters
  40.   #-----------------------------------------------------------------------------
  41.   # * Alias Listings
  42.   #-----------------------------------------------------------------------------
  43.   alias_method :chgencounters_gmmap_setup,          :setup
  44.   alias_method :chgencounters_gmmap_encounterlist,  :encounter_list
  45.   alias_method :chgencounters_gmmap_encounterstep,  :encounter_step
  46.   #-----------------------------------------------------------------------------
  47.   # * Setup
  48.   #-----------------------------------------------------------------------------
  49.   def setup(map_id)
  50.     @encounters ||= Hash.new
  51.     chgencounters_gmmap_setup(map_id)
  52.     @encounters[map_id] ||= Game_Map::Encounters.new
  53.   end
  54.   #-----------------------------------------------------------------------------
  55.   # * Reset Encounters
  56.   #-----------------------------------------------------------------------------
  57.   def reset_encounters
  58.     encounter_list = @map.encounter_list
  59.     encounter_step = @map.encounter_step
  60.   end
  61.   #-----------------------------------------------------------------------------
  62.   # * Encounter List
  63.   #-----------------------------------------------------------------------------
  64.   def encounter_list
  65.     unless @encounters[map_id].list.is_a?(Array)
  66.       old_list = chgencounters_gmmap_encounterlist
  67.       @encounters[map_id].list = old_list
  68.     end
  69.     @encounters[map_id].list
  70.   end
  71.   #-----------------------------------------------------------------------------
  72.   # * Encounter Step
  73.   #-----------------------------------------------------------------------------
  74.   def encounter_step
  75.     unless @encounters[map_id].step.is_a?(Numeric)
  76.       old_step = chgencounters_gmmap_encounterstep
  77.       @encounters[map_id].step = old_step
  78.       $game_player.make_encounter_count
  79.     end
  80.     @encounters[map_id].step
  81.   end
  82.   #-----------------------------------------------------------------------------
  83.   # * Encounter List = (list)
  84.   #-----------------------------------------------------------------------------
  85.   def encounter_list=(list)
  86.     unless list.is_a?(Array) || list.is_a?(NilClass)
  87.       err  = "Wrong argument for changing $game_map.encounter_list\n\nThe argum"
  88.       err += "ent must be an :Array: (or :NilClass: object to reset), not a "
  89.       err += ":#{list.class}:"
  90.       raise ArgumentError.new(err)
  91.     end
  92.     @encounters[map_id].list = list
  93.   end
  94.   #-----------------------------------------------------------------------------
  95.   # * Encounter Step = (step)
  96.   #-----------------------------------------------------------------------------
  97.   def encounter_step=(step)
  98.     unless step.is_a?(Numeric) || step.is_a?(NilClass)
  99.       err  = "Wrong argument for changing $game_map.encounter_step\n\nThe argum"
  100.       err += "ent must be a :Numeric: (or :NilClass: object to reset), not a "
  101.       err += ":#{step.class}:"
  102.       raise ArgumentError.new(err)
  103.     end
  104.     @encounters[map_id].step = step
  105.     $game_player.make_encounter_count
  106.   end
  107. end
  108.  
Expand to see the code.


Compatibility

Wow, this doesn't require SDK? How cool... however, this corrupts old save files, just to let'cha know!

This script aliases the following methods... Spoiler
Game_Map.encounter_list
Game_Map.encounter_step

This script creates the following methods... Spoiler
Game_Map.encounter_list=
Game_Map.encounter_step=


Donno if this works for VX but maybe it does? I do recall VX using "areas" to define encounters, so I'm guessing that could be an issue, but I'm just making a general assumption that for some reason it might not work in VX. Either way, I have VX so if you need a version made for it then I'll see what I can do for ya!

Credit and Thanks

Armor King 108 : Reporting some issues I overlooked in the first couple of posts, thank you! :thumb:

Author's Notes

I want at least ONE reply, even if you find no bugs whatsoever and think this is great one reply will make me want to post more simple mini-scripts! If I get more replies on stuff, I'll start posting the more extravagant stuff I've been holding out on ;)

Terms and Conditions

Another "Free to use in commercial and non-commercial releases" script, but credit is required thanks ;)
Is this different than the other Map : Change Encounters script you posted about 3 days ago? It looks like there are more features now, but I'm not sure. Anyway, I haven't tried it out yet, but it sounds neat. Currently, unless I'm using a world map, I probably wouldn't use a script like this much. I used to want to do all kinds of crazy things, but spending so much time not actually making RPGs discourages me from trying all the interesting things I used to try to do. Well, I could also use this for a map that has different enemies later in the game...

Oh wait! How does this script work with Parallel Process events? Could you have a parallel process event that changes the enemy party's every few seconds? Or an item or spell that temporarily replaces all enemy parties with a specific weak monster? Couldn't you also have an ability that temporarily changes the encounter rate? Hmmm...I may try this out soon after all.

(by the way, I like all your scripts that I've seen, I'm looking forward to seeing more!)
I tried it out and it seemed to be working fine. Well, except for two major problems.

First of all, I tried making a parallel process common event that only worked when a certain switch was on. While testplaying I could use F9 to turn the switch on and test it out. The common event changed the encounters to enemy parties 1, 2, and 3...and after 200 frames it turned it back to normal. However, while the switch was off I couldn't fight any random encounters. While it was on, it worked perfectly! But after 200 frames on the map (10 seconds I think) when it was supposed to reset the encounter list and turn off the switch, it caused an error, this error:

Image

Is it because I was using a parallel process event, I messed something up, or is it something else? Any help would be greatly appreciated!

EDIT: (Oops, I wanted to edit my previous post with this information, not make a new post! Sorry!)
I've updated the script, thanks for pointing out the bug I forgot one part of the method lol! Go ahead and hit Refresh and replace the version you have with this one, it should work fine now (yes, you can assign nil to reset encounters and steps now yay!)

Quote:
Is this different than the other Map : Change Encounters script you posted about 3 days ago?


Did I really already post this o.O ? I'm sorry if I did then I'll have to report the old one so a mod can lock/delete it.
It doesn't freeze anymore, but I can't fight any battles until activating a call script for Map : Change Encounters. I tried moving the script around different parts in the script zone (different places above Main, I'm using about 3 other scripts, though I don't think they are interfering)

I'm so confused. I don't understand scripts at all...:(
Another small thing I overlooked, Game_Map::Encounters @list = Array.new should be @list = nil, so that it loads the old list from the MapXXX.rxdata file.

I also adjusted two lines in the Game_Map#encounter_list and #encounter_step methods, which would drop the frame rate 2 points, now it runs at a steady 40 again. Go ahead and just copy/replace the old one you have with the updated version in the post above.

Thanks for reporting that Armor King 108, now you're in the Credit and Thanks section! :thumb:
very handy script! I never understood why some scripter didn't make this earlier :p
Cool! It's working perfectly now. I didn't notice any problems at all.

I never expected to be in the Credits/Thanks section of a script! Interesting. Glad I could help.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=65663