MV Finding the closest regional tile with a specific number (RPGMaker MV)

Short version:
I need a way of getting the x and y of the closets regional id numbered 3.

Fully-explained:
So I'm building my game, and I've designated tiles as hiding spots like trees and boxes as Danger Spots, and I gave them an ID of 3 (I chose based on color...)
I then have regional IDs (set to ID1) around that Danger Spot to designate that hiding spots area of effect (Danger Area).
(so visually the tree here are the danger, but the spots around it are the actual bits which trigger events)
ID Problem Image.png


I've got the parallel event to check when a player walks onto a Danger Area to randomise and trigger an event if they are unlucky; however, I want there to be a short Autorun event where a figure jumps out from the Danger Spot at the player. It's not efficient to make an event for each spot, so I was hoping to get a solution here.

My current plan is to have 1 event. When the player steps on a Danger Area the parallel function triggers an 'Event Set Location' command, and then script call to trigger the self-switch of the moved event to start.

The issue I have is finding a way to get the x and y of a regional tile (Id 3) that is closest to the player.
Any thoughts on this super-specific scenario I got myself in.
I wrote a script for Shaz's pathfinder to go the closest tile of region x

A potential issue is it goes by distance on map, and doesn't take into account cliffs or obstacles. So if the closest region is at the top of that cliff and youre at the bottom of the cliff, it will use that region even if the paths to the bottom of the cliff regions are shorter
It's not efficient to make an event for each spot
Why not? That's most likely what I would do, based on your screenshot.

I would make one event that references the specific location of each tree, and copy-paste it around that tree.

But you can certainly also do it the way you describe and use what Aqua posted.
Hello everyone, I had a brainwave and finished it. It works now.
Thank you for your suggestions though.

solution was:
Make two variables storing the to-be-checked tiles x and y value , and have them directed around the player starting at (player.x-1,player.y-1) to (player.x+1,player.y+1)
They then checked the tile using $gameMap.regionId(x,y) (which I keep typing as regionalId....) if that tile id was 3.
If it was triggered $gameMap.event(id).locate(x,y) using those values
$gameSelfSwitch.setValue to trigger the autorun event
breakloop

Original thread: https://forums.rpgmakerweb.com/threads/finding-the-closest-regional-tile-with-a-specific-number-rpgmaker-mv.165327/