retrofiction

Villager
Member
Joined
Oct 26, 2015
Messages
8
Reaction score
0
Primarily Uses
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
62
Reaction score
41
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
404
Reaction score
473
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

Villager
Member
Joined
Oct 26, 2015
Messages
8
Reaction score
0
Primarily Uses
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 Posts

Latest Profile Posts

I have a micro economics midterm tomorrow. I'm not worried.
Should be a...small exam :kaojoy:
While was working on one of the monsters that will appear in my horor game I may have made harold a Lovecraftian monster. (I used his head to keep things aligned.)
Finally got my website fixed and the security sorted so it's been a productive day. Can I go to sleep now? I mean... I don't need to work right?
It's always a good idea to refresh yourself on what your plugins do. I'm working on a map with opening walls, and I was about to tear my hair out over how much image editing and hand-constructing of autotiles I'd have to do, when I looked again and saw @Shaz 's Tile Changer could copy areas from another map.
"sorry it took me so long to respond" - can we please agree not to say that anymore unless it actually took a long time?! (Like 36hrs at least) I mean, I'm running out of funny responses here xD

Forum statistics

Threads
115,923
Messages
1,094,073
Members
151,180
Latest member
GinTank
Top