Get x,y location of Terrain Tag

BloodMists

Villager
Member
Joined
Mar 21, 2018
Messages
7
Reaction score
2
First Language
English
Primarily Uses
Other
I spent a great deal of time trying to figure this out myself and searching the web for help, but I can't find anything that talks on what I want.

Simply put, is there a way to get the x,y coordinates for a specific terrain tag?

Just as example, I want to make a common event for the player to sit at a table, but the chair can be in any 1 of 4 spaces, see below. Each chair is marked with a terrain tag of 1.



As it's meant to be a common event I can't just input coordinates, and I'm not sure of any other way of doing it aside from using an absolutely silly amount of variables, or creating a new event, coping the reliant code, & editing it to fit the situation perfectly every time, which kinda makes making it a common even useless. While I do think it could be done by using a silly amount of variables, each one being input by the event that will need to be situated on the table anyway, it would quickly become a mess of epic proportions even with proper commenting. Besides, if a simpler way using terrain tags is possible, why not use it.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
It works the other way. You have the coordinates, and you use Get Location Info to return the terrain tag at that location.

So if your stool could be in one of 4 places, you will need to repeat the process up to 4 times until you get the correct terrain tag returned.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
It wouldn't take much to write a loop that would check every single tile on the map and stop when it finds one with the required terrain tag. Or if you could have multiple, it could build a list of coordinates that have that terrain tag and then you would have to figure out how to choose between them.
 

BloodMists

Villager
Member
Joined
Mar 21, 2018
Messages
7
Reaction score
2
First Language
English
Primarily Uses
Other
I hadn't thought of that. Think it could be simplified to "search" just the tiles adjacent to an event?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Yes. Use a common event to search around the specified event id, and use a map event to set a variable to the event id you're looking at.

So let's say event 8 is at the location of the table, we'll store the event id into variable 15, and we want the stool coordinates to be placed into variables 16 and 17. We're using terrain tag 2 for the stool location.

Prior to calling the common event, set variable 15 to 8 (the id of the event we want to search around).

In your common event, do the following script call:
Code:
var x1 = $gameMap.event($gameVariables.value(15)).x - 1;
var x2 = $gameMap.event($gameVariables.value(15)).x + 1;
var y1 = $gameMap.event($gameVariables.value(15)).y - 1;
var y2 = $gameMap.event($gameVariables.value(15)).y + 1;
for (var y = y1; y <= y2; y++) {
  for (var x = x1; x <= x2; x++) {
    if ($gameMap.terrainTag(x, y) === 2) {
      $gameVariables.setValue(16,x);
      $gameVariables.setValue(17,y);
    }
  }
}
After that common event runs, variables 16 and 17 will have the location of the last tile found with terrain tag 2.
This works on the assumption that there always will be at least one stool with terrain tag 2 around that event. If there isn't, you could end up with entirely different coordinates in those values, from the last time the common event was run successfully (which could be from a different map).
 

BloodMists

Villager
Member
Joined
Mar 21, 2018
Messages
7
Reaction score
2
First Language
English
Primarily Uses
Other
Thank you for the advice & assistance Shaz, I found it to be extremely helpful. Thanks to you I now have a fully functional, plug & play common event that finds the number of seats around a "table", notes the number of them & their locations, and then send the various party members to an assigned seat. (Still working on randomly chosen seats.) So once again, thank you.

-BloodMists
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top