JS: Finding what event is within an area in front of the player's x/y (shotgun map effect)

Hey there! I've tried searching but can't seem to find the right way to phrase it to get the information I need, so I hope this isn't something common that I have just failed miserably at searching for X_x

Anyway, I have a common event that is called by a keypress which uses a skill (ABS-style combat). I want it to scan for events which have the <enemy> meta tag in their note field in a certain range (a cone in front of the player based on the direction they are facing). When this happens, and if it finds an enemy in the AoE, I want it to turn the Self Switch "A" on for the events that are within that AoE cone's coverage.

I'm having a hard time figuring this out since I'm pretty new to this. I remember figuring out how to do this in RM2k3 way back in the day, but that was by making variables for and then updating every enemy's event's X/Y on a parallel process and calling a common event via [Password Input] to have an area based on the map x/y and player x/y and their facing direction, and using a ridiculous amount of conditional branches to check it all and to go to different labels to execute other direction checks X_x I'm willing to do that if I have to, but I would rather use this as a learning experience to help further my understanding of Javascript in this game.

Any help or even just a snide "just read this article" reference would be greatly appreciated! Thank you for your time, and also...hi! Haven't posted on an RPG Maker forum seriously since...well....near the turn of the century? RPG2Knet.com was my last real RPG Maker attempt. Played with VX for a minute, but then, y'know, work...life...... But now work is on a regular schedule, and I'd like to give this an earnest shot, again!
You need to split this into two parts to solve the problem.

The first part is identifying the area (all coordinates affected) and the second part is for checking which events are on one of those coordinates.

The first part is half mathematics and half your decision on how to define the area that is affected. The result will always be a list of coordinates or a range of coordinates that needs to be checked for targets.

Then for each of those coordinates you need to check if there is an event on that Position and if yes, which one. This is usually done in some form of a loop, but the exactly form depends on your definition of the target area.


As for the check itself, that can be done either by event command "get location info" or by its script equivalent. Which way would be best to go depends on how you stored the info about the target area.
Yeah, I'm familiar with the theory behind how to do this, and I'm sure it's gonna be several parts of code execution. What I'm unsure of are the actual functions/variables that hold significance to this problem. The ones I need to know are:

1) Player variable for its map x/y
2) Player variable for its current directional orientation
3) A function that checks a specific X/Y map coordinate and returns the event ID of an event that is already occupying it (if it's already built in)

If 3) is not possible (Which would suck, since that seems like something that'd be built in based on other plugins I've seen) then I'd need to make a "for (...){}" statement that evaluates all the events on a map and checks to see which have the <enemy> meta in their notes, then checks their X/Y, sees if it is included in the current executed code's cone's AoE, and then turns their Self Switch "A" on. That seems needlessly overdone.

I know ways I COULD do this, but what I'm looking for are better ways, since I'm new to this and I don't wanna develop bad habits based on me saying, "Well, this is the only thing I can figure out," without asking people who are better than me at this if there are better ways to go about it.
1) $gamePlayer.x
2) $gamePlayer.direction()
3) $gameMap.eventsXy(x, y)[0]._eventId

If there's no event at x,y (3) would return undefined.
Long story short, I can create a for(){}; function to check the area of a cone's effect based upon a mathematical equation/function, but what I don't know how to do is:
1) Give it originating coordinates to start the equation (Player's X/Y)
2) Give it directional orientation to modify the formula (Player's facing)
3) Use the produced array to check those coordinates for an event

Like I said, if I have to, I can just make every event constantly update its coordinates, then use basic click-button events to say, "is the player facing this way? Then does variable [0001]-[0021] = [0101]" and see if a range of my auto-updated X variables == the first part of the shotgun's X variable if facing up...then repeat that 12 more times for every square in the cone...then double that and repeat it for the Y coords....then TRIPLE all that and repeat it for the other 3 directions............But man, f@#% that, that is SO 2003 lol. This is why I am asking about Javascript ways to work around all this gruntwork. I'll even be cool with being pointed in the direction of a bunch of scripts that do similar things if they at least are somewhat helpful in helping me learn the specific parts of the system that I want to manipulate :\
Thanks dahlys! Sorry, I was typing up that long response while you already answered it for me >_<
Thanks so much, +20 internets to you, my friend.

Now I just gotta figure out how to use the $gameMap.eventsXy(x,y)[0]._eventId correctly!
Uh, sorry, there's an easier one for 3)

3) $gameMap.eventIdXy(x, y)

This one returns 0 is there's no event.

You can find (1) and (2) by typing window into the game console. (3) is somewhere in rpg_objects.js
Using $gameMap.eventsXy(x, y)[0] you can get the whole event, not just the id. Getting the whole event is useful if you need to check its notetag, and whether it is set to Through (you can't shoot a ghost!).
Haha Dahlys, I really appreciate you taking the time to come back and give me those notes, bud. Again, thank you.

Original thread: https://forums.rpgmakerweb.com/threads/js-finding-what-event-is-within-an-area-in-front-of-the-players-x-y-shotgun-map-effect.85342/