Check if player's co-ordinates match those of any event.

Joined
Sep 28, 2019
Messages
23
Reaction score
9
First Language
English
Primarily Uses
RMMV
Hi everybody, happy weekend!

I'm trying to find a conditional script that would let me check if the player's co-ordinates match with any of the events on the map.
This is because Yanfly's Event Spawner plugin won't spawn events where there are already events present on the map.
I'm trying to spawn events right under the player, which works fine unless the player is already over an existing event.
This isn't a problem in itself, but I'd like a conditional check which can show the player a message, telling them to find a clear space.
At the moment, the plugin executes as normal but without spawning a new event.

I need to find whether the player is standing over any of the events on the map at the time they choose to spawn a new event.
I'd really like to avoid having to check the player's position versus every single event ID on the map!

Any help, or suggestions about where to look, would be appreciated.
I already checked the big script calls document and nothing occured to me, but I am a bit nooby so...
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,961
First Language
English
Primarily Uses
RMMV
$gameMap.events().some(event => $gameMap.eventsXy($gamePlayer.x, $gamePlayer.y).includes(event))

Will return true if the player is on a map event, and false otherwise.
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,848
First Language
English
If you wanted a general function that checks if there are any events at a specified position (assuming you're using default RPG Maker position system), it would be convenient to have a function that you can call from your events.

You can create a new plugin (open notepad, copy code, save in plugins folder) that contains

Code:
function anyEventsAt(x, y) {
  var events = $gameMap.events();
  for (var i = 0; i < events.length; i++) {
    var ev = events[i];
    if (ev.x === x && ev.y === y) {
      return true;
    }
  }
  return false;
}
Then add the plugin to your project. The code can probably be optimized but it's the basic logic.

Then you can use a script condition to pass in the player's current position

Code:
anyEventsAt($gamePlayer.x, $gamePlayer.y)
This can also be used to check if there are any events at any particular position by passing in any position that you want

Code:
anyEventsAt(2, 3)
 
Joined
Sep 28, 2019
Messages
23
Reaction score
9
First Language
English
Primarily Uses
RMMV
If you wanted a general function that checks if there are any events at a specified position (assuming you're using default RPG Maker position system), it would be convenient to have a function that you can call from your events.

You can create a new plugin (open notepad, copy code, save in plugins folder) that contains

Code:
function anyEventsAt(x, y) {
  var events = $gameMap.events();
  for (var i = 0; i < events.length; i++) {
    var ev = events[i];
    if (ev.x === x && ev.y === y) {
      return true;
    }
  }
  return false;
}
Then add the plugin to your project. The code can probably be optimized but it's the basic logic.

Then you can use a script condition to pass in the player's current position

Code:
anyEventsAt($gamePlayer.x, $gamePlayer.y)
This can also be used to check if there are any events at any particular position by passing in any position that you want

Code:
anyEventsAt(2, 3)
This works perfectly, thankyou so much.
 

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

Latest Threads

Latest Profile Posts

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.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top