Different Region Access for Different NPCs

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
Is it possible to create rules that restrict and allow different NPCs to pass through different regions?

For example, if everyone's movement is random...

Grass = Region 10
Water = Region 20

Event 1, 2, 3 = Cats
Event 4, 5, 6 = Ducks
Event 7, 8, 9 = Fish​

I want to bind Events 1-3 to Region 10, Events 7-9 to Region 20, and allow Events 4-6 to have unrestricted access. Basically, no swimming cats or walking fish without bothering the ducks.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,126
Reaction score
12,405
First Language
English
Primarily Uses
RMMV
This sounds like something Yanfly's Region Restrictions plugin would handle.

You might need something else (a region common events plugin - I made one, but I have a feeling Yanfly might have one of those too) to change the duck sprite when they're on water vs on land - after all, they don't walk on the water :)
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
Thank you. My duck sprites currently swim/walk where appropriate, but I'm having trouble adding a "fence" to keep fish in the water without keeping the ducks out. I tried Yanfly's Region Restrictions, but it seems to be all-or-nothing for events. I haven't seen any history of anyone else differentiating between which events are/aren't effected by restrictions.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,126
Reaction score
12,405
First Language
English
Primarily Uses
RMMV
Yanfly's doesn't let you add a note to the event to say which region to stick with or avoid?
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
The notes seem to pertain to the map only and affect all regions on the map.

Capture.PNG

Not everybody wants NPC's to travel all over the place. With this plugin,

you can set NPC's to be unable to move pass tiles marked by a specified

Region ID. Simply draw out the area you want to enclose NPC's in on and

they'll be unable to move past it unless they have Through on. Likewise,

there are regions that you can prevent the player from moving onto, too!



A new change from the RPG Maker VX Ace version is that now there exist

Regions that can allow players and events to always travel through.



============================================================================

Notetags

============================================================================



You can use this notetag inside of your maps.



Map Notetags:



<Player Restrict Region: x>

<Player Restrict Region: x, x, x>

<Player Restrict Region: x to y>

Restricts region x for the player on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<Event Restrict Region: x>

<Event Restrict Region: x, x, x>

<Event Restrict Region: x to y>

Restricts region x for all events on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<All Restrict Region: x>

<All Restrict Region: x, x, x>

<All Restrict Region: x to y>

Restricts region x for the player and all events on this particular map.

Use multiple x to mark more regions. From x to y, you can mark a multitude

of regions.



<Player Allow Region: x>

<Player Allow Region: x, x, x>

<Player Allow Region: x to y>

Allows region x for the player on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<Event Allow Region: x>

<Event Allow Region: x, x, x>

<Event Allow Region: x to y>

Allows region x for all events on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<All Allow Region: x>

<All Allow Region: x, x, x>

<All Allow Region: x to y>

Allows region x for the player and all events on this particular map.

Use multiple x to mark more regions. From x to y, you can mark a multitude

of regions.
 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,260
Reaction score
537
First Language
Portuguese - Br
Primarily Uses
RMMV
The notes seem to pertain to the map only and affect all regions on the map.

View attachment 108576

Not everybody wants NPC's to travel all over the place. With this plugin,

you can set NPC's to be unable to move pass tiles marked by a specified

Region ID. Simply draw out the area you want to enclose NPC's in on and

they'll be unable to move past it unless they have Through on. Likewise,

there are regions that you can prevent the player from moving onto, too!



A new change from the RPG Maker VX Ace version is that now there exist

Regions that can allow players and events to always travel through.



============================================================================

Notetags

============================================================================



You can use this notetag inside of your maps.



Map Notetags:



<Player Restrict Region: x>

<Player Restrict Region: x, x, x>

<Player Restrict Region: x to y>

Restricts region x for the player on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<Event Restrict Region: x>

<Event Restrict Region: x, x, x>

<Event Restrict Region: x to y>

Restricts region x for all events on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<All Restrict Region: x>

<All Restrict Region: x, x, x>

<All Restrict Region: x to y>

Restricts region x for the player and all events on this particular map.

Use multiple x to mark more regions. From x to y, you can mark a multitude

of regions.



<Player Allow Region: x>

<Player Allow Region: x, x, x>

<Player Allow Region: x to y>

Allows region x for the player on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<Event Allow Region: x>

<Event Allow Region: x, x, x>

<Event Allow Region: x to y>

Allows region x for all events on this particular map. Use multiple x

to mark more regions. From x to y, you can mark a multitude of regions.



<All Allow Region: x>

<All Allow Region: x, x, x>

<All Allow Region: x to y>

Allows region x for the player and all events on this particular map.

Use multiple x to mark more regions. From x to y, you can mark a multitude

of regions.
Try the region events. I think you can use one common events per region id.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
Try the region events. I think you can use one common events per region id.
What is a region event? (Sorry, I'm still new to this program!)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,126
Reaction score
12,405
First Language
English
Primarily Uses
RMMV
that's not going to restrict/allow movement though. That would only be when you want something to happen when the player moves from one region to another.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
Thank you both for your help. I'll post back if I find a solution.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
This is the closest I have using Yanfly's Region Restriction plugin.

Fish (raft icon) are restricted to the water.
Cats are restricted to the land.
Ducks (chicken icon) can move anywhere due to the "through on" movement designation.

However... ducks/chickens can still go through the fence. I tried a bunch of switches, but it got cumbersome. "Through on" lets the event go through anything (Region 7, the Player, fences...). I wish there was a way to negate part of the plugin just for specific events. I tried picking the code apart, but my javascript knowledge is minimal. It would also be awesome (not essential, just cool) if the cat could approach the water without going in. Having to use one tile as a no-access region means the cat and fish can't simultaneously be at the water's edge on their respective sides.

//=============================================================================
// Yanfly Engine Plugins - Region Restrictions
// YEP_RegionRestrictions.js
//=============================================================================

var Imported = Imported || {};
Imported.YEP_RegionRestrictions = true;

var Yanfly = Yanfly || {};
Yanfly.RR = Yanfly.RR || {};
Yanfly.RR.version = 1.04

//=============================================================================
/*:
* @plugindesc v1.04 Use regions to block out Events and/or the player from
* being able to venture into those spots.
* @author Yanfly Engine Plugins
*
* @param Player Restrict
* @desc This region ID will restrict the player from entering.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @param Event Restrict
* @desc This region ID will restrict all events from entering.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @param All Restrict
* @desc This region ID will restrict players and events.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @param Player Allow
* @desc This region ID will always allow player passability.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @param Event Allow
* @desc This region ID will always allow events passability.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @param All Allow
* @desc This region ID will always allow both passability.
* To use multiple regions, separate them by spaces.
* @Default 0
*
* @Help
* ============================================================================
* Introduction and Instructions
* ============================================================================
*
* Not everybody wants NPC's to travel all over the place. With this plugin,
* you can set NPC's to be unable to move pass tiles marked by a specified
* Region ID. Simply draw out the area you want to enclose NPC's in on and
* they'll be unable to move past it unless they have Through on. Likewise,
* there are regions that you can prevent the player from moving onto, too!
*
* A new change from the RPG Maker VX Ace version is that now there exist
* Regions that can allow players and events to always travel through.
*
* ============================================================================
* Notetags
* ============================================================================
*
* You can use this notetag inside of your maps.
*
* Map Notetags:
*
* <Player Restrict Region: x>
* <Player Restrict Region: x, x, x>
* <Player Restrict Region: x to y>
* Restricts region x for the player on this particular map. Use multiple x
* to mark more regions. From x to y, you can mark a multitude of regions.
*
* <Event Restrict Region: x>
* <Event Restrict Region: x, x, x>
* <Event Restrict Region: x to y>
* Restricts region x for all events on this particular map. Use multiple x
* to mark more regions. From x to y, you can mark a multitude of regions.
*
* <All Restrict Region: x>
* <All Restrict Region: x, x, x>
* <All Restrict Region: x to y>
* Restricts region x for the player and all events on this particular map.
* Use multiple x to mark more regions. From x to y, you can mark a multitude
* of regions.
*
* <Player Allow Region: x>
* <Player Allow Region: x, x, x>
* <Player Allow Region: x to y>
* Allows region x for the player on this particular map. Use multiple x
* to mark more regions. From x to y, you can mark a multitude of regions.
*
* <Event Allow Region: x>
* <Event Allow Region: x, x, x>
* <Event Allow Region: x to y>
* Allows region x for all events on this particular map. Use multiple x
* to mark more regions. From x to y, you can mark a multitude of regions.
*
* <All Allow Region: x>
* <All Allow Region: x, x, x>
* <All Allow Region: x to y>
* Allows region x for the player and all events on this particular map.
* Use multiple x to mark more regions. From x to y, you can mark a multitude
* of regions.
*
* ============================================================================
* Changelog
* ============================================================================
*
* Version 1.04:
* - Updated for RPG Maker MV version 1.5.0.
*
* Version 1.03:
* - Fixed an issue with vehicles being capable of landing the player in region
* restricted zones.
*
* Version 1.02:
* - Plugin parameters have been upgraded to now accept multiple region ID's.
* Insert a space in between them to add more than one region ID.
*
* Version 1.01:
* - Added new notetags to allow for more region restriction settings!
*
* Version 1.00:
* - Finished plugin!
*/
//=============================================================================

//=============================================================================
// Parameter Variables
//=============================================================================

Yanfly.Param = Yanfly.Param || {};

Yanfly.SetupParameters = function() {
var parameters = PluginManager.parameters('YEP_RegionRestrictions');
Yanfly.Param.RRAllAllow = String(parameters['All Allow']);
Yanfly.Param.RRAllAllow = Yanfly.Param.RRAllAllow.split(' ');
for (var i = 0; i < Yanfly.Param.RRAllAllow.length; ++i) {
Yanfly.Param.RRAllAllow = Number(Yanfly.Param.RRAllAllow);
}
Yanfly.Param.RRAllRestrict = String(parameters['All Restrict']);
Yanfly.Param.RRAllRestrict = Yanfly.Param.RRAllRestrict.split(' ');
for (var i = 0; i < Yanfly.Param.RRAllRestrict.length; ++i) {
Yanfly.Param.RRAllRestrict = Number(Yanfly.Param.RRAllRestrict);
}
Yanfly.Param.RREventAllow = String(parameters['Event Allow']);
Yanfly.Param.RREventAllow = Yanfly.Param.RREventAllow.split(' ');
for (var i = 0; i < Yanfly.Param.RREventAllow.length; ++i) {
Yanfly.Param.RREventAllow = Number(Yanfly.Param.RREventAllow);
}
Yanfly.Param.RREventRestrict = String(parameters['Event Restrict']);
Yanfly.Param.RREventRestrict = Yanfly.Param.RREventRestrict.split(' ');
for (var i = 0; i < Yanfly.Param.RREventRestrict.length; ++i) {
Yanfly.Param.RREventRestrict = Number(Yanfly.Param.RREventRestrict);
}
Yanfly.Param.RRPlayerAllow = String(parameters['Player Allow']);
Yanfly.Param.RRPlayerAllow = Yanfly.Param.RRPlayerAllow.split(' ');
for (var i = 0; i < Yanfly.Param.RRPlayerAllow.length; ++i) {
Yanfly.Param.RRPlayerAllow = Number(Yanfly.Param.RRPlayerAllow);
}
Yanfly.Param.RRPlayerRestrict = String(parameters['Player Restrict']);
Yanfly.Param.RRPlayerRestrict = Yanfly.Param.RRPlayerRestrict.split(' ');
for (var i = 0; i < Yanfly.Param.RRPlayerRestrict.length; ++i) {
Yanfly.Param.RRPlayerRestrict = Number(Yanfly.Param.RRPlayerRestrict);
}
};
Yanfly.SetupParameters();

//=============================================================================
// DataManager
//=============================================================================

DataManager.processRRNotetags = function() {
if (!$dataMap) return;
$dataMap.restrictPlayerRegions = Yanfly.Param.RRAllRestrict.concat(
Yanfly.Param.RRPlayerRestrict);
$dataMap.restrictEventRegions = Yanfly.Param.RRAllRestrict.concat(
Yanfly.Param.RREventRestrict);
$dataMap.allowPlayerRegions = Yanfly.Param.RRAllAllow.concat(
Yanfly.Param.RRPlayerAllow);
$dataMap.allowEventRegions = Yanfly.Param.RRAllAllow.concat(
Yanfly.Param.RREventAllow);
if (!$dataMap.note) return;

var note1a = /<(?:pLAYER RESTRICT REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note1b = /<(?:pLAYER RESTRICT REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;
var note2a = /<(?:EVENT RESTRICT REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note2b = /<(?:EVENT RESTRICT REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;
var note3a = /<(?:ALL RESTRICT REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note3b = /<(?:ALL RESTRICT REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;

var note4a = /<(?:pLAYER ALLOW REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note4b = /<(?:pLAYER ALLOW REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;
var note5a = /<(?:EVENT ALLOW REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note5b = /<(?:EVENT ALLOW REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;
var note6a = /<(?:ALL ALLOW REGION):[ ]*(\d+(?:\s*,\s*\d+)*)>/i;
var note6b = /<(?:ALL ALLOW REGION):[ ](\d+)[ ](?:TO)[ ](\d+)>/i;

var notedata = $dataMap.note.split(/[\r\n]+/);

for (var i = 0; i < notedata.length; i++) {
var line = notedata;
if (line.match(note1a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.restrictPlayerRegions =
$dataMap.restrictPlayerRegions.concat(array);
} else if (line.match(note1b)) {
var mainArray = $dataMap.restrictPlayerRegions;
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.restrictPlayerRegions =
$dataMap.restrictPlayerRegions.concat(range);
} else if (line.match(note2a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.restrictEventRegions =
$dataMap.restrictEventRegions.concat(array);
} else if (line.match(note2b)) {
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.restrictEventRegions =
$dataMap.restrictEventRegions.concat(range);
} else if (line.match(note3a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.restrictPlayerRegions =
$dataMap.restrictPlayerRegions.concat(array);
$dataMap.restrictEventRegions =
$dataMap.restrictEventRegions.concat(array);
} else if (line.match(note3b)) {
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.restrictPlayerRegions =
$dataMap.restrictPlayerRegions.concat(array);
$dataMap.restrictEventRegions =
$dataMap.restrictEventRegions.concat(array);
} else if (line.match(note4a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.allowPlayerRegions =
$dataMap.allowPlayerRegions.concat(array);
} else if (line.match(note4b)) {
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.allowPlayerRegions =$dataMap.allowPlayerRegions.concat(range);
} else if (line.match(note5a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.allowEventRegions = $dataMap.allowEventRegions.concat(array);
} else if (line.match(note5b)) {
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.allowEventRegions = $dataMap.allowEventRegions.concat(range);
} else if (line.match(note6a)) {
array = JSON.parse('[' + RegExp.$1.match(/\d+/g) + ']');
$dataMap.allowPlayerRegions = $dataMap.allowPlayerRegions.concat(array);
$dataMap.allowEventRegions = $dataMap.allowEventRegions.concat(array);
} else if (line.match(note6b)) {
var range = Yanfly.Util.getRange(Number(RegExp.$1),
Number(RegExp.$2));
$dataMap.allowPlayerRegions = $dataMap.allowPlayerRegions.concat(array);
$dataMap.allowEventRegions = $dataMap.allowEventRegions.concat(array);
}
}
};

//=============================================================================
// Game_Map
//=============================================================================

Yanfly.RR.Game_Map_setup = Game_Map.prototype.setup;
Game_Map.prototype.setup = function(mapId) {
Yanfly.RR.Game_Map_setup.call(this, mapId);
if ($dataMap) DataManager.processRRNotetags();
};

Game_Map.prototype.restrictEventRegions = function() {
if ($dataMap.restrictEventRegions === undefined) {
DataManager.processRRNotetags();
}
return $dataMap.restrictEventRegions || [];
};

Game_Map.prototype.restrictPlayerRegions = function() {
if ($dataMap.restrictPlayerRegions === undefined) {
DataManager.processRRNotetags();
}
return $dataMap.restrictPlayerRegions || [];
};

Game_Map.prototype.allowEventRegions = function() {
if ($dataMap.allowEventRegions === undefined) {
DataManager.processRRNotetags();
}
return $dataMap.allowEventRegions || [];
};

Game_Map.prototype.allowPlayerRegions = function() {
if ($dataMap.allowPlayerRegions === undefined) {
DataManager.processRRNotetags();
}
return $dataMap.allowPlayerRegions || [];
};

//=============================================================================
// Game_CharacterBase
//=============================================================================

Yanfly.RR.Game_CharacterBase_isMapPassable =
Game_CharacterBase.prototype.isMapPassable;
Game_CharacterBase.prototype.isMapPassable = function(x, y, d) {
if (this.isEventRegionForbid(x, y, d)) return false;
if (this.isPlayerRegionForbid(x, y, d)) return false;
if (this.isEventRegionAllow(x, y, d)) return true;
if (this.isPlayerRegionAllow(x, y, d)) return true;
return Yanfly.RR.Game_CharacterBase_isMapPassable.call(this, x, y, d);
};

Game_CharacterBase.prototype.isEvent = function() {
return false;
};

Game_CharacterBase.prototype.isPlayer = function() {
return false;
};

Game_CharacterBase.prototype.processRRNotetags = function() {
DataManager.processRRNotetags();
};

Game_CharacterBase.prototype.isEventRegionForbid = function(x, y, d) {
if (this.isPlayer()) return false;
if (this.isThrough()) return false;
var regionId = this.getRegionId(x, y, d);
if (regionId === 0) return false;
if ($gameMap.restrictEventRegions().contains(regionId)) return true;
return false;
};

Game_CharacterBase.prototype.isPlayerRegionForbid = function(x, y, d) {
if (this.isEvent()) return false;
if (this.isThrough()) return false;
var regionId = this.getRegionId(x, y, d);
if (regionId === 0) return false;
if ($gameMap.restrictPlayerRegions().contains(regionId)) return true;
return false;
};

Game_CharacterBase.prototype.isEventRegionAllow = function(x, y, d) {
if (this.isPlayer()) return false;
var regionId = this.getRegionId(x, y, d);
if (regionId === 0) return false;
if ($gameMap.allowEventRegions().contains(regionId)) return true;
return false;
};

Game_CharacterBase.prototype.isPlayerRegionAllow = function(x, y, d) {
if (this.isEvent()) return false;
var regionId = this.getRegionId(x, y, d);
if (regionId === 0) return false;
if ($gameMap.allowPlayerRegions().contains(regionId)) return true;
return false
};

Game_CharacterBase.prototype.getRegionId = function(x, y, d) {
switch (d) {
case 1:
return $gameMap.regionId(x - 1, y + 1);
break;
case 2:
return $gameMap.regionId(x + 0, y + 1);
break;
case 3:
return $gameMap.regionId(x + 1, y + 1);
break;
case 4:
return $gameMap.regionId(x - 1, y + 0);
break;
case 5:
return $gameMap.regionId(x + 0, y + 0);
break;
case 6:
return $gameMap.regionId(x + 1, y + 0);
break;
case 7:
return $gameMap.regionId(x - 1, y - 1);
break;
case 8:
return $gameMap.regionId(x + 0, y - 1);
break;
case 9:
return $gameMap.regionId(x + 1, y - 1);
break;
default:
return $gameMap.regionId(x, y);
break;
}
};

//=============================================================================
// Game_Event
//=============================================================================

Game_Event.prototype.isEvent = function() {
return true;
};

//=============================================================================
// Game_Player
//=============================================================================

Game_Player.prototype.isPlayer = function() {
return true;
};

//=============================================================================
// Game_Vehicle
//=============================================================================

Yanfly.RR.Game_Vehicle_isLandOk = Game_Vehicle.prototype.isLandOk;
Game_Vehicle.prototype.isLandOk = function(x, y, d) {
var value = Yanfly.RR.Game_Vehicle_isLandOk.call(this, x, y, d);
if (!value) return false;
if (this.isAirship()) {
d = 5;
$gamePlayer._through = false;
}
if ($gamePlayer.isPlayerRegionForbid(x, y, d)) {
if (this.isAirship()) $gamePlayer._through = true;
return false;
}
if ($gamePlayer.isPlayerRegionAllow(x, y, d)) {
if (this.isAirship()) $gamePlayer._through = true;
return true;
}
return true;
};

//=============================================================================
// Utilities
//=============================================================================

Yanfly.Util = Yanfly.Util || {};

Yanfly.Util.getRange = function(n, m) {
var result = [];
for (var i = n; i <= m; ++i) result.push(i);
return result;
};

//=============================================================================
// End of File
//=============================================================================


region1.PNG

region2.PNG
 
Last edited:

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
I tried the @Galv Move Route extras, which creates an allowed area block per event, and the @Yanfly Region Restrictions, which creates region fences for all events at once, however they don't seem to allow for some of the other event movements I'm using. I also found the @pizzacat Region Restricted Movement script, which seems to be exactly what I need (region fences per event), but it's written for RMVX Ace. Does anyone know if something similar to this (region fences per event) exists for RMMV?
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
394
Reaction score
212
First Language
English
Primarily Uses
RMMV
I can't think of any plugin that would do this for you, but it may be possible to handle their movement outwith the custom move route and within the main body of their event content, if the events are actually doing things this is a little more complicated but could be handled by a separate "controller" event set to parallel. This will allow you to add conditional branches to check their x and y positions and then make moves accordingly, it's certainly not the most elegant solution but given your map is relatively simple shouldn't be too much work.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
I can't think of any plugin that would do this for you, but it may be possible to handle their movement outwith the custom move route and within the main body of their event content, if the events are actually doing things this is a little more complicated but could be handled by a separate "controller" event set to parallel. This will allow you to add conditional branches to check their x and y positions and then make moves accordingly, it's certainly not the most elegant solution but given your map is relatively simple shouldn't be too much work.
Good thought. I'll try that now.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
Good thought. I'll try that now.
I tried it, and it worked the same as if the custom move route was written within the same event,
 

Silva

Scoobityboo
Veteran
Joined
Nov 5, 2018
Messages
394
Reaction score
212
First Language
English
Primarily Uses
RMMV
I'm not sure if you've used conditional branches to determine the events position or just copied the move route into the event contents. I've just copied your map and layout roughly and got this working with no plugins, it's just a bit of logic that's needed. I'll walk you through what I've done.

So for all your events you have 9 potential scenarios, 4 corners, 4 edges and in the middle, you need to tell the events what to do in each of these situations.

For your fish there are 2 top left corners (one at the waters edge and one where the bridge sticks out). In my recreation of your map the top left corner of my pond is on (4, 3) and the top left corner made by my bridge is (4, 7). I've used this code in a condition branch to check if the fish is in one of these corners:

Code:
($gameMap.event(1).x === 4 && $gameMap.event(1).y === 3) || ($gameMap.event(1).x === 4 && $gameMap.event(1).y === 7)
If the fish is on one of these tiles we only want it to move down or right. I used Control Variable->Script with Math.randomInt(2) to generate a random number between 0 and 1. From there I used a conditional branch to check if the assigned variable was 1, if it was I told the event to move down, otherwise move right, after which I end the event processing so that the whole process starts again - this is important as the last step is a non-conditional "move random" that we don't want to execute unless all other possibilities have been checked for.

upload_2019-2-4_20-52-57.png

Moving on to the top right corner (1 at waters edge). Mine is (12, 3). So we repeat the same process as above. The code to check the top right corner on my map is:

Code:
$gameMap.event(1).x === 12 && $gameMap.event(1).y === 3
Our options here are to move down or move left, so repeat the above process with these commands.

upload_2019-2-4_21-15-56.png

Following the same logic for the bottom right corner - for me (12, 9) - the code is:

Code:
$gameMap.event(1).x === 12 && $gameMap.event(1).y === 9
upload_2019-2-4_21-37-47.png

Same again for bottom left, but there's two this time because of the bridge. For me these are (4, 9) and (4, 5), so the code is:

Code:
($gameMap.event(1).x === 4 && $gameMap.event(1).y === 9) || ($gameMap.event(1).x === 4 && $gameMap.event(1).y === 5)
upload_2019-2-4_21-40-9.png

Now we move on to the straight edges. Keep in mind the bridge creates its own bottom edge, top edge and left edge.

On my map the top edge of the water is along y = 3, and the top edge made by the bridge (water beneath the bridge) is on y =7 and x = 5 or 6. So the code is:

Code:
$gameMap.event(1).y === 3 || ($gameMap.event(1).y === 7 && ($gameMap.event(1).x === 5 || $gameMap.event(1).x === 6))
This time because we have three potential movements we need to use Math.randomInt(3) to get a random number between 0-2. From here we make a condition branch to check if this value is 2, then we move right and exit event processing. Then we make a second conditional branch (with else) to check if this value is 1, then we move down and exit event processing. If else then we move left and exit event processing.

upload_2019-2-4_21-48-9.png

We repeat this process with the remaining edges, changing the one movement that's invalid with a valid one. Ie. if we look at the process from the top edge and change it to fit the right edge we need to remove the move right and replace it with move up.

The right edge on my map is where x = 12. So the code is:

Code:
$gameMap.event(1).x === 12
upload_2019-2-4_21-52-42.png

The bottom edge on my map is where y = 9. The bottom edge made by the bridge (water tiles above the bridge) are where y = 5 and x = 5 or 6. So the code is:

Code:
$gameMap.event(1).y === 9 || ($gameMap.event(1).y === 5 && ($gameMap.event(1).x === 5 || $gameMap.event(1).x === 6))
upload_2019-2-4_21-57-38.png

The left edge on my map is where x = 4. The left edge created by my bridge (water tile to the right of end bridge tile) is on point (7,6). So the code is:

Code:
$gameMap.event(1).x === 4 || ($gameMap.event(1).x === 7 && $gameMap.event(1).y === 6)
upload_2019-2-4_22-1-43.png

Then finally, as mentioned above, we just add a move random (because we've checked that the event is not on a corner, and not on an edge, so it must be on a middle tile, thus can move anywhere).

upload_2019-2-4_22-4-25.png

And that's that, your fish won't go wandering out of the water and no plugins involved (though I admit a plugin would've made this a lot easier)! This process hasn't added any changes in speed or waiting period, I used the Math.randomInt(3) function again to add random changes to both but you could easily do this some other way. Whatever you do, it should be done at the top of the event page because the "exit event processing" will cause it to be skipped if it's at the bottom unless the event is on a "middle" tile.

upload_2019-2-4_22-26-56.png

NOTES:
You will need to use a different "random variable" for each event - it would be possible to use one for them all, but I hadn't thought of doing so when I was mocking this up, sorry!
Where I've used $gameMap.event(1), you should replace the 1 with the ID of the event you're controlling.
upload_2019-2-4_22-21-13.png
upload_2019-2-4_22-22-29.png


You can apply these same steps for your ducks as well, just reference the corners and edges made by your fence. These are easier as there is only one of each corner and edge.
 

Anchovy

A Fish Called Amy
Veteran
Joined
Jan 9, 2019
Messages
40
Reaction score
25
First Language
English
Primarily Uses
RMMV
@Silva I really can't thank you enough for taking the time to recreate this and break it down for me. I know I'll be referencing this repeatedly while experimenting with controlled random routes for my events throughout learning RMMV and JS. I'll let you know how I use this. Again, thanks a ton!
 

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

Latest Threads

Latest Posts

Latest Profile Posts

*Violent ball of 80's TV electricity* "Oww!! Stupid @ImaginaryVillain and his plugin, he didn't say time travel hurts! And why am I naked??"
It was at 3am Pacific May 25 that Skynet was created. And it came in the form of a messenger plugin so powerful it now runs my randomizer and does it better than the randomizer itself did. What have I created? :kaoback:
Found out someone took one of my artist's commissions, edited it and claimed it as their own. Called them out on Twitter, got blocked. Not sure whether to feel irritated or honored.
Im so glad that im into 16/32bit games because i'd never be able to create any assets for something more complex :p
I was thinking of MAYBE (a big maybe) starting an soundtrack resource thread where I would post one track per week.

Forum statistics

Threads
97,747
Messages
946,649
Members
128,948
Latest member
CMEEEEPTb
Top