hmmm... probably something like this
def make_encounter_count if $game_variables[30] == 0 @encounter_count = 9999999 else n = $game_map.encounter_step/$game_variables[30] @encounter_count = rand(n) + rand(n) + 1 end endso, as the value of the variable goes up, the probability to have encounters become higher (since you now randomize from a smaller range), but since dividing by zero will cause error, we simply give it a different value when it's 0... in this case a very high number...you can change that 1 into another digit that you want to set as "minimum number of steps" for an encounter to happen for reasons as explained by Racheal below...
The way the formula works by default is as follows:
n is set to whatever "Steps Average" you set the map to.
rand(n) will get a random number between 0 and n-1.
So if you set the map to 30 steps average, @encounter_count will be set to a number between 1 and 59, with a slight preference towards to middle. Think of it like rolling two thirty-sided dice.
While I was typing that up, Shana replied, so see that reply for the actual script change. I'm posting this anyway so you can understand how the formula works. If you're changing it anyway for your script, you might consider improving it since as I pointed out, it is possible to have an encounter every single step with the current formula.
You might consider something like the following:
def make_encounter_count n = $game_map.encounter_step d = $game_variables[30] @encounter_count = d == 0 ? 99999 : rand(n) + ((3 - d) * n)/2 + 1 endWith this formula and a Steps Average of 30, you'd see an encounter in:1: 30-59
2: 15-44
3: 1-29
Okay, Shana's script didn't have any crashes or anything, but now there are no encounters at all, even when the variable is set to 3.
EDIT: It seems the script is causing it to get stuck on
if $game_variables[30] == 0@encounter_count = 9999999even if the variable is set to something other than 0. It's like it ignores the rest of the script.
You're going to need to change the change_custom_variables method in Yanfly's options script:
#-------------------------------------------------------------------------- # change_custom_variables #-------------------------------------------------------------------------- def change_custom_variables(direction) Sound.play_cursor value = direction == :left ? -1 : 1 value *= 10 if Input.press?🙂A) ext = current_ext var = YEA::SYSTEM::CUSTOM_VARIABLES[ext][0] minimum = YEA::SYSTEM::CUSTOM_VARIABLES[ext][4] maximum = YEA::SYSTEM::CUSTOM_VARIABLES[ext][5] $game_variables[var] += value $game_variables[var] = [[$game_variables[var], minimum].max, maximum].min $game_player.make_encounter_count if var == 30 #new line draw_item(index) endYou might also want to check out the edit to my initial post above. I made some suggestions about the encounter rate formula.[Edit] Changed my mind on this a little. Now it recalculates the encounter rate every time you change it instead of just when changing from 0.
Put my edited script first, so that it won't do the 999999 thingy for the game set-up, then add Racheal's code so that it auto-updates the encounter count when you change variables...
@Racheal - I think you should remove the and old_val == 0, so that it will reset everytime the variable is changed, which is actually needed for it to work correctly... coz right now, if I use 3 then I reset it to zero, the encounter rate won't reflect that change immediately and will only reflect once an encounter has happened... 🙂
@Shana: your new script gave me an error about dividing by zero. 🙁
@Rachael: I will try that ...
ah wait, do this:
def make_encounter_count if $game_variables[30] == 0 if $game_switches[id] #so that it doesn't run on start game @encounter_count = 9999999 else n = $game_map.encounter_step/1 @encounter_count = rand(n) + rand(n) + 1 $game_switches[id] = true end else n = $game_map.encounter_step/$game_variables[30] @encounter_count = rand(n) + rand(n) + 1 end endAssuming 1 is your default value for the variable... then get Racheal's code, but probably remove the and old_val == 0 part as I explained aboveand of course make sure to change the id into the id of the switch that you will be using...
My second snippet alone will not get the results you want. It was made just to address the updating encounter rate issue. You'll want to include either Shana's first snippet or my first one.
@Shana: Yeah, I realised that and had already edited it. For some reason my brain was stuck on "if you re-calculate the encounter rate every time, they could use it to avoid battles!!" Yeah, sometimes my brain is really dumb.
Also, you shouldn't need that switch stuff with my auto-update code?
Ah, that is true, though assuming the first map has encounters (which it's possible it does not), you could just call $game_player.make_encounter_count after you set the variable. It doesn't seem worth the use of a switch to me.
Okay, problem solved! I used Rachael's updated snippet with Shana's way WITHOUT the switch and now it works perfectly! Setting the variable to 0 causes no encounters, even when i set the average steps to 1. Yay!
Yanfly's probably run the default set-up somewhere, so it ran Racheal's code... XD
Take note that it will still cause an encounter, after 9999999 steps on that map... 🙂
Yes, I realize that haha ... although I very much doubt someone will do that xD