retrofiction

Veteran
Veteran
Joined
Oct 26, 2015
Messages
50
Reaction score
21
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
488
Reaction score
582
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
50
Reaction score
21
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 Posts

Latest Profile Posts

Currently at beginner level, checking tutorials on YT and Skillshare
If you like my music I'm open for commissions. You can also visit my website by clicking here to know more about my work.
I know it can be a little confusing with all the advent calendars and time zones, but make sure Starbird, GalacticGod, WaywardMartian and Guardinthena get all the love they deserve fot their hard work! ;3
*it's getting better all the time* tenacious determination (got bills to pay) and doing PT for this gimpy hand - I'm improving quite a bit. :rock-left::troll::rock-right: Had to resign from my fav Lead Security Analyst job because I couldn't type to keep pace ;_; however, Big N kept me on, so finishing my contracts with them. :D
I was playing with ChatGPT-3 and I feels like did some crime with this...

1670127825626.png

Forum statistics

Threads
127,020
Messages
1,183,288
Members
166,897
Latest member
yeonanha
Top