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
406
Reaction score
474
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 Profile Posts

I just don't know why, but it's funny.
5.gif
Ugh. The one time I forget to save every hour or so is also the day my computer crashes. That's life!
Even though I spent 100's of dollars on my game already. I think I might just have to give it away for free. Since I haven't heard back from people if I could use some of their graphics. Even from a global mod here. Maybe I can make a donation thing.
you know, some days you get resentful that game dev is even considered a "fun job" and other days it's like, welp, time to roll up my sleeves and code these molotov cocktails
If you suck at playing trumpets, that is probably why.

Forum statistics

Threads
115,964
Messages
1,094,435
Members
151,234
Latest member
sousou123232
Top