Jump to content
Einargizz

Want to restrict player movement to one direction.

Recommended Posts

I wanted to create an event where you can only move in one direction and I wanted to see if there was a way to temporarily disable individual movement buttons on keyboard.

 

For example: An event calls for player to be only able to move up. For the duration of the event, left, right and down buttons are disabled.

 

Is this possible and if not, what else could I do to achieve a similar effect?

Share this post


Link to post
Share on other sites

some workaround method...

if it's not a hassle. you can try by teleporting to different map with one direction passage tileset. after the goal achieved. teleport back to the real map.

Share this post


Link to post
Share on other sites

module Input
  Disable_Dir = {
#Direction => Switch ID
         2 => 1,
         4 => 2,
         6 => 3,
         8 => 4,
  }
end

class Game_Player < Game_Character
  
  #--------------------------------------------------------------------------
  # * Processing of Movement via Input from Directional Buttons
  #--------------------------------------------------------------------------
  alias switch_disable_move_by_input move_by_input
  def move_by_input
    return if Input.dir4 > 0 && Input::Disable_Dir[Input.dir4] &&
      !$game_switches[Input::Disable_Dir[Input.dir4]]
     switch_disable_move_by_input
  end
  
end

I guess it's self-explaining: Turn on a switch to disable a direction.

Direction is the direction on your PC num-pad. 2 - Down; 4 - Left; 6 - Right; 8 - Up.

And I don't think you're using a 8-directional system, cuz this script is for 4 Dir only.

Edit: Fixed the derp.

Edited by Demintika

Share this post


Link to post
Share on other sites

some workaround method...

if it's not a hassle. you can try by teleporting to different map with one direction passage tileset. after the goal achieved. teleport back to the real map.

 

I came up with a similar solution, using the script that was available over here. Using that, I could create a trench like region that the player could navigate through. The only problem with it is that the player can still walk back and forth.

 

module Input
  Disable_Dir = {
#Direction => Switch ID
         2 => 1,
         4 => 2,
         6 => 3,
         8 => 4,
  }
end

class Game_Player < Game_Character
  
  #--------------------------------------------------------------------------
  # * Processing of Movement via Input from Directional Buttons
  #--------------------------------------------------------------------------
  alias switch_disable_move_by_input move_by_input
  def move_by_input
    return if Input.dir4 > 0 && Input::Disable_Dir[Input.dir4] &&
      !$game_switches[Input::Disable_Dir[Input.dir4]]
      disable_move_by_input
  end
  
end

 

 

I guess it's self-explaining: Turn on a switch to disable a direction.

Direction is the direction on your PC num-pad. 2 - Down; 4 - Left; 6 - Right; 8 - Up.

And I don't think you're using a 8-directional system, cuz this script is for 4 Dir only.

 

 

You're right about me using only 4 directions. However, I'm forced to admit that I'm not 100% certain on how to properly implement your code. I tried placing it with my other scripts but the game tosses an error, if I do so. I'm assuming that's not what I'm supposed to do with it.

Share this post


Link to post
Share on other sites

Seems he forgot to add "switch_" in alias method name 

class Game_Player < Game_Character
  
  #--------------------------------------------------------------------------
  # * Processing of Movement via Input from Directional Buttons
  #--------------------------------------------------------------------------
  alias switch_disable_move_by_input move_by_input
  def move_by_input
    return if Input.dir4 > 0 && Input::Disable_Dir[Input.dir4] &&
      !$game_switches[Input::Disable_Dir[Input.dir4]]
      disable_move_by_input # <-- change this part
  end
  
end
class Game_Player < Game_Character
  
  #--------------------------------------------------------------------------
  # * Processing of Movement via Input from Directional Buttons
  #--------------------------------------------------------------------------
  alias switch_disable_move_by_input move_by_input
  def move_by_input
    return if Input.dir4 > 0 && Input::Disable_Dir[Input.dir4] &&
      !$game_switches[Input::Disable_Dir[Input.dir4]]
      switch_disable_move_by_input # <-- into this one
  end
  
end
  • Like 1

Share this post


Link to post
Share on other sites

Seems he forgot to add "switch_" in alias method name

Oh well, I derped. At first I planned to use

disable_move_by_input

but I was afraid about compatibility so I decided to use

switch_disable_move_by_input

Share this post


Link to post
Share on other sites

Hmm... It's no longer tossing an error, when I start the game but it looks like the code is automatically disabling the movements, as if the switches were already on.

 

I tried creating an event that automatically turns the switches off, at the begining of the map but I still can't move the character.

 

I'm assuming we are talking about switches 1-4, unless I were to change the

 

#Direction => Switch ID
         2 => 1,
         4 => 2,
         6 => 3,
         8 => 4,
into

#Direction => Switch ID
         2 => X,
         4 => Y,
         6 => Z,
         8 => Q,
where X, Y, Z and Q are the number of the switches I choose to define for this function (I still haven't done this, btw). Edited by Einargizz

Share this post


Link to post
Share on other sites

I derped again. Just turn switch on to enable;

OR

remove the ! in

!$game_switches[Input::Disable_Dir[Input.dir4]]
Yeah, XYZQ are switch numbers; AND they can be the same (disable 3 direction with 1 switch?)

P/s: Press F8 while in TEST mode to turn on/off switch

Edited by Demintika

Share this post


Link to post
Share on other sites

P/s: Press F8 while in TEST mode to turn on/off switch

I believe, it should be F9 :P

Share this post


Link to post
Share on other sites

Works like a charm now. Thanks allot.

 

So, would you like me to give you credit in the finished release? Special thanks?

Share this post


Link to post
Share on other sites

since he wrote you some code. you should put him on scripts section of the credits. it's my opinion though.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted