Variable Random Encounter Rates

Is there a plugin that lets you:

1) Set different encounter rates for different regions on the same map?
2) Alter the encounter rates for individual maps during the game, for instance in response to switches triggered by the player's actions?

MV lets you choose the troops for random encounters for any map by region. By not selecting troops for a region it is possible to have parts of the map free from random encounters. MV also lets you turn all random encounters on or off. However, each region of a map that has enemy troops will have the same encounter rate, which can't be altered, as far as I am aware.

The type of scenario that I have in mind is a map with the main roads or paths being fairly safe with few encounters. Going off onto minor roads or paths gives increased risk of random encounters, which becomes a high risk if you search the undergrowth or urban back alleys.

One possible solution in the absence of such a plugin might be to use common events in conjunction with the Yanfly plugin that can call common events whenever the player steps on specific regions. This would mean replicating much of facilities given by MV for random encounters, though.
I could probably whip up something like this using notetags in the map properties.

Edit: Here. Pretty quick and dirty, but I also added the ability to determine encounter rate by variable value, and it recalculates encounter steps as soon as your region changes.

Code:
//=============================================================================
// RegionEncounters.js
//=============================================================================

/*:
 * @plugindesc Allows you to use notetags in maps to specify encounter frequency
 * by region.
 * @author John Clifford (Trihan)
 *
 * @help
 *
 * Plug and play, just put <region#:##> in the map notes where # is the region ID
 * and ## is your desired encounter steps. Put a 'v' before the step number to use
 * the value in that variable for the encounter count instead.
 *
 */

(function() {
    var regex = /region\d+/
   
    _Game_Map_encounterStep = Game_Map.prototype.encounterStep;
    Game_Map.prototype.encounterStep = function() {
        var steps = _Game_Map_encounterStep.call(this);
        if (Object.keys($dataMap.meta).length > 0) {
            var keys = Object.keys($dataMap.meta).filter(function(key) {
                return key.match(regex);
            });
            if (keys.length > 0) {
                keys.forEach(function(key) {
                    var variableMode = false;
                    if ($dataMap.meta[key].startsWith('v')) { variableMode = true; }
                    var region = Number(key.match(/\d+/)[0]);
                    if (region === $gamePlayer.regionId()) {
                        var count = Number($dataMap.meta[key].match(/\d+/)[0]);
                        steps = variableMode ? $gameVariables.value(count) : count;
                        return true;
                    }
                });
            }
        }
        return steps;
    };
   
    _Game_CharacterBase_moveStraight = Game_CharacterBase.prototype.moveStraight;
    Game_CharacterBase.prototype.moveStraight = function(d) {
        var currentRegion = $gamePlayer.regionId();
        _Game_CharacterBase_moveStraight.call(this, d);
        if (currentRegion !== $gamePlayer.regionId()) {
            $gamePlayer.makeEncounterCount();
        }
    };
})();
Wow! Thank you ever so much. I will try it out this afternoon.🙂

Edit: Yes, it seems to work well, including the option to have the rate for regions controlled by a variable. The test project that I tested it in has a lot of other plugins enabled, so I think that it would work in most setups. (Note for anyone else who tries it - I used it at the bottom of the plugin list.)

Thanks again.

Edit 2: @Trihan - Did you want to quote terms of use? I can't imagine that I would ever release anything commercial, but it is possible that someone else might find this plugin useful. I believe that I am supposed to let the Mods know once this thread is solved; I will wait a while before I do so, in case you want to specify terms of use.
Glad it works well for you. 🙂 If you need any other functionality from it give me a shout.
@Trihan I don't think that tagging works in an edit, so you may have missed the request to specify terms of use. I will leave this thread open to give you a chance to do that.
I don't think it does either @Kes ; terms of use are the same as all my other scripts/plugins: use it for whatever you want, reverse engineer it, break it apart, edit it, distribute it and claim you made it, I couldn't care less (maybe don't do that last one). It's free to use for any kind of project, commercial included. Credit would be appreciated but isn't strictly necessary. If you do use it in a commercial project and make a crapload of money on it because everyone thought your variable encounter rate was the greatest thing since sliced bread, feel free to share some of the profit with me.

TL;DR - I don't really do terms of use with my stuff, do with it as ye will.
TL;DR - I don't really do terms of use with my stuff, do with it as ye will.
That already is a "terms of use" - it just needs to be stated as such, but "do with it as ye will" does count as TOS when stated.

Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/variable-random-encounter-rates.75084/