I'm still not totally getting what you're after, but perhaps this will help?
I've set aside four variables. In this case, I used:
- Variable 9: boomId (represents the Id of the bomb event going off)
- Variable 10: destructibleIds (represents all the event Ids that should blow up)
- Variable 11: destructCount (used as an iterator in a loop)
- Variable 12: destructibleId (used to represent the current event Id that should blow up in a loop)
I've made a common event called Boom that looks like so:
Spoiler: Boom common event
It would be called like so:
So whatever the bomb event is, you set its Id to variable 9 (or whatever you want to set aside), then call the common event.
The common event will then look at each coordinate around that event with that event's coordinates as the center - so:
- x - 1, y - 1: top left
- x, y - 1: top center
- x + 1, y - 1: top right
- x - 1, y: left center
- etc.
For each coordinate, it will look at all the events on the current map and gather up the Ids of each event whose coordinates match one of those coordinates and it will store the resulting Array in game variable 10.
As an example, the slime is event 1 and represents my bomb. The brown chest is event 2, the red chest is event 3, and the gold chest is event 4.
After interacting with the slime, game variable 10 would be an Array of [2, 3], because event Id 2 (the brown chest) and event Id 3 (the red chest) are in the 8 surrounding squares, but event Id 4 (the gold chest) is not.
So then, in the common event, I've got the event version of a for loop - set an iterator (game variable 11 = 0, the first index of the Array that variable 10 is holding), then retrieve the value for that iterator (game variable 12, which will be game variable 10 at index 0, which is game variable 11). I then have a conditional branch saying, "If something is defined for game variable 12," and an else meaning, "There's nothing in the Array at that point, so exit the loop".
So within the part of the conditional where something is defined for game variable 12, I could do whatever you want to do to have something blow up. Presumably it would be a programmatic move route of some sort, but again, I'm not for sure what you're trying to do.
If that's not quite what you're looking for, then the first part would at least give you an Array of all the Ids of events that are in explodable range of the bomb. Here's the code for that:
Code:
const bomb = $dataMap.events[$gameVariables.value(9)];
$gameVariables.setValue(10,
[
[bomb.x - 1, bomb.y - 1], [bomb.x, bomb.y - 1],
[bomb.x + 1, bomb.y - 1], [bomb.x - 1, bomb.y],
[bomb.x + 1, bomb.y], [bomb.x - 1, bomb.y + 1],
[bomb.x, bomb.y + 1], [bomb.x + 1, bomb.y + 1]
].reduce((blowUpIds, [x,y]) => {
return blowUpIds.concat($dataMap.events.filter(event => {
return event && event.x === x && event.y === y;
}).map(event => event.id));
}, []));