[ACE] How to access current map's regions? Or maybe how to check if tile is walkable?

Hello there!

I'm new to RPG Maker and got some questions regarding it. Also I'm new to Ruby, but I'm pretty well excperienced in programming in general, so I'm not affraid to dig into Ruby.

I'll start from the first challenge I've encountered. I want to implement a common in MMOs system when killed monster respawns elsewhere on the map. Also the default "encounter" system does not suit for me because I want the monsters to be displayed visually on the map.

I saw some scripts for respawning monsters, but I do want to respawn them on a random walkable position on map.

For this there could be two solutions, but I'm stuck trying to implement them.

Solution #1

First create a region on map covering all possible places of monsters to respawn. On monster's death move it's event to a random tile of that region, maybe with a delay.

So, the question is: how I can access map's regions from script to get random cell of specific region and get it's coordinates?

Solution #2

Upon monster's death cycle through random coordinates of current map until some walkable tile found and respawn monster there.

Here I'm stuck at RPG::Map data-structure. Firstly, I don't understand why it is 3-dimensional, because we have 2-d map? Secondly, how to determine if tile [x, y] is walkable?

Thanks in advance for your help covering my these two questions or possible help for achieving my goal 🙂
So, while my question was under approval, I spent some time investigating the Map class and actually found the answer to my question 🙂

First of all, solution #1 seems not possible (at least out of the box). There is no opportunity out of the box to get map's regions, because there is no such "entity" as region. Each tile has its own "attachment" to region, stored in the Map's data ($game_map.data[x, y, 3] >> 8). There could be a workaround by adding additional code: cycling through the whole map and filling my custom-made regions array. But that is to much work for me at the moment.

But, solution #2 turned out to be pretty simple. There is a method in a Map class called passable?, which gets three arguments: x, y, and direction.

$game_map.passable?(x, y, i)Where i is the direction and is one of the following values:

  • 2 - down
  • 4 - left
  • 6 - right
  • 8 - up
So now the question seems to be almost answered (by myself  🙂 ). I'll continue now further and when I'm done - I'll make a tutorial on how to make random respawn of monsters on map since I did not find any.
Amegatron, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


Tsukihime wrote a script that would allow you to spawn events randomly, based on regions.
This is one solution to that

(some methods might be misspelled, just writing this off my head)

def spawn_location pos = nil until pos x = rand($game_map.width) y = rand($game_map.height) next unless passable?(x, y) next unless $game_map.region_id(x, y) == ID pos = [x, y] end return posendFor the delay, you could just start a timer after the enemy dies and once it reaches 0 it'll run the respawn method, which should include the spawn location + reviving the enemy and setting the sprites, ect.

 how to determine if tile [x, y] is walkable?
There's a method inside Game_CharacterBase called passable?(x, y, dir) so you can do something like

Code:
$game_player.passable?(x, y, d)# or$game_map.events[ID].passable?(x, y, d)

Original thread: https://forums.rpgmakerweb.com/threads/ace-how-to-access-current-maps-regions-or-maybe-how-to-check-if-tile-is-walkable.37996/