self switch trigger nearby event (help request)

Hi, I'm new here, I'm searching for some help with an event using MZ.

I'm eventing a projectile (fired by the player) that trigger a barrel that explode.
the explosion can damage the player (if he's near) or completely kill an enemy.
I have a problem only with the barrel/bomb: I need to check the nearby area and damage the player or/and trigger the self swith "D" of all the events in the nearby area.

For now I set it like that:

-I have the barrel (event1) that is triggered using a projectile that turns his self switch A "on".
On the second page of event 1 (parallel), it needs to check near itself:
bomb area.JPG

-when there is the player nearby it damages the hero (-xx HP)
-when there is an event (eg. an enemy) it needs to trigger the nearby event's self switch "D" to "on"
-when there is anything the bomb only do an explosion.

The barrel then, self switch B On and "erase" itself

So far I only managed to do it for a specific enemy (knowing the correct event id n'5).
bomb.JPG


But I need it to work with a common event so I can use it with different enemies/events without tracing with variables all the enemies data.
I need a way to get the nearby ID of the events in the area and put it in the "selfswitches.setValue" formula.
for the player damage I think I'll use the hero x and y variables to track him but first I want to fix the enemy part.

I also tried that approach in the barrel page(parallel):
--------------------------------
for a in (2..50)
if $gameMap.events[a] != nil
if ($gameMap.events[a].x - $gameMap.events(this.eventId).x).abs +
($gameMap.events[a].y - $gameMap.events(this.eventId).y).abs <= 1
$game_self_switches[[this._mapId, a, 'D']] = true
end ; end
end

--------------------------------
but I couldn't figure it out :rtear:
I checked those threads:



and that's was really promising:


I'm not really good with script and English isn't my main language so, have mercy!
if ($gameMap.events[a].x - $gameMap.events(this.eventId).x).abs +
($gameMap.events[a].y - $gameMap.events(this.eventId).y).abs <= 1
that doesn't work like you believe, because if the enemy is diagonal to the barrel, the formula will get 2 (dx=1 + dy=1).
It is much better to make it two conditional branches, one checking x and one checking y.
adding both scales will only check in a circle-like area, not a square.

You might also consider checking only positions instead of every event - you can use get location info to retrieve the ID of any one event on the 8 tiles around, if get location info returns 0 there is no event there.
After that you'll have to check if the event is an enemy or something else however, but since you have the ID number that should not be a problem.
You need to read more carefully the threads you're referencing.

Two of them are in the VX Ace Support forum, which is why your code doesn't work - it's Ruby, not JavaScript.

You might also find this plugin useful:
that doesn't work like you believe, because if the enemy is diagonal to the barrel, the formula will get 2 (dx=1 + dy=1).
It is much better to make it two conditional branches, one checking x and one checking y.
adding both scales will only check in a circle-like area, not a square.

You might also consider checking only positions instead of every event - you can use get location info to retrieve the ID of any one event on the 8 tiles around, if get location info returns 0 there is no event there.
After that you'll have to check if the event is an enemy or something else however, but since you have the ID number that should not be a problem.
Thank you. I didn't thought about the "get location info". I can get the x and y of the bomb event at the center of the square but then how can I check all the square for events IDs?

Talking about location... Is there a way to use the region ID?
Like some script that simply change all the self switch in a determined ID region on the map?
You need to read more carefully the threads you're referencing.

Two of them are in the VX Ace Support forum, which is why your code doesn't work - it's Ruby, not JavaScript.

You might also find this plugin useful:
Thank you for pointing out, I was so desperate to find something that I was really checking without thinking.
Anyway I'm totally not capable of distinguish it... so you can imagine how good I'm with script.
Thank you. I didn't thought about the "get location info". I can get the x and y of the bomb event at the center of the square but then how can I check all the square for events IDs?

Talking about location... Is there a way to use the region ID?
Like some script that simply change all the self switch in a determined ID region on the map?
I don't know if you looked at the link I left for you, but it sounds like it would be much easier for you to simply use a plugin that did all of this automatically.

Thank you for pointing out, I was so desperate to find something that I was really checking without thinking.
Anyway I'm totally not capable of distinguish it
I'm not sure what to say...even if English is not your first language, the letters on the top of the page are different.

1704310853909.png


1704310884627.png
but then how can I check all the square for events IDs?
basically modifying x and y to use eight get location info commands on the eight pairs of coordinates.

this can be done directly or with a loop or with a sccripted loop.
I don't know if you looked at the link I left for you, but it sounds like it would be much easier for you to simply use a plugin that did all of this automatically.


I'm not sure what to say...even if English is not your first language, the letters on the top of the page are different.

View attachment 290588

View attachment 290589
By "not capable of distinguish it" I meant "Ruby" and "java", I totally skipped the title, I checked directly the question below without thinking, sorry.
For the plugin I read all in the link but I think it works only with the player prox and not with an event-event proximity. Also it's for MV... It works anyway in MZ?
basically modifying x and y to use eight get location info commands on the eight pairs of coordinates.

this can be done directly or with a loop or with a sccripted loop.
Thanks, I'll try to work it out this way.


Thank you both for the tips
Also it's for MV... It works anyway in MZ?
Rarely directly, but there is a plugin called FOSSIL that wraps the differently named functions and redirects them to their MZ equivalent, and about 50% of all MV plugins can use it to work on MZ.
It's no guarantee, but worth a try if you can't find an MZ equivalent to something.
Solved directly with the "get location info" checking all the 8 tiles near the bomb event.
Thank you😉

Original thread: https://forums.rpgmakerweb.com/threads/self-switch-trigger-nearby-event-help-request.164366/