Static Encounter Region Restriction Question

Hi Guys,

i try to do a static encounter on the map. he move "random" and had a chaseplayer script, if im near.
I dont want that my static encounter walks randomly over the whole map, so i did a region restriction. but if hes chasing me, i want that he can overcome this restriction and if he not caught me, he runs back into the his "jail", enclosed with the region number. sorry for my bad english, i hope you understand what i mean
greetings
How do you make the event stay inside one area? Are you using a plugin?
Yes, RegionRestrictions from Yanfly 🙂
with <Event Restrict Region: 10> on my Map Note and around the enemy events "10".
push
It's awkward because I don't think Yanfly's plugin allows for modification of regions or their behaviours mid-game. Doesn't look like anyone else has any ideas, though, so I wrote a little alternative plugin you can try, see attachment (full code in spoiler below).
Spoiler: Full plugin code
JavaScript:
/*:
 * @plugindesc Restrict characters to a specific region.
 * @author Caethyril
 * @help Use this script call to set/get an event's restriction region:
 *        $gameMap.event(X)._stayInRegion = Y;
 *   e.g. $gameMap.event(5)._stayInRegion = 10;
 *     This will make event 5 unable to move outside of region 10.
 *     If they are already outside, they will move freely until moving inside.
 *     This is ignored for events chasing the player (YEP_EventChasePlayer).
 */

(function(alias) {
'use strict';
    const PROP = '_stayInRegion';
    Game_CharacterBase.prototype.canPass = function(x, y, d) {
        const region = this[PROP];
        if (region && this.regionId() === region && !this._chasePlayer) {
            const x2 = $gameMap.roundXWithDirection(x, d);
            const y2 = $gameMap.roundYWithDirection(y, d);
            if ($gameMap.regionId(x2, y2) !== region) return false;
        }
        return alias.apply(this, arguments);
    };
})(Game_CharacterBase.prototype.canPass);

Original thread: https://forums.rpgmakerweb.com/threads/static-encounter-region-restriction-question.129273/