Check Spawned Event Collision/Radius effect

joket

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
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

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,347
Reaction score
8,769
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

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
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
Veteran
Joined
Sep 12, 2016
Messages
685
Reaction score
588
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

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
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
Veteran
Joined
Sep 12, 2016
Messages
685
Reaction score
588
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

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
First Language
English
Primarily Uses
RMMV
Tried, but its not looking to work:

1635078779001.png
 

LadyBaskerville

Hell-poodle
Veteran
Joined
Sep 12, 2016
Messages
685
Reaction score
588
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

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
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
Veteran
Joined
Sep 12, 2016
Messages
685
Reaction score
588
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

Veteran
Veteran
Joined
Apr 24, 2021
Messages
176
Reaction score
44
First Language
English
Primarily Uses
RMMV
Works nice! Thank you very much.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
34,347
Reaction score
8,769
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

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

Latest Threads

Latest Posts

Latest Profile Posts

Evening humans! How goes the game make?
The anime characters we saw 20 years ago,
still have the same age when we see them now.
Somehow it's strange but also beautiful.
It's like no matter how much we change,
there's certain part of ourselves we can reconnect to when we see them again.
Took a long, long time, way longer than it should to be honest...but I've finally finished the big content update to my demo!
Lots of not good things happening IRL but I'm not gonna let this day end like this. Quote time:
"Success is not final, failure is not fatal: it is the courage to continue that counts." -Winston Churchill

So, keep going, lads. Whatever you do keep going. Until next time.

It's a Spanish devlog don't get scared!. (please)

Forum statistics

Threads
117,240
Messages
1,105,806
Members
153,405
Latest member
Eamon_Dev-Alera
Top