MV Alter Galv's Event Spawning to allow certain overlapping


I would like to spawn events on other events IF the existing event has the through option checked or is above/below the character priority.

I attempted to do this myself but I'm having issues.
I tried adding && $gameMap.eventIdXy(x, y)._through != true to the if statement in line 164 but I discovered for some reason ._through is always undefined for the event in question when I call it specifically, even if it's true when I log all the values inside of the event. Same with ._priorityType being 2. The event I'm trying to check ._through/._priorityType for is also spawned in with this plugin.

The reason I need this is because I have my hoe from Galv's Simple Tools/Crops using Event Spawning to create the tilled dirt to plant in, and I would like to have an indicator show where the dirt would be spawned while the hoe is equipped. I'm doing this currently by having an event spawned in front of the player, but this event is blocking the dirt from being spawned in. I don't want the dirt to be spawnable in every location so I don't want to change it to be spawnable on top of all events.

Thank you in advance for any help.
That's because eventIdXy returns an ID, not a Game_Event instance. And obviously numbers don't have a _through property.
Hi there! ^^

You are almost there!

The thing is, the function $gameMap.eventIdXy(x, y) will return the event id that is on that coordinate.
So, you can't use "._through", because it is a number, instead of an event.
But, I believe maybe you can achieve what you want, using the $gameMap.eventsXy(x, y)

This, instead of a number, will return an array, with all the events on that coordinate.
So you will need to check all these events and see if one or all of them, has the through set to TRUE.

So, if you just need one event with the through ON, use "some"
If you need all events on that coordinate with through ON, use "every"

Replace line 164 with that below:

JavaScript:
if ($gameMap.eventsXy(x, y).length > 0 && $gameMap.eventsXy(x, y).some(event => event._through === false)) return false;

I just add:
&& $gameMap.eventsXy(x, y).some(event => event._through === false)) return false;

I can think of other ways to implement this feature in a safe way, instead of changing just line 164. But I do not have that time now. See if the above solution will work for you.
That's because eventIdXy returns an ID, not a Game_Event instance. And obviously numbers don't have a _through property.
I feel really dumb for not noticing that mistake lol I must've been so drained from looking at the wrong part of the problem.


Hi there! ^^

You are almost there!

The thing is, the function $gameMap.eventIdXy(x, y) will return the event id that is on that coordinate.
So, you can't use "._through", because it is a number, instead of an event.
But, I believe maybe you can achieve what you want, using the $gameMap.eventsXy(x, y)

This, instead of a number, will return an array, with all the events on that coordinate.
So you will need to check all these events and see if one or all of them, has the through set to TRUE.

So, if you just need one event with the through ON, use "some"
If you need all events on that coordinate with through ON, use "every"

Replace line 164 with that below:

JavaScript:
if ($gameMap.eventsXy(x, y).length > 0 && $gameMap.eventsXy(x, y).some(event => event._through === false)) return false;

I just add:
&& $gameMap.eventsXy(x, y).some(event => event._through === false)) return false;

I can think of other ways to implement this feature in a safe way, instead of changing just line 164. But I do not have that time now. See if the above solution will work for you.
Thank you both so much! I used that piece of code and now it appears to be working exactly how I wanted. This should also help in-case there's ever a bird flying over where the player is tilling fields.

Again, thank you both!

Original thread: https://forums.rpgmakerweb.com/threads/alter-galvs-event-spawning-to-allow-certain-overlapping.145046/