Terrain Tag Passability - PG_TTagPass.js

This plugin gives you the ability to make terrain passable or not by turning switches on or off. Instead of using regions (which are not related to the tiles used) it uses terrain tags. Up to 6 terrain tags may have their passability controlled. It overides the passability of land tiles with specific terrain tags.

Spoiler: Why use Terrain Tags to Control Access?
Terrain Tags are settings that can be made in the "Tilesets" tab of the editor. Individual tiles can be given a terrain tag of 0 to 7. Multiple tiles can have the same terrain tag. By default, all terrain tags are 0.

Whenever a tile is used, the places it is used have the terrain tag of that tile. Unlike regions, if you change your mind where a wood or mountain range is, the terrain tag of each place is set automatically.

Terrain tags are a feature that I haven't previously used, and I suspect, are not used by many other people. Regions are sometimes used by other plugins for various effects. By default, they get used to control which enemies may be encountered in different areas of the same map. With this plugin, you could, for example, make all mountains impassable to the party, until they learn the mountaineering. Using a plugin that controls access by region, means that every time you edit the map you have to check whether the regions need updating. With this plugin, the party can be given access to previous blocked terrain by setting a switch.

To use a switch to control passability for a terrain tag, put the switch number into the relevant parameter. If the switch is "On", then tiles with that terrain tag are passable for the party, while if the switch is "Off" then they are impassable. [Be aware that when using B to E sheet tiles, the uppermost tile's terrain tag tends to overwrite that of the A sheet tile underneath.] If you don't want to overide the passability of tiles with a particular terrain tag, leave the parameter for the switch controlling it as '0'.

Version 2

JavaScript:
//=============================================================================
// PG_TTagPass.js
//=============================================================================
/*:
 * @plugindesc Allows switched tile passability using terrain tags
 *
 * @author Piyan Glupak, amended for version 2 by Trihan
 *
 *
 * @help
 * This plugin has 6 parameters, for switches to control passability of tiles
 * with terrain tags of 2, 3 , 4, 5, 6 and 7. If the switch is 'on', then all
 * tiles with that terrain tag are passable. If the switch is 'off', then they
 * are impassable. If no switch is chosen for a terrain tag (parameter is '0'),
 * the
 * tiles with that terrain tag have their default passability.
 *
 * Terrain tags are '0' by default, but can be set in the editor.
 *
 * This is intended for land. It is possible to fly over tiles the tiles with
 * switched passability with the airship.
 *
 * This is Version 2.
 *
 * TERMS OF USE
  **************************************************************************
 * TERMS OF USE
 * Free for use in commercial and non-commercial games. No liability accepted.
 * Credit Piyan Glupak and Trihan
 **************************************************************************
 *
 * COMPATIBILITY
 * No issues known
 *
 * Version 2 - Code improved by Trihan when he wrote a supplementry plugin to
 * improve visual aspects.
 * Version 1 - Original version by Piyan Glupak
 *
 * @param Terrain Tag 2 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 2
 * @default 0
 *
 * @param Terrain Tag 3 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 3
 * @default 0
 *
 * @param Terrain Tag 4 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 4
 * @default 0
 *
 * @param Terrain Tag 5 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 5
 * @default 0
 *
 * @param Terrain Tag 6 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 6
 * @default 0
 *
 * @param Terrain Tag 7 Flag
 * @type number
 * @min 0
 * @desc Number of the flag allowing passability of Terrain Tag 7
 * @default 0
*/

window.PG = window.PG || {};
PG.parameters = PluginManager.parameters('PG_TTagPass');
PG.TFlag2 = Number(PG.parameters['Terrain Tag 2 Flag']);
PG.TFlag3 = Number(PG.parameters['Terrain Tag 3 Flag']);
PG.TFlag4 = Number(PG.parameters['Terrain Tag 4 Flag']);
PG.TFlag5 = Number(PG.parameters['Terrain Tag 5 Flag']);
PG.TFlag6 = Number(PG.parameters['Terrain Tag 6 Flag']);
PG.TFlag7 = Number(PG.parameters['Terrain Tag 7 Flag']);

Game_Map.prototype.checkPassage = function(x, y, bit) {
    var flags = this.tilesetFlags();
    var tiles = this.allTiles(x, y);
    var TerTag = $gameMap.terrainTag(x,y);
    for (const tile of tiles) {
        const flag = flags[tile];
        if ((flag & 0x10) !== 0)  // [*] No effect on passage
            continue;
        for (let i = 2; i <= 7; i++) {
            const propName = `TFlag${i}`;
            if (TerTag === i && PG[propName] > 0) {
                return $gameSwitches.value(PG[propName]);
            }
        }
        if ((flag & bit) === 0)   // [o] Passable
            return true;
        if ((flag & bit) === bit) // [x] Impassable
            return false;
    }
    return false;
};

Terms and Conditions:
Free to use for both free and commercial games. Please do not publish this elsewhere on the Internet, but link to this thread. (This is in case I ever need to update the plugin; I would want only the latest version to be available.) I would prefer to be credited, either as "Piyan Glupak" or by my real name. Please credit Trihan as well, if using version 2.

Trihan's Supplementary Plugin may be found in post 7 of this thread.
I was looking for something like this for toggleable climbing. My backup plan was using a tile changer and writing a script to loop through the map and change the top layer of every mountain tile to an invisble passable tile
I wonder why you didn't aliased the gameMap function though.

I have a bit similair than yours, but more region based with switches.

TileFlags is a nice option if the map is full of regions and no place to
set them, but if autotiles and B-E can overwrite like stacking tiles which is 0,
it probably need also a 1-7 digit to avoid those, and some probably need to
duplicate the tiles to make it work.

@AquaEcho if you want a toggleable ladder, you could use 1 event for a ladder
length, and make it unpassable until you toggle it to passable.

but there are small ways to get this done, depending if you use it multiple times
or a few times.
Trihan has been kind enough to tidy up and improve the code. He has also written a supplementary plugin to treat auto-tiles with a terrain tag of either 6 or 7 as if they have "star-passability" when used with this plugin.

Trihan has given me permission to put his supplementary plugin on this forum. I will do this when I have contacted a mod to ask what way they recommend.
You could just post it in the same topic below the original.
If Trihan has said it's cool, it's cool. How things are credited and distributed will always be up to collaborators. He's the best source of info. 🙂
Thank you to Trihan for giving me permission to post his supplementary plugin.

[I have also added the file as an attachment to the first post of this thread.]

This is Trihan's plugin, written to be used with the plugin above:-

JavaScript:
//=============================================================================
// PG_TTagPass_X_StarAutotiles.js
//=============================================================================
/*:
 * @plugindesc Allows star passability on autotiles with certain terrain tags
 *
 * @author Trihan (Original PG_TTagPass by Piyan Glupak)
 *
 *
 * @help
 * This plugin is plug-and-play and works alongside PG_TTagPass. Autotiles
 * with a terrain tag of 6-7 will appear above the party when their
 * passability switch is on.
 *
 * TERMS OF USE
  **************************************************************************
 * TERMS OF USE
 * Free for use in commercial and non-commercial games. No liability accepted.
 * Credit Piyan Glupak and Trihan
 **************************************************************************
 *
 * COMPATIBILITY
 * No issues known
 *
*/

ShaderTilemap.prototype._drawTile = function(layer, tileId, dx, dy) {
    if (Tilemap.isVisibleTile(tileId)) {
        if (Tilemap.isAutotile(tileId)) {
            let terrainFlag = false;
            for (let i = 6; i <= 7; i++) {
                const propName = `TFlag${i}`;
                const terrainTag = this.flags[tileId] >> 12;
                if (terrainTag === i && PG[propName] > 0 && $gameSwitches.value(PG[propName])) {
                    terrainFlag = true;
                    break;
                }
            }
            if (terrainFlag)
                layer = this.upperLayer.children[0];
            this._drawAutotile(layer, tileId, dx, dy);
        } else {
            this._drawNormalTile(layer, tileId, dx, dy);
        }
    }
};

Game_Switches.prototype.onChange = function() {
    $gameMap.requestRefresh();
    if (SceneManager._scene._spriteset) SceneManager._scene._spriteset._tilemap.refresh();
};

This plugin is intended for overworld maps.

If you use this plugin with PG_TTagPass from the first post in the thread, and use terrain tags 6 or 7 (with switches set to enable passibility of tiles with terrain tags 6 and 7), if the tiles are auto-tiles, the top layer is treated as having "Star-Passability". You wouldn't need this for hills, mountains or swamps, but it might be useful for tree auto-tiles, so that the party is seen walking through the wood rather than on top of it.

It only does it for terrain tags 6 and 7 in case you want to also use terrain tags to control access to terrain where you don't want this effect, such as swamps and mountains.

For best results, I recommend using smaller sprites for the overworld. The effect looks better with some non-RTP tiles such as the Winlu overworld tiles.

Screenshot 2024-01-23 172830.png
[/CODE]
Thanks for these!

Just a suggestion - consider attaching the actual plugin files, rather than (or in addition to) pasting their text into the body of your post.

It's more convenient for users to click the file for download than it is to select the whole scrolling field, and it will help ensure people save it with the correct filename.
i dont understand how to use this,, i need a plugin for restricting passage in my world map via switches, painting by region was my initial thoughts.
@xabileug - I don't know whether or not one of the plugins that allows you to set passability for regions by a switch might be better for what you want. However, I will try to explain how to use this plugin and what it is intended for. I will use spoilers to avoid a wall of text.

Spoiler: What it's for
This plugin was intended for something like the "Pathfinding" and "Mountaineering" abilities of the old "Might and Magic" 3, 4 and 5 games, where the party can't pass through dense forest or mountains at the start of the game, but can gain those abilities during play. I use it for the overworld autotiles.

I chose to do this by terrain tag because I want everything to be automatic. If I edit where woods are, I don't want to have to worry whether or not I changed the regions as well.

Terrain tags seem to be a feature that not many people use, so using them for this isn't likely to affect other aspects of gameplay.
Spoiler: How to use it
You can set terrain tags in the editor, under the "Tilesets" tab. On the right, above the "Note" area, there are several buttons to choose things to set for individual tiles. The bottom one is "Terrain Tag". A terrain tag can be any number between 0 and 7. This means that everywhere that has a tile with that terrain tag has that terrain tag.

Screenshot 2025-07-19 064508.png


Lots of tiles can have the same terrain tag. The default for all tiles is 0.

Using the plugin's parameters, you can choose a switch to control whether or not the player can pass through the tiles with that terrain tag. If the switch is "Off", the party can't enter or pass through. If it is "On", then they can.

You can do things like make the forest tiles passable by setting the switch when earlier in the game forest had been impassable. ("You are now all masters of woodcraft!").

Original thread: https://forums.rpgmakerweb.com/threads/terrain-tag-passability-pg_ttagpass-js.164894/