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
669
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,701
Reaction score
1,147
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

Got inspired and started writing a simple tower defence battle system last night :o
Good news! I have located an amazing 3D website called SketchFab that has rotatable renderings of famous statues!
Picked up a physical copy of Megadimension Neptunia VII for the PS4 today. It's pretty good. I'm having a lot of fun with it.
The only upside of this remote semester was the plenty of funny photoshop material those facecams provided. Not that I would do that. Ever.

Forum statistics

Threads
100,516
Messages
976,707
Members
132,080
Latest member
nwr
Top