MZ Make that this plugin can be turned ON and OFF by switch (very short code) (LEFT/RIGHT movement only on map).

Hello, I know that this question has been asked many times, and that this is upon the plugin developer to provide such function.

However, since the plugin is absolutely short, it should be really easy to give it the possibility to be turned off... or better said, make that when Switch number is ON, plugin uses the changed code, and when switch number is OFF, plugin uses the unchanged code.

This plugin is to make that character only uses Left and Right sprites in Map, but I want to use this feature only under specific cases while in map.

Here's the code:
JavaScript:
//-----------------------------------------------------------------------------
// 2D Fixed Direction (Horizontal)
/*:
 * @plugindesc Only allows player to face left or right (even when moving up or down). Example uses Platformer or Brawler/Beat'em Ups.
 * @author Quasi      Site: http://quasixi.com
 * @help This plugin does not provide plugin commands.
 */
(function() {
  var Alias_Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
  Game_CharacterBase.prototype.setDirection = function(d) {
    if (d === 4 || d === 6) {
      Alias_Game_CharacterBase_setDirection.call(this, d);
    }
  };
}());

As you see, the code is really short, so it shouldn't be a problem to make that it takes effect when a switch is ON/OFF.

I assume that the normal code is this one (not sure):
JavaScript:
Game_CharacterBase.prototype.setDirection = function(d) {
    if (!this.isDirectionFixed() && d) {
        this._direction = d;
    }
    this.resetStopCount();
};


Thanks in advance.
Hi there!

This should work:

JavaScript:
//-----------------------------------------------------------------------------
// 2D Fixed Direction (Horizontal)
/*:
 * @plugindesc Only allows player to face left or right (even when moving up or down). Example uses Platformer or Brawler/Beat'em Ups.
 * @author Quasi      Site: http://quasixi.com
 * @help This plugin does not provide plugin commands.
 */
(function() {
  var Alias_Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
  Game_CharacterBase.prototype.setDirection = function(d) {
      if($gameSwitches.value(ID)){
            if (d === 4 || d === 6) {
                  Alias_Game_CharacterBase_setDirection.call(this, d);
            }
          }else{
            Alias_Game_CharacterBase_setDirection.call(this, d)
        }
  };
}());

Replace ID with the switch ID you want to use to disable/enable the plugin feature
Hi there!

This should work:

JavaScript:
//-----------------------------------------------------------------------------
// 2D Fixed Direction (Horizontal)
/*:
 * @plugindesc Only allows player to face left or right (even when moving up or down). Example uses Platformer or Brawler/Beat'em Ups.
 * @author Quasi      Site: http://quasixi.com
 * @help This plugin does not provide plugin commands.
 */
(function() {
  var Alias_Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
  Game_CharacterBase.prototype.setDirection = function(d) {
      if($gameSwitches.value(ID)){
            if (d === 4 || d === 6) {
                  Alias_Game_CharacterBase_setDirection.call(this, d);
            }
          }else{
            Alias_Game_CharacterBase_setDirection.call(this, d)
        }
  };
}());

Replace ID with the switch ID you want to use to disable/enable the plugin feature

So fast! Thank you! It works as intended.

On a side note, would be possible to make that this also applies to followers? 🙂

EDIT: NVM, it already affects followers, was a thing from my side.

Original thread: https://forums.rpgmakerweb.com/threads/make-that-this-plugin-can-be-turned-on-and-off-by-switch-very-short-code-left-right-movement-only-on-map.166132/