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,226
Reaction score
1,633
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,226
Reaction score
1,633
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

  • regionCage.js
    1 KB · Views: 2

Latest Threads

Latest Posts

Latest Profile Posts

3am me: So how do you feel about a character inviting their own character portrait to a tea party? =D

3pm me: //facepalms
I turned 17 two months ago and I feel like I've grown (personality-wise) more in this 1 year than all the 16 years I had lived combined.
Ugh, I may have been cumbersomely eventing a bunch of stuff I could have easily done changing the tileset "Passage (4 dir)" and "Ladder" options. Oops :D
I have no idea why some of the program "splash screen" always on top. E.g, RMMZ loading screen stuck on the top blocking anything I want to do until it fully loaded. What is even the purpose?
One of the secret places in the game.

Forum statistics

Threads
107,644
Messages
1,031,107
Members
139,766
Latest member
lincore
Top