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,706
Reaction score
1,152
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 Posts

Latest Profile Posts

Quexp wrote on lumimae's profile.
Welcome! :)
Sonic and All Stars Racing Transformed (geez... what a long name) is my favorite racing game, I've spended lots of hous leveling my characters, learning new techs and polishing my runs. My friends don't want to play with me anymore because I'm too good according to them :kaoeh:
In 1314, King Edward II banned football. This is your random, useless bit of historical trivia for the day.
Ami
my USB Cable (which i buy myself since tuesday,it's the best pick one),has been exchanged with my mom's USB Cable (from my dad a few moments ago) :rtear:
It's time to Darkness of Hope - The Pocket Watch wake up. After DE:VOID has been released, we want to finish DoH TPW project. I think, we have a tight schedule. I'll update the thread later.

Forum statistics

Threads
100,626
Messages
977,930
Members
132,246
Latest member
lumimae
Top