Need help making an Event "Area of Effect" activation (Script Call)

So, essentially what I want to do in my game is an Active Battle System built from the ground up using Events as enemies. So far, it's not going too bad, but there is a small problem.

My game uses both melee and ranged combat, and I can't figure out a script that tells the event/player: "If player is in coordinate (0, +1) relative to this event, then melee attacks are allowed." or "If player is in coordinate (-5. 0) relative to this event, then melee attacks are not allowed."

Essentially, I need a way to put the "$gamePlayer.pos(x,y)" check relative to an Event's own position.

The checking area is a 7 * 7 tile circle with the Event in the center. Essentially from +3 to -3 in both the X and Y axes relative to the Event.

Visual representation, red being the event, black being the area of effect.
1656902631977.png


At this point I'm open to anything, whether it's a solution for my method or an entirely new one that meets my needs, please, feel free to comment.
If you're running the code from a script call within the event in question, then this is how you could detect if the player is within the circle that you have described:

JavaScript:
const distanceX = Math.abs(this.character(0).x - $gamePlayer.x);
const distanceY = Math.abs(this.character(0).y - $gamePlayer.y);

if (distanceX + distanceY <= 4) {
    // Player is within a radius of 3
} else {
    // Player is not within a radius of 3
}
If you're running the code from a script call within the event in question, then this is how you could detect if the player is within the circle that you have described:

JavaScript:
const distanceX = Math.abs(this.character(0).x - $gamePlayer.x);
const distanceY = Math.abs(this.character(0).y - $gamePlayer.y);

if (distanceX + distanceY <= 4) {
    // Player is within a radius of 3
} else {
    // Player is not within a radius of 3
}
Thanks a million!

I'll try it out on a sec!
If you're running the code from a script call within the event in question, then this is how you could detect if the player is within the circle that you have described:

JavaScript:
const distanceX = Math.abs(this.character(0).x - $gamePlayer.x);
const distanceY = Math.abs(this.character(0).y - $gamePlayer.y);

if (distanceX + distanceY <= 4) {
    // Player is within a radius of 3
} else {
    // Player is not within a radius of 3
}

Is it possible to configure this to work in a Conditional Branch script? I tried, and it seems to half work, only for the 'out of range' portion. I'm not awfully good with Script Calls, even if I can tell my way around...
Conditional Branch -> Script: "is the X + Y distance between This Event and the player ≤ 4?"

var c1 = this.character(0), c2 = $gamePlayer; $gameMap.distance(c1.x, c1.y, c2.x, c2.y) <= 4
This works correctly on looped maps as well.

Note that there are different ways of measuring distance; by default the game calculates distance as X + Y (rectilinear). You may not need scripting here, e.g.
Spoiler: event example (X + Y ≤ R)
◆Comment:Get X distance... ◆Control Variables:#0024 x = Map X of Player ◆Control Variables:#0024 x -= Map X of This Event ◆Comment:If x < 0 then multiply by -1 so distance > 0. ◆If:x < 0 ◆Control Variables:#0024 x *= -1 ◆ :End ◆Comment:Same for Y distance... ◆Control Variables:#0025 y = Map Y of Player ◆Control Variables:#0025 y -= Map Y of This Event ◆If:y < 0 ◆Control Variables:#0025 y *= -1 ◆ :End ◆Comment:Add together and check! ◆Control Variables:#0024 x += y ◆If:x ≤ 4 ◆Text:None, None, Window, Bottom : :In range! ◆ :Else ◆Text:None, None, Window, Bottom : :Not in range! ◆ :End
Spoiler: event example (X² + Y² ≤ R²)
◆Comment:Get X² distance... ◆Control Variables:#0024 x = Map X of Player ◆Control Variables:#0024 x -= Map X of This Event ◆Control Variables:#0024 x *= x ◆Comment:Get Y² distance... ◆Control Variables:#0025 y = Map Y of Player ◆Control Variables:#0025 y -= Map Y of This Event ◆Control Variables:#0025 y *= y ◆Comment:Add together and compare vs R² ◆Control Variables:#0024 x += y ◆If:x ≤ 16 ◆Text:None, None, Window, Bottom : :In range! ◆ :Else ◆Text:None, None, Window, Bottom : :Not in range! ◆ :End
(I've used a radius of R = 4 in these examples.) These event examples do not account for looped maps.
Conditional Branch -> Script: "is the X + Y distance between This Event and the player ≤ 4?"

var c1 = this.character(0), c2 = $gamePlayer; $gameMap.distance(c1.x, c1.y, c2.x, c2.y) <= 4

This works correctly on looped maps as well.

Note that there are different ways of measuring distance; by default the game calculates distance as X + Y (rectilinear). You may not need scripting here, e.g.
Spoiler: event example (X + Y ≤ R)
◆Comment:Get X distance... ◆Control Variables:#0024 x = Map X of Player ◆Control Variables:#0024 x -= Map X of This Event ◆Comment:If x < 0 then multiply by -1 so distance > 0. ◆If:x < 0 ◆Control Variables:#0024 x *= -1 ◆ :End ◆Comment:Same for Y distance... ◆Control Variables:#0025 y = Map Y of Player ◆Control Variables:#0025 y -= Map Y of This Event ◆If:y < 0 ◆Control Variables:#0025 y *= -1 ◆ :End ◆Comment:Add together and check! ◆Control Variables:#0024 x += y ◆If:x ≤ 4 ◆Text:None, None, Window, Bottom : :In range! ◆ :Else ◆Text:None, None, Window, Bottom : :Not in range! ◆ :End
Spoiler: event example (X² + Y² ≤ R²)
◆Comment:Get X² distance... ◆Control Variables:#0024 x = Map X of Player ◆Control Variables:#0024 x -= Map X of This Event ◆Control Variables:#0024 x *= x ◆Comment:Get Y² distance... ◆Control Variables:#0025 y = Map Y of Player ◆Control Variables:#0025 y -= Map Y of This Event ◆Control Variables:#0025 y *= y ◆Comment:Add together and compare vs R² ◆Control Variables:#0024 x += y ◆If:x ≤ 16 ◆Text:None, None, Window, Bottom : :In range! ◆ :Else ◆Text:None, None, Window, Bottom : :Not in range! ◆ :End
(I've used a radius of R = 4 in these examples.) These event examples do not account for looped maps.
Thanks a million! This works perfectly!

Original thread: https://forums.rpgmakerweb.com/threads/need-help-making-an-event-area-of-effect-activation-script-call.149155/