Friday, November 21, 2014

Adjusting Encounter Rate

On every map in an RPG Maker VX Ace project, you can specify the average number of steps between random enemy encounters (on regions designated for random encounters), in the Map Properties window (below where you assign troops to each region). This gives you some level of control over how often a player will run into random encounters, but the formula the program uses to calculate the number of steps between any two given encounters leaves much to be desired. This formula can be found in the script editor on line 195 of Game_Player, and is as follows:
@encounter_count = rand(n) + rand(n) + 1
where "@encounter_count" is the number of steps until the next encounter, and "n" corresponds to the average number of steps between encounters that you specify in the Map Properties window on any given map. This formula calculates a random number from 1 to twice the average steps (plus 1) you've given the map. That means that on a map that you've chosen the average steps between encounters to be 20, for example, you could go anywhere from just a single step to as many as 41 steps before your next encounter. Quite frankly, I think that's too much variance, and especially on the low side, only being able to get a few steps between encounters is pretty frustrating.

The good news is, changing the program's behavior is as simple as modifying the above formula. Feel free to let your imagination run wild. A simple alternative that I'm using for the time being is as follows:
@encounter_count = rand(n) + n / 2
Here, the lowest possible number of steps before the next encounter will be: not 1, but half whatever the average steps between encounters is, and the maximum will be 50% more than the average. So, if you set the average to be 20 on a map, the steps calculated between encounters will always be between 10 (half the average) and 30 (three halves of the average). There's still a lot of variance there, but this formula cuts out the really short and really long travels between encounters to make it all a bit more consistent. As I said, you can fool with the formula as much as you like.

And if you don't want to change the default code (which I wouldn't recommend), just paste this code into the Materials section (with whichever updated formula you want to use) and it will overwrite the default:
class Game_Player < Game_Character
  def make_encounter_count
    n = $game_map.encounter_step
    @encounter_count = rand(n) + n / 2
  end
end
I recommend you give it a title ("encounter adjustment", perhaps?) so you know what it does at a glance in the future. This is a nondestructive way of messing around with the scripts so that if for whatever reason you want to revert to the default, you can just delete the added code in the Materials section!

Click here for another mini-script related to random encounters.

No comments:

Post a Comment