Get ID of two events at the same location?

Thread. I've tried placing two events at the same place, then getting the ID of the event, using $gameMap.eventIdXy(x, y), but it's always returning the lowest event ID. Does anyone have any solution concerning this? Another method, something alternative?

And yes, I need to have two overlapping events, and for me to be able to return both. I'm far in my project, and I don't need another way that doesn't involve events overlapping.

Thank you!
Code:
Game_Map.prototype.eventsXy_special = function(x, y) {
    var arr = [];
    this.events().filter(function(event) {
        if (event.pos(x, y)) {
            arr.push(event);
        }
    });
    return arr;
};

Game_Map.prototype.eventIdXy_special = function(x, y) {
    var arr = [];
    var list = this.eventsXy_special(x, y);
    if (list.length > 0) {
        for (var i = 0; i < list.length; i++) {
            arr.push(list[i].eventId());
        }
    }
    return arr;
};

Add this bit of code in the game's code (you can add it as a single plugin for instance). Now, instead of calling the old method you can call the new one: $gameMap.eventIdXy_special(x, y) . This will send you back an array with the id of all events at the position you specify.

Note, I wrote this quickly and have not tested the code. If there's an error just screenshot it and I'll fix it.

Edit: I forgot to move the thread to the appropriate subforum, so...

I've moved this thread to Learning Javascript. Thank you.

$gameMap.eventsXy(x, y).length for all events at the location?

$gameMap.eventsXyNt(x, y).length is without the through switch according to another post

So you could set the one with the lower ID to have through checked
$gameMap.eventIdXy(x, y) would grab lowest as normal
$gameMap.eventIdXyNt(x, y) would have to grab the latter
And the code works wonder, MushroomCake28! That saves me a lot of trouble.

Thanks again!
@Winek Glad we could help! Can I mark this thread as solved and close it?
Yes indeed! I forgot to report it as solved, so I'll do it now!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/get-id-of-two-events-at-the-same-location.117883/