Check Spawned Event Collision/Radius effect

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Hello everyone. I'm using YEP spawn plugin to spawn bombs in the map on the player position.
I'd like to event the following:
- when the player is in 3 tiles radius from the bomb when it explodes --> damage animation
- when a given event (breakable wall or other) is in 3 tiles radius from the bomb --> turn switch on

Given the bomb is spawned, I won't know exactly what will be the event number relative to the bomb (for conditional branch of checks). I'd need something like: a comment tag or event note which acknowledge that it's breakable.
That is because multiple bombs can exist at once.

Here is the bomb eventing like: Parallel event
Animation flash
wait 3 frames
Animation flash
wait 3 frames
....
Animation flash
wait 3 frames
SE: Break
Animation: Explosion
Erase event


What do you suggest?
I can make the single bombs to check if the player is within 3 tiles by x and y player position, but what about wallet and breakable events?

This is where I'm now:

var ev = $gameMap.event(this._eventId);
var pl = $gamePlayer;
var rx = pl.x - ev.x;
var ry = pl.y - ev.y;
var pdir = (pl.direction() / 2) - 1;
var check = [ry==-1, rx==1, rx==-1, ry==1];
check = (rx==0 || ry==0) && check[pdir];
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], check);
 
Last edited:

Andar

Regular
Regular
Joined
Mar 5, 2013
Messages
39,954
Reaction score
11,895
First Language
German
Primarily Uses
RMMV
the breakable events would have to be checked in the same way as the player, by comparing coordinates or distance. This can be done through the event ID, and you can get that even for spawned events in the same way you get x and y.

Are you using MV or MZ? You posted in MV but your profile states MZ.
In the case of MV you can use the meta function (see help file) to get a notetag from the event note, and compare that to breakable or not.
 

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Thank you for the reply. Yes it's a different process.
Where can I see the help file for the metafunction?
Oh, I'm updating the profile, I'm on MV.

The problem is: I can have let's say 5 different bombs parallely going on the map.
There can be 3 breakable events around.
I should make something in the bomb spawned event which locally activates some trigger that then the breakable event can check for! (Let's say the breakable event checks for local switches of the bombs, but can't say how to make it check for any bombs)

Problem is:
Event which is breakable: have either - 1) a check for bombs explodings in 3 tiles from it; or 2) a notetag or a comment - or even a region id - for the bombs to check so that it can then after being broken

or, on the contrary:

Bomb which can check for any breakable event around it, locally (which sounds the smarter way) and trigger local switch change on them
something like:
If breakableEvent is within 3 tiles from this event (bomb): then--> $gameSelfSwitches.setValue([MapID, BreakableEventID, 'A'], true)
 
Last edited:

LadyBaskerville

Hell-poodle
Regular
Joined
Sep 12, 2016
Messages
705
Reaction score
648
First Language
German
Primarily Uses
RMMV
If breakableEvent is within 3 tiles from this event (bomb)
You should be able to do that by iterating through all events on the map and checking their notetag. If they're tagged as breakable, calculate distance from the bomb and turn on the self switch of the breakable event - you pretty much have the code for that part already.

Iterating and checking if the note contains the tag <breakable> would look something like this:
JavaScript:
for (let i = 1; i <= $gameMap.events().length; i++) {
  if ($gameMap.event(i).event().meta.breakable) {
      // event with ID i is breakable
      // check distance to bomb, turn on self switch if close enough
  }
}

(Side note: If your breakable events are also spawned by a plugin, the code for checking the notetag might look different, depending on how exactly the event spawning was implemented)
 
Last edited:

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Thank you! Trying it: robably I'm noob but this isnt' working :(

for (let i = 1; i <= $gameMap.events().length; i++) {
if ($gameMap.event(i).event().meta.breakable) {
if eventId==i {
$eventId.gameSelfSwitches.setValue(true)
}
}
}
 

LadyBaskerville

Hell-poodle
Regular
Joined
Sep 12, 2016
Messages
705
Reaction score
648
First Language
German
Primarily Uses
RMMV
I didn't realize you hadn't written that part already for the player.
This assumes you're putting the code into a script call in the bomb event:
JavaScript:
for (let i = 1; i <= $gameMap.events().length; i++) {
  if ($gameMap.event(i).event().meta.breakable) {
      let bombX = $gameMap.events(this._eventId).x;
      let bombY = $gameMap.events(this._eventId).y;
      let eventX = $gameMap.events(i).x;
      let eventY = $gameMap.events(i).y;
      if (Math.abs(bombX-eventX) <= 3 && Math.abs(bombY-eventY) <= 3) {
          $gameSelfSwitches.setValue([this._mapId, i, 'A'], true);
      }
  }
}

For the player, you can do something similar (in a separate script call, because there's a line limit):
JavaScript:
let bombX = $gameMap.events(this._eventId).x;
let bombY = $gameMap.events(this._eventId).y;
let playerX = $gamePlayer.x;
let playerY = $gamePlayer.y;
if (Math.abs(bombX-playerX) <= 3 && Math.abs(bombY-playerY) <= 3) {
    $gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);
}
and then use normal eventing to see if the bomb event's self switch A is turned on - that means the player is in a 3 tile radius.
For the bomb - player distance, you could also do it purely by eventing (Control Variables -> Game Data to get x and y coordinates of Player and "This Event", then do calculations from there), but I personally find the script more convenient when we're already using basically the same code for the breakable events.
 

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Tried, but its not looking to work:

1635078779001.png
 

LadyBaskerville

Hell-poodle
Regular
Joined
Sep 12, 2016
Messages
705
Reaction score
648
First Language
German
Primarily Uses
RMMV
A few things to check: First, can you open the console (F8 during playtest) and send a screenshot of anything that comes up there?
Does your bomb event have any other pages? If so, please show screenshots of them as well (with the page numbers and conditions visible).
Also please send a screenshot of one of your breakable events (all pages if you have multiple, make sure the note box is visible as well).
 

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Yes the console shows for "event" property unreadable:

1635080790966.png


Bomb do not have any page, just an erase event at the end (to avoid event spawn overload and stacking of map events which can lag the game).

Breakable event 1st page:
1635080873268.png
2nd page:
1635080897683.png
 

LadyBaskerville

Hell-poodle
Regular
Joined
Sep 12, 2016
Messages
705
Reaction score
648
First Language
German
Primarily Uses
RMMV
Alright, try this instead:
JavaScript:
for (let i = 1; i <= $gameMap.events().length; i++) {
  if ($gameMap.event(i) && $gameMap.event(i).event().meta.breakable) {
      let bombX = $gameMap.event(this._eventId).x;
      let bombY = $gameMap.event(this._eventId).y;
      let eventX = $gameMap.event(i).x;
      let eventY = $gameMap.event(i).y;
      if (Math.abs(bombX-eventX) <= 3 && Math.abs(bombY-eventY) <= 3) {
          $gameSelfSwitches.setValue([this._mapId, i, 'A'], true);
      }
  }
}

JavaScript:
let bombX = $gameMap.event(this._eventId).x;
let bombY = $gameMap.event(this._eventId).y;
let playerX = $gamePlayer.x;
let playerY = $gamePlayer.y;
if (Math.abs(bombX-playerX) <= 3 && Math.abs(bombY-playerY) <= 3) {
    $gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);
}
 

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Works nice! Thank you very much.
 

Andar

Regular
Regular
Joined
Mar 5, 2013
Messages
39,954
Reaction score
11,895
First Language
German
Primarily Uses
RMMV
Where can I see the help file for the metafunction?
I don't know if you still need it, but it is:
- Menu Help, Contents (or press F1 in the editor)
- click/go down to documentation in the list on the left side
- click on "Plugin Specifications"

The metadata section is in the middle, and that plus the code above should tell you where and how you can use it
 

joket

Regular
Regular
Joined
Apr 24, 2021
Messages
322
Reaction score
73
First Language
English
Primarily Uses
RMMV
Thank you very much! This thread will help lots of people trying to event bombs.
 

Latest Threads

Latest Profile Posts

made an RTP edit to try to save on work, found out I was editing the wrong tilesheet of cliffs.
It's fine... I'm fine... I'm sure fixing this won't take too long
Proud of the work done.
Probably gonna toss out some cameos.
-Message sponsored by the β Gang.
"I WAN BOOZY EGGY-NOG!"
"I WAN BOOZY EGGY-NOG!"
"For the love of the cosmos TarTar, you shouldn't drink spiked eggnog."
"I WAN BOOZY EGGY-NOG"
Boozy-Eggy-Nog.png
I've always found Game Over screens to be a bit boring. Mostly because I see them too often.
Tried to mix it up for the jam.
GameOver.png

Forum statistics

Threads
136,904
Messages
1,271,288
Members
180,689
Latest member
pharaoh14
Top