Make a Tile Unpassable Using Regions

mega01man

Villager
Member
Joined
Jan 29, 2017
Messages
14
Reaction score
3
First Language
Tagalog
Primarily Uses
RMMV
Hello, I'm trying to make a short plugin that just prevent the player on walking on tiles with a set region(say region 1). I am aware there are quite a few of region plugins that are amazing and does what I want to do. But I'm just trying to make a little plugin specifically only to the player.

I'm confused on what following properties should I use to make the player not walk to the tile.
  • $gamePlayer.setThrough();
  • $gamePlayer.moveByInput();
  • $gamePlayer.canMove();
  • $gamePlayer.canPass();
  • $gamePlayer.isCollided();
  • $gameMap.isValid();
  • $gameMap.passable();
I can get the following data: $gamePlayer.regionId, $gameMap.regionId, $gamePlayer.x, $gamePlayer.y
 

Fornoreason1000

Black Sheep
Veteran
Joined
Mar 1, 2014
Messages
206
Reaction score
95
First Language
English
Primarily Uses
RMMV
Okay I'll start by explaining what each of those properties are

$gamePlayer.setThrough(bool); this is a function that will turn on or off the collision of the player, when bool true the player will move 'through' everything. when false, the player collides normally.
$gamePlayer.moveByInput(); this function tells the player to move based on the players input
$gamePlayer.canMove(); This function returns a bool depending on whether the engine will let the player move or not. this is not necessarily caused by collision, such as when a event runs the player will not move.
$gamePlayer.canPass(); This function returns true when the player attempts to move on a "passable" tile. (use this)
$gamePlayer.isCollided(); This function returns true when a play attempts to move on an unpassable tile or an event attempts to pass through the player.
$gameMap.isValid(x, y); this function take in a set of coordinates and checks if they are within the Maps limits. returns true if they are.
$gameMap.passable(); doesn't exists a.k.a undefined. $gameMap.isPassable?.

a very easy cheesy way to make your code only affect the player, is to define the new behavior in Game_Player . we override the inherited function Game_CharacterBase.canPass(); , kinda like this. remember , we want to return a Boolean on this function.

Code:
Game_Player.prototype.canPass = function(x,y,d) {

//this var will be true when the tile is normally passable, e.g grass
var normalPass = Game_CharacterBase.prototype.canPass(this, args);

// add you if block here that checks the region is passable, inside put return false;

return normalPass; //return normally.
};
 
Last edited:

mega01man

Villager
Member
Joined
Jan 29, 2017
Messages
14
Reaction score
3
First Language
Tagalog
Primarily Uses
RMMV
thank you very much! it worked! thank you for your explanation of what the properties are! :kaosalute:

It made more sense and $gameMap.passable() is a type i didn't catch, you're right, it's supposed to be $gameMap.isPassable().

i would also like to ask a few of questions.

In order for this to work, why did we create a new behavior on Game_Player? Is it because it only affects the player? If, for example, one decided to make the player's party or any character to walk on that tile, would one add a new behavior on Game_Character(for any characters) or Game_Party(player's party)?

Also when I was applying your answer, I kept getting args is not defined. I removed 'args' and replaced it with 'x, y, d'. Then I got, max call stack error, googled searched it and inferred it was exceeding the number of arguments the Game_CharacterBase is accepting, so I removed 'this'. And then it worked.
 
Last edited:

Fornoreason1000

Black Sheep
Veteran
Joined
Mar 1, 2014
Messages
206
Reaction score
95
First Language
English
Primarily Uses
RMMV
Okay the reason we add it only to Game_Player is becuase Game_Player represents the player or character you control.
Game_Character on the other hand is a Base class of Game_Events, Game_Followers AND Game_Player. There is no in-built way to differentiate between the three. Which means if you added it to Game_Character, all events, followers and the Player will collide with regions which is exactly what you do not want.


the error is my fault, i forgot to add call to it it should be. you can also use Apply(). In the case of Apply() you substitute x,y,d with arguments (not args like I did). the result should be the same.
Code:
var normalPass = Game_CharacterBase.prototype.canPass.call(this, x,y,d);
I'm unsure of the repercussions of just invoking the base method normally. I think its something to do with the value of this changing unexpectedly. but the method I'm using is what is usually used to call inherited functions after overriding them.
 

mega01man

Villager
Member
Joined
Jan 29, 2017
Messages
14
Reaction score
3
First Language
Tagalog
Primarily Uses
RMMV
Thank you for explaining it to me. I understand it better now.

I tried the line of code you newly posted and yes it did work. What I have before was:
Code:
var normalPass = Game_CharacterBase.prototype.canPass(x, y, d);
Thank you again for your answers! :kaosalute:
 

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

Latest Threads

Latest Profile Posts

Day 9 of giveaways! 8 prizes today :D
He mad, but he cute :kaopride:

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.

Forum statistics

Threads
106,040
Messages
1,018,476
Members
137,824
Latest member
dobratemporal
Top