Static Encounter Region Restriction Question

NBGDani

Villager
Member
Joined
Dec 24, 2016
Messages
19
Reaction score
0
Primarily Uses
N/A
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
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,050
Reaction score
1,479
First Language
EN
Primarily Uses
RMMZ
How do you make the event stay inside one area? Are you using a plugin?
 

NBGDani

Villager
Member
Joined
Dec 24, 2016
Messages
19
Reaction score
0
Primarily Uses
N/A
Yes, RegionRestrictions from Yanfly :)
with <Event Restrict Region: 10> on my Map Note and around the enemy events "10".
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
2,050
Reaction score
1,479
First Language
EN
Primarily Uses
RMMZ
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).
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);
 

Attachments

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

GOBBLE GOBBLE! Happy thanksgiving.
Oh no. That moment when you try to fix something you modified in your game, like, a year ago but didn't want to fix then, and you now have no idea what you even did. Me right now, trying to figure out why my gold window is over stretched?
LittlePIGGY wrote on atreyoray's profile.
Where are you TT^TT
We need ARP_InGameManual for MZ
Oh my gosh. Thank you, Macy's! Thank you so much! You have made me very happy!

Forum statistics

Threads
105,551
Messages
1,014,570
Members
137,225
Latest member
Eryndor
Top