I'm looking to change random encounter parameters

It might not take a script because I'm not wanting something ground breaking (hopefully), but I want to know where in the base script I can access the following:

1) the probability density function of random encounters, and how can I change it to another function if preferred

2) the expected value of random encounters i.e. number of steps per encounter

3) the variance of random encounters

If I am unable to do the above without having to add something to Materials, I'd be grateful for a script.
I believe you can do all of what you're asking by using the stock RPGM engine, if I'm reading what you want correctly.

Go into a map edit screen and all of those options should be on the right-hand side.
1. Game_Player#make_encounter I think


2. Game_Map#encounter step


3. Probably stick that into encounter step
1. Game_Player#make_encounter I think

2. Game_Map#encounter step

3. Probably stick that into encounter step
Thanks for the info. Looking at the code, it seems like the game rolls two n-sided dice from 0 to n (n = input in the map properties tab), takes the sum, and adds 1 to it. Then when the player appears, once they have taken this many steps, an encounter occurs. Is that correct?

Fore reference:

Code:
#--------------------------------------------------------------------------  # * Get Encounter Steps  #--------------------------------------------------------------------------  def encounter_step    @map.encounter_step  end
Code:
#--------------------------------------------------------------------------  # * Create Encounter Count  #--------------------------------------------------------------------------  def make_encounter_count    n = $game_map.encounter_step    @encounter_count = rand(n) + rand(n) + 1  end
Not quite.  This gives the average number of steps before the next encounter, not the actual nor the minimum.  That is why you can have the "3 steps and there's a battle" problem.

Here is how I deal with the variance of random encounters

I first create a variable.  For the sake of this example, let us say it will be variable switch #5.

Then in the snippet that you quote for Create Encounter count amend line #195 so that it reads:

@encounter_count = rand(n) + rand(n) + 1 + $game_variables[5]

What this does is to add the amount you set in variable 5 to the encounter count.  This will increase the average by that amount and ensure that many steps have been taken before a battle.

At the very beginning of the game, include this switch in the opening event.  Turn it ON and set it to an appropriate figure.  I set mine to 25.  That ensures that the player will always take at least 25 steps before the next battle.  You now have your minimum, and encounters will tend to happen at around that minimum number.
Thanks for the info. Looking at the code, it seems like the game rolls two n-sided dice from 0 to n (n = input in the map properties tab), takes the sum, and adds 1 to it. Then when the player appears, once they have taken this many steps, an encounter occurs. Is that correct?
Pretty much.


Once the count is generated, that's how many steps you can take before an encounter occurs.
Not quite.  This gives the average number of steps before the next encounter, not the actual nor the minimum.  That is why you can have the "3 steps and there's a battle" problem.

Here is how I deal with the variance of random encounters

I first create a variable.  For the sake of this example, let us say it will be variable switch #5.

Then in the snippet that you quote for Create Encounter count amend line #195 so that it reads:

@encounter_count = rand(n) + rand(n) + 1 + $game_variables[5]

What this does is to add the amount you set in variable 5 to the encounter count.  This will increase the average by that amount and ensure that many steps have been taken before a battle.

At the very beginning of the game, include this switch in the opening event.  Turn it ON and set it to an appropriate figure.  I set mine to 25.  That ensures that the player will always take at least 25 steps before the next battle.  You now have your minimum, and encounters will tend to happen at around that minimum number.
But that makes no sense. Why would the computer randomly generate an average for the average number of steps? Plus, if you take the expected value of the hard code, you find that the expected value is n+1. Since it only makes sense to count from 0 in computer language, the +1 is just there for translating it into natural numbers.

Hence, the expected value of encounters would be what you entered (+1) in the map properties tab. In any case, going through the process of finding the expected value of the hard code answered my question about its behavior, so this topic is now solved.
Maybe I wasn't too clear in the thinking behind my suggestion.

My point was that yes, the computer randomly generates an average, but unfortunately the way that RM does it you often end up with what I called the "3 steps and there's a battle" problem.  Although you might set 30 or 40 as the average number of steps in Map Properties, you can still end up with encounters at significantly fewer steps than the one you have specified.  This is one of the reasons why random encounters are so disliked by many players.  The point of the method I suggested is that it prevents encounters at low step counts.

Original thread: https://forums.rpgmakerweb.com/threads/im-looking-to-change-random-encounter-parameters.35110/