MV Stepping on region IDs changes Variables.

I've been looking all over for a plugin that gives the region IDs the ability to change Variables and Switches when stepped on, but I just don't find anything. (Or I'm just too stupid to understand coding).

What I've been trying to do:
- First, I've been using Galvs Layer graphics, so you know what plugin I'm using.
- Second, I want specific layer graphics/pictures to have a different opacity when the player steps on a region id, making it possible to see the player behind it.
Something like this:

Spoiler: Examples:
Full Opacity:
Screenshot 2025-10-06 135558.png

Less Opacity:
Screenshot 2025-10-06 135636.png


So far, I've been able to do this through changing the variable with an event. But this is not what I had in mind. I want to add pictures that change opacity when the player is behind it.

I thought using region IDs would be the easiest way, but I haven't found a plugin that gave them the ability to change variables and switches.

If there is, I'd be very happy if someone could show me. If not, I would pay for one to be made.

Aside from that, I also have a little problem with Galvs plugin. When I take a few steps, the ground layer under the player disappears. But when I go back to the initial position, it reappears. I haven't changed much from the example commands in the plugin.
Spoiler: This is how it looks after a few steps:
Screenshot 2025-10-06 135911.png


I'd be very grateful if anyone of you could help me out.
You can change switches and variables, depending on the current Region Tiles, with a Common Event that runs with parallel process:

Then you want to create 5 Variables:
- last Player X
- last Player Y
- next Player X
- next Player Y
- Region ID

And 1 Switch:
- Position has changed

Code:
Variable Next Player X = Player X Pos
Variable Next Player Y = Player Y Pos
Conditional Branch Last Player X is NOT Next Player X
  Set Switch "Position has changed" to ON
End Branch
Conditional Branch Last Player Y is NOT Next Player Y
  Set Switch "Position has changed" to ON
End Branch
Conditional Branch Switch "Position has changed" is ON
  Variable Region = PlayerRegion ID
  Variable last Player X = next Player X
  Variable last Player Y = next Player Y
  
  --> configure switches and variables here
  Set Switch "Position has changed" to OFF
End Branch

Wait a few milliseconds

That's 1 way you can do it, there are probably many more!
I had a code to change opacity that swap events from normal to opacity.
this require the normal and opacity one, but dealing with layers can
be tricky.

if you want to avoid it, I do have a plugin to show the character behind tiles,
unsure for layers though which I didn't test.

but the above way may work out for you, depending how galv layers work.
@Aerosys I think you forgot to update the Last Player X/Y there?
this is my region switch ID barrier
Code:
/*:
 * @plugindesc [v1.1] RegionSwitchBarrier - Prevent passage in region unless switch is ON (MV Compatible + Optimized)
 * @author xabileug
 *
 * @help
 * Blocks player movement into region-painted tiles unless a corresponding switch is ON.
 * Automatically refreshes when switch is changed.
 *
 * ============================================================================
 * @param Region Switch Map
 * @type struct<RegionSwitch>[]
 * @desc Map region IDs to switch IDs. Player cannot pass tiles in the region unless the switch is ON.
 * @default []
 */

/*~struct~RegionSwitch:
 * @param Region ID
 * @type number
 * @min 1
 * @desc The Region ID painted on the map.
 *
 * @param Switch ID
 * @type switch
 * @desc The switch required to enable passage through this region.
 */

(function () {
    const parameters = PluginManager.parameters('RegionSwitchBarrier');
    const regionSwitchMap = JSON.parse(parameters['Region Switch Map'] || "[]").map(entry => {
        const data = JSON.parse(entry);
        return {
            regionId: Number(data["Region ID"]),
            switchId: Number(data["Switch ID"])
        };
    });

    const _Game_Map_checkPassage = Game_Map.prototype.checkPassage;
    Game_Map.prototype.checkPassage = function (x, y, bit) {
        const regionId = this.regionId(x, y);
        for (let i = 0; i < regionSwitchMap.length; i++) {
            const entry = regionSwitchMap[i];
            if (regionId === entry.regionId && !$gameSwitches.value(entry.switchId)) {
                return false;
            }
        }
        return _Game_Map_checkPassage.call(this, x, y, bit);
    };

    const _Game_Switches_setValue = Game_Switches.prototype.setValue;
    Game_Switches.prototype.setValue = function (switchId, value) {
        _Game_Switches_setValue.call(this, switchId, value);
        if (regionSwitchMap.some(entry => entry.switchId === switchId)) {
            if ($gamePlayer) {
                $gamePlayer.refresh();
            }
        }
    };
})();

Code:
/*:
 * @plugindesc [v1.1] RegionVariableToggle - Change variable by operation when stepping on Region
 * @author xabileug
 *
 * @help
 * Changes a variable's value when the player steps onto a tile with the given Region ID.
 * Supports operations: set, add, sub, mul, div, mod.
 *
 * Console output example:
 *   player stepped on Region ID 3, var ID 14 value from 5 to 6
 *
 * Supports negative values and Once Per Step.
 *
 * @param Region Variable Map
 * @type struct<RegionVariable>[]
 * @default []
 */

/*~struct~RegionVariable:
 * @param Region ID
 * @type number
 * @min 1
 *
 * @param Variable ID
 * @type variable
 *
 * @param Change Value
 * @type number
 *
 * @param Variable Operation
 * @type select
 * @option set
 * @option add
 * @option sub
 * @option mul
 * @option div
 * @option mod
 * @default add
 *
 * @param Repeat Per Step
 * @type boolean
 * @on No
 * @off Yes
 * @default true
 */
(function() {

    const params = PluginManager.parameters('RegionVariableToggle');
    const regionVarMap = JSON.parse(params['Region Variable Map'] || "[]").map(entry => {
        const data = JSON.parse(entry);
        return {
            regionId: Number(data["Region ID"]),
            variableId: Number(data["Variable ID"]),
            changeValue: Number(data["Change Value"]),
            operation: String(data["Variable Operation"] || "add"),
            repeatPerStep: String(data["Repeat Per Step"]) === "true"
        };
    });

    const _Game_Player_moveStraight = Game_Player.prototype.moveStraight;
    Game_Player.prototype.moveStraight = function(d) {
        _Game_Player_moveStraight.call(this, d);
        if (this.isMovementSucceeded()) {
            const regionId = $gameMap.regionId(this.x, this.y);
            const entry = regionVarMap.find(e => e.regionId === regionId);
            if (!entry) return;

            if (!this._lastRegionVarIds) this._lastRegionVarIds = {};

            if (!entry.repeatPerStep && this._lastRegionVarIds[regionId]) return;

            const vid = entry.variableId;
            const oldVal = Number($gameVariables.value(vid) || 0);
            let newVal;

            switch (entry.operation) {
                case 'add': newVal = oldVal + entry.changeValue; break;
                case 'sub': newVal = oldVal - entry.changeValue; break;
                case 'mul': newVal = oldVal * entry.changeValue; break;
                case 'div': newVal = oldVal / entry.changeValue; break;
                case 'mod': newVal = oldVal % entry.changeValue; break;
                case 'set':
                default:    newVal = entry.changeValue; break;
            }

            $gameVariables.setValue(vid, newVal);

            console.log(
                `player stepped on Region ID ${regionId}, var ID ${vid} value from ${oldVal} to ${newVal}`
            );

            this._lastRegionVarIds[regionId] = true;
        }
    };

    const _Game_Player_update = Game_Player.prototype.update;
    Game_Player.prototype.update = function(sceneActive) {
        if (this.isMoving()) {
            this._lastRegionVarIds = {};
        }
        _Game_Player_update.call(this, sceneActive);
    };

})();
I managed to actually get it done. And even without too much scripting.

Thanks to everyone for helping me. I guess the thread can be closed now.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/stepping-on-region-ids-changes-variables.180437/