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

#### Lex1253

##### Villager
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.

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.

#### Arthran

##### Veteran
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
}``````

#### Lex1253

##### Villager
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!

#### Lex1253

##### Villager
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...

#### caethyril

##### ^_^
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.
```◆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```
```◆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.

#### Lex1253

##### Villager
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.
```◆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```
```◆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!

### Latest Profile Posts

MORE GAMBLING THEMED ATTACKS!

I AM UNABLE TO STOP!
Is it ok to repost stuff that i've posted to threads in the status feed?
If so, here's art of Shiloh, the main protagonist of the game i'm making:
They are meant to be ambiguous in gender, like Frisk from Undertale or Gogo from FFVI. I haven't decided what their age will be yet. Any ideas?
Please comment what you think about the art and design!

Looks like Mike's got a new party member in Robbi...

Calf survival story with a happy ending.
well here's that concept art!
Whaddya think? Name suggestions?