Set Event Next To Player? (Need Passability Check)

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,224
First Language
English
Primarily Uses
RMMV
So uh, I'm trying to make an event always hug the player's location. It can either be in front, behind or beside the player; basically adjacent. How can I do this? There are 2 possible scenarios I'm thinking of...

A. Make the event adjacent to the player. This means one of the 8 tiles surrounding the player tile. How do I check if any of these 8 tiles are passable/impassable or if they're occupied? After that check, the event should randomly be at 1 of these 8 tiles.

B. Or instead of a random tile surrounding/next to the player, I would also be okay with a specific tile in relation to the player's location. However, this approach would also have to account for the player's facing/direction. For example, if the player is facing Down, the event should be at (x-1,y-1) or (x+1,y-1).

Edit: Actually, I think I really just need a way to check if a certain tile is occupied or impassable. Thx.
 
Last edited:

Aerosys

Veteran
Veteran
Joined
Apr 23, 2019
Messages
730
Reaction score
701
First Language
german
Primarily Uses
RMMZ
RPG Maker provides you with many features to choose from; using Variable Ops you can quickly get the player's position and direction. You need scripting only to check if a tile is passable, you can do that inside a Conditional Branch -> Tab 4.

Code:
$gameMap.isPassable($gamePlayer.x, $gamePlayer.y)

You need to play a bit with Variables, Switches, and Conditional Branches to combine this check with randomness.

Code:
Loop
  Variable random = Random 1..8

  If Variable random = 1
    Comment: check top
    If $gameMap.isPassable($gamePlayer.x, $gamePlayer.y - 1)
      Variable EventPositionX = Player X
      Variable EventPositionY = Player Y
      Variable EventPositionY - 1
      Relocate your Event to Variables (yes, this Event Command exists)
      Break Loop

.. do that for all the other directions

End Loop

You may want to ensure that at least one tile is passable, otherwise, it will be stuck in the Loop.
 

Frostorm

[]D[][]V[][]D
Veteran
Joined
Feb 22, 2016
Messages
2,788
Reaction score
2,224
First Language
English
Primarily Uses
RMMV
Thanks! All I was missing was that script call for checking passability. I got the rest in the bag now. ^.^

Honestly, I was already thinking about using that, but there's also canPass(), canPassDiagonally(), and isMapPassable() so I wasn't sure which to use...

Edit: I got it working but there are rare instances where the blue and red circles (aka the events) overlap and occupy the same tile. This happens when the player turns or changes direction in place in an area of the map where the intended tile is impassable.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

As you get older you notice how things you always used to do is starting to cause pain XD
I've always sitted on my feet for exemple and now I've started to develop knee pains that always occur after I sit in a way that I've ALWAYS done.
And am I going to stop doing it? Eh, likely not before it is causing me massive pain....:kaoswt:
Yay me...
Taking screenshot from later part of the game, to use as foreshadowing in earlier parts. :kaoblush:
So close to being finished with this portion, feels like it's been taking forever
Tukold2.PNGTukold3.PNGTukold1.PNG

Forum statistics

Threads
124,451
Messages
1,163,755
Members
163,272
Latest member
Krull
Top