retrofiction

Veteran
Veteran
Joined
Oct 26, 2015
Messages
32
Reaction score
16
First Language
German
Primarily Uses
RMMV
Hello!
I'm looking for a way to stop the player from moving when the OK button is being pressed. I still want the player to be able to change the direction by using the arrow keys (as well as all other keys), I just want him to stay on the spot as long as the button is being pressed.

For starters I found a solution somewhere to at least make the player stop doing anything while the OK button is being pressed (here by activating a switch upon button press):
JavaScript:
(function(alias) {
  Game_Player.prototype.getInputDirection = function() {
    if ($gameSwitches.value(10)) return 0;
    else return alias.apply(this, arguments);
  };
})(Game_Player.prototype.getInputDirection);

But it doesn't work properly at all, after a few minutes I'm getting a Maximum call stack size exceeded error message:
Unbenannt.PNG

Any ideas how to implement this?
Btw., my knowledge of JavaScript is very very basic...
 

autodidact

Veteran
Veteran
Joined
Nov 13, 2020
Messages
82
Reaction score
64
First Language
English
Primarily Uses
RMMV
If you don't mind trying someone else's code, I'd give Galv's Stationary Turn plugin a look.

I used a bit of code on line 73 to use a switch so I can halt walking and turn only. So, it should work for you. You'd have to decide if you were okay with always turning in place, or else you'd have to code in the stationary turn only when holding the okay button.
 
  • Like
Reactions: TSR

TSR

The Northern Frog
Veteran
Joined
Nov 14, 2019
Messages
451
Reaction score
535
First Language
French
Primarily Uses
RMMZ
Hello, if the solution above doesn't work for you, try to alias the canPass method:
Code:
var alias = Game_Player.prototype.canPass
Game_Player.prototype.canPass = function(x, y, d) {
    if (!this.isPressedOk()) {
        return alias.call(this, x, y, d);
    }
};

Game_Player.prototype.isPressedOk = function() {
    return Input.isPressed('ok') ||
           Input.isTriggered('ok') ||
           Input.isRepeated('ok');
};
 

retrofiction

Veteran
Veteran
Joined
Oct 26, 2015
Messages
32
Reaction score
16
First Language
German
Primarily Uses
RMMV
Hello, if the solution above doesn't work for you, try to alias the canPass method:
Code:
var alias = Game_Player.prototype.canPass
Game_Player.prototype.canPass = function(x, y, d) {
    if (!this.isPressedOk()) {
        return alias.call(this, x, y, d);
    }
};

Game_Player.prototype.isPressedOk = function() {
    return Input.isPressed('ok') ||
           Input.isTriggered('ok') ||
           Input.isRepeated('ok');
};
That actually works great, thank you!
What I noticed - I'm using Galvs Pseudo-Pixelmovement and when using the script above for some reason I can't change the direction to diagonal while pressing ok. Any idea how to fix that problem?
 

Latest Threads

Latest Profile Posts

It's not about your writing, it's about your mapping.
Newbie, please be gentle
reworkMZ.png
To keep myself motivated to make the MZ SF tiles normal and usable modern tiles I like to make tiny maps and toggle between the options :3
Character selection in games be like
Special Tractor Operation! :kaojoy:

Forum statistics

Threads
122,083
Messages
1,146,350
Members
160,368
Latest member
slotgacorunsurtoto
Top