Lex1253

Villager
Member
Joined
Nov 6, 2019
Messages
28
Reaction score
7
First Language
Eng/Ro
Primarily Uses
RMMV
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.
 

Arthran

Regular
Regular
Joined
Jun 25, 2021
Messages
1,100
Reaction score
1,601
First Language
English
Primarily Uses
RMMZ
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
Member
Joined
Nov 6, 2019
Messages
28
Reaction score
7
First Language
Eng/Ro
Primarily Uses
RMMV
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
Member
Joined
Nov 6, 2019
Messages
28
Reaction score
7
First Language
Eng/Ro
Primarily Uses
RMMV
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

^_^
Global Mod
Joined
Feb 21, 2018
Messages
5,047
Reaction score
4,405
First Language
EN
Primarily Uses
RMMZ
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
Member
Joined
Nov 6, 2019
Messages
28
Reaction score
7
First Language
Eng/Ro
Primarily Uses
RMMV
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 Threads

Latest Posts

Latest Profile Posts

It's been long time since last I'm tinkering with RPG Maker ~
Turns out. I wasn't in my head accounting for when the Actor doesn't have a weapon equipped but DOES still have a Grimoire equipped... 40+ SV Spritesheets!!! D'x
Elemental chart based on taoism could be interesting.
Taotypes.png
Come and join me in 10 minutes for Trihan's Challenge Hour, where I'll be attempting a game of Cartographers where I can only position terrain in the orientation on the explore card! Following that will be the Wifestream, where Kytt will be trying out From Space for the first time! https://twitch.tv/trihanstreams
F***, I promised myself not to make overlong intros anymore, but the dialogues are again getting out of hand in a very visual novel kind of way, and there's only two fights against bats in between them...well, at least there's going to be a proper area with fights after this intro sequence. And the intro is a bit more lively with several locations and different scenes.

Forum statistics

Threads
135,044
Messages
1,253,262
Members
178,021
Latest member
Alcarin
Top