Override Player Inputs

nathanlink169

Game Dev by Career, no idea what I'm doing
Veteran
Joined
Aug 15, 2013
Messages
66
Reaction score
29
First Language
English
Primarily Uses
RMMV
Hi all,

I'm looking for how I would go about hijacking the player's input to prevent the inputs from actually moving the player. I'm thinking it would look something like this:
Code:
if (overridePlayerMovement)
{
  // Do something with the movement
}
else
{
  base.PlayerMovement();
}
Does anyone have any experience with something like this?
 

Eliaquim

Hakuen Studio
Veteran
Joined
May 22, 2018
Messages
1,418
Reaction score
671
First Language
Portuguese - Br
Primarily Uses
RMMV
Hi!
I think the right function is that one from RPG objects:
JavaScript:
Game_Player.prototype.moveByInput = function() {
    if (!this.isMoving() && this.canMove()) {
        var direction = this.getInputDirection();
        if (direction > 0) {
            $gameTemp.clearDestination();
        } else if ($gameTemp.isDestinationValid()){
            var x = $gameTemp.destinationX();
            var y = $gameTemp.destinationY();
            direction = this.findDirectionTo(x, y);
        }
        if (direction > 0) {
            this.executeMove(direction);
        }
    }
};
You will have to alias that then you can put your if condition like:
JavaScript:
const alias = Game_Player.prototype.moveByInput;
Game_Player.prototype.moveByInput = function() {
if(your condition){
    // do your code
}else{
    alias.call(this);
}
};
EDIT:
This function is called on game player update:
JavaScript:
Game_Player.prototype.update = function(sceneActive) {
    var lastScrolledX = this.scrolledX();
    var lastScrolledY = this.scrolledY();
    var wasMoving = this.isMoving();
    this.updateDashing();
    if (sceneActive) {
        >>>>>>>> this.moveByInput(); <<<<<<<
    }
    Game_Character.prototype.update.call(this);
    this.updateScroll(lastScrolledX, lastScrolledY);
    this.updateVehicle();
    if (!this.isMoving()) {
        this.updateNonmoving(wasMoving);
    }
    this._followers.update();
};
 

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,703
Reaction score
1,148
First Language
EN
Primarily Uses
RMMV
If you just want to override the move direction then you can alias getInputDirection, e.g.
JavaScript:
(function(alias) {
  Game_Player.prototype.getInputDirection = function() {
    if ($gameSwitches.value(1)) return 0;
    else return alias.apply(this, arguments);
  };
})(Game_Player.prototype.getInputDirection);
I.e. "if game switch #1 is on then there is no input direction, otherwise get input as normal".
 

nathanlink169

Game Dev by Career, no idea what I'm doing
Veteran
Joined
Aug 15, 2013
Messages
66
Reaction score
29
First Language
English
Primarily Uses
RMMV
Thank you both! Did the trick exactly!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

I've invented a cheap way to manipulate weather. Should I get it patented?
It's change from frikin' hot to beautiful at the cost of only 4 beers.
I think is french enough.
Yanfly told me the new earth all animations in MZ look a bit like summoning potatoes and now I can't unsee it. halp
Despite time and all the other things I am working on, I decided that I am going to start a Fire Emblem-like project. Follow your dreams! I'll just have to balance hours efficiently. I'm also not making this as complex as my Might and Magic inspired project, so it will be a much easier project to work on.

Forum statistics

Threads
100,587
Messages
977,533
Members
132,186
Latest member
layer6ai
Top