How to stop all player movement input?

I'm trying to implement a carry weight system via events and basic scripting, which seems to almost work - aside from a game breaking error. Basically I run an event every 60 frames that checks if a variable is above or below a certain value, stopping all movement if true and allowing movement if false.
This is supposed to stop movement:
Code:
if($gamePlayer.moveByInputCached === undefined)
$gamePlayer.moveByInputCached = $gamePlayer.moveByInput;
$gamePlayer.moveByInput = function(){
return false;
}
And this is supposed to allow movement:
Code:
$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;

But I'm getting this error presumably whenever it runs, as it hits immediately lol
1730570234238.png


any way to make this work?
I'm trying to implement a carry weight system via events and basic scripting, which seems to almost work - aside from a game breaking error. Basically I run an event every 60 frames that checks if a variable is above or below a certain value, stopping all movement if true and allowing movement if false.
This is supposed to stop movement:
Code:
if($gamePlayer.moveByInputCached === undefined)
$gamePlayer.moveByInputCached = $gamePlayer.moveByInput;
$gamePlayer.moveByInput = function(){
return false;
}
And this is supposed to allow movement:
Code:
$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;

But I'm getting this error presumably whenever it runs, as it hits immediately lol
View attachment 321927

any way to make this work?
Hi, I use SDR restrict-movement-directions,
it allows you to block movements via switches.
There's 1 switch per direction, which is actually quite handy for certain situations, as you can block all 4 directions, or just some...
Just by looking at it I think the issue might be that the allow movement part runs before the $gamePlayer.moveByInputCached variable is assigned, so it puts an undefined value in the $gamePlayer.moveByInput

The quickest way to fix this would be to add a similar check as is present in the other part but with the condition flipped to !==
if($gamePlayer.moveByInputCached !== undefined) {
$gamePlayer.moveByInput = $gamePlayer.moveByInputCached;
}

Or you could just use a plugin as posted above 🙂

Original thread: https://forums.rpgmakerweb.com/threads/how-to-stop-all-player-movement-input.172984/