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

Veteran
Veteran
Joined
Jun 25, 2021
Messages
512
Reaction score
492
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
3,808
Reaction score
2,868
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 Profile Posts


Calf survival story with a happy ending.
well here's that concept art!
WIN_20220812_16_53_56_Pro (2).jpg
Whaddya think? Name suggestions?
Some character designs of 'Coin Locker'.
(there may be some future designs along the process.)


Untitled1294_20220813055849.png
1660339609612.png
Really need to come up with better names for my folders.
rpgmakerxp wrote on caethyril's profile.
Hi, I saw you comment a google drive link to add a specific script to a kadowa plugin for battle voices here: https://forums.rpgmakerweb.com/inde...attacking-defending-skills-damage-ect.119148/

I'd like to add "multiple possible battle voices" for stuff too, can you please let me know what to change cause the link isn't working.

Forum statistics

Threads
124,455
Messages
1,163,794
Members
163,276
Latest member
Ciberfreak
Top