How to make an event patrolling with range of vision?

I am trying to make a stealth map, where there are some soldiers patrolling, the user should avoid walking in front of these soldiers.

For example, this event walks in a left-right cycle and should trigger when the player walks inside this area.
1689898075567.png


I could do a parallel process every second with a condition like this:

Code:
if( eventX+eventY<=playerX+PlayerY)
  if( eventX-eventY>=playerX-PlayerY)
    if( eventX-eventY<=playerX-PlayerY+8)
      if( eventX+eventY>=playerX+PlayerY-8)
        doSomething...

There is any easier way to do it?
If it's a static area and doesn't follow the soldier you could just use region ids and a region event plugin.
not without plugins.

and your foprmulae are not for the red area, you got mistakes there and the area will both be larger and differently formed with those checks, just use some more specific numbers to test.
Here's a list of Line of Sight plugins you can try if your event does move around


And this one
Yanfly has the EventChase plugin, you can set range vision and make stealth areas with region tiles. But it doesn't work well if the event is moving.
Thank you, for now I made the following code, it is working fine for the 4 directions the event can watch, I still looking for a way to make it easier.

JavaScript:
const ev=$gameMap.event(this._eventId);
var x=ev._x; var y=ev._y;
const d=ev.direction();
if(d==2){x-=3;y+=3;}if(d==8){x-=3;y-=3;}
if(d==4){x-=6;}
if(x+y<=$gamePlayer.x+$gamePlayer.y &&
   x-y<=$gamePlayer.x-$gamePlayer.y &&
   x-y>=$gamePlayer.x-$gamePlayer.y-6 &&
   x+y>=$gamePlayer.x+$gamePlayer.y-6){
  ev.requestBalloon(1);
  this.setWaitMode('Balloon');
}

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-an-event-patrolling-with-range-of-vision.159541/