MV Event sees Player in the right direction

Hello there! So, it's all in the title basically...

I've been struggling for days now with ways to make the Player 'seen' by a specific event which patrols from left to right in the same map. (TL;DR at the end of post)

I'd like this event to detect the Player from a certain range when it's facing the right direction (if Player's at the right of the map, then the event should notice them only when they're at a certain distance and when walking to the right). If the events sees the Player then, it chases them until the Player hides. When they hide, the event freezes for a moment, then resume patrolling.

I've been trying plugins (YEP's Event Chase Player, Galv's Event Detector) but I can't manage to make them work as I'd like. So i've tried resorting to javascript (I do not do coding, I don't know Scheiße about that so I was just trying stuff by using the Player's coordinates, whenever the event should detect them depending on where they're on the map comparing to the event's position). I managed to accomplish some stuff by pure luck but there's always something going wrong.

So yeah, I'm starting to get a little annoyed by that and would like to call for help. Maybe I haven't used all the plugins' potential? I was wondering if Galv's could be used in any other way than what the file says.

Here's an example of my attempt at using javascript, just so you can see what I've been trying to do (there's more) (fyi it works, it just makes things a little messy):

Spoiler
b7b43713581c7ce1a052e434b4bc5a8a.png

TL;DR: I'd like to find a way so to make the Player 'seen' by an event at some range when the event is facing the right direction.

Thank you for your time.
What you descrihe should be easily accomplished with Yanflys Event Chase Player Plugin you mentioned.

What exactly die you try using the Plugin what didn't work?

Normally you Just Put something like
Code:
this._chaseRange = 4
this._seePlayer = true
as a script into the events move route. The Event will then Chase the Player whenever they move four tiles into it's line of sight.

When the Player hides you just turn on a switch to skip the Event to a new page and change it's move route.
It is possible to do this using events, but relying heavily on script calls.
I made a basic example, here’s a video demonstration:


Attached is the map file. Paste it into the "data/" folder of a empty project to see how I set up the event. :hhappy:
@JorgeMaker i don't know if you wrote this just for me or if you had that before, but— though i really appreciate it, I'd rather not using code that I don't understand — yeah I know i've been fooling around for trying javascript when I'm no connoisseur myself, but if I want to make changes with your code, then i'd have no idea of how to. Thanks a bunch though!
What you descrihe should be easily accomplished with Yanflys Event Chase Player Plugin you mentioned.

What exactly die you try using the Plugin what didn't work?

Normally you Just Put something like
Code:
this._chaseRange = 4
this._seePlayer = true
as a script into the events move route. The Event will then Chase the Player whenever they move four tiles into it's line of sight.

When the Player hides you just turn on a switch to skip the Event to a new page and change it's move route.

Sorry for not mentionning it earlier but the thing is I'd like the event to walk when patroling, then running when chasing the player. I use Galv's CharactersAnimation plugin for that.

So the problem is that YEP's plugin won't work with a basic Movement Route command. And after testing, I can't put the line of code in the Autonomous Route, because then it'd only chase the player once the line is read, in the middle of multiple 'go right, go right, go right' or multiple 'go left'. Hence why I wrote that '$gameMap.event(3).x' stuff in the conditional branch.

Not to mention that line of code gets rid of the wonder if the event will keep patrolling fully to the right or fully to the left once it resumes patrolling, no matter where it had stopped when the player hides.

I did try putting the conditional branch in the event itself and the plugin's script call in the Autonomous Route, but one would always prevent the other from working.

So yeah idk if I'm making this complicated for nothing (I do that sometimes tho i try not to) or if it won't just work out. That's why I'd like to find a way for the event to react however I'd like while keeping the patrol routine, rather than using a direct 'Chase' solution with its own system.
I am not familiar with Galvs Charakters Animation Plugin, so I don't know If I am able to help you with that. Maybe if you describe what you have to do to switch to the running Animation? Is it just a Plugin command or how is this handled?

Regarding Yanflys Event Chase Player Plugin however, you'd put the Code right at the beginning of the autonomous moveroute, so it's read at First. I am Sure that is mentioned somewhere in the Help section.
Is there any reason you cannot do that?

There is also a Return command which let's the Event Return to its original Spot afert the Chase, but I See that this might cause problems, when the Event ist constantly moving.
That's why it's better to make the Event move Back to it's original place with a move route command, as soon as the Player hides.

If you are willing to throw another Plugin in you could use Yanflys Move Router Core to make your life a bit easier, since it let's you move an Event to specific coordinates instead of counting go left and go right commands.
I am not familiar with Galvs Charakters Animation Plugin, so I don't know If I am able to help you with that. Maybe if you describe what you have to do to switch to the running Animation? Is it just a Plugin command or how is this handled?

it's a script call you put in the Autonomous Route (so I have to switch to a different page) and it works just fine. It doesn't interfere with anything so far.

Regarding Yanflys Event Chase Player Plugin however, you'd put the Code right at the beginning of the autonomous moveroute, so it's read at First. I am Sure that is mentioned somewhere in the Help section.
Is there any reason you cannot do that?

So I've just tried that while using the Move Router Core plugin you've mentionned (thanks for that btw!) and sadly the chase command is completely ignored (see right below).

Spoiler
a888b14b50374038228b72b78917f31f.png

969b3d5d9dc111cacbaa2c5a7c6c97ec.gif

There is also a Return command which let's the Event Return to its original Spot afert the Chase, but I See that this might cause problems, when the Event ist constantly moving.
That's why it's better to make the Event move Back to it's original place with a move route command, as soon as the Player hides.

I might be a bit spoiled at this point but I don't really want the event to return back to the original spot when it's done chasing actually. It'd be part of the riddle for the player to hide when the event's patrolling (or when being chased) so whether they were chased or not, they can sneak behind the event once it walked past the hiding spot.

The closer I could get to what I want was using conditionnal branches comparing position X of player and event. It could get some sort of range with this

Code:
($gamePlayer.x - 5) <= $gameMap.event(3).x

the event would chase the player then. So the player would hide, which triggers a switch, and a new page on the event, where that same conditional branch right above doesn't exist (so the event cannot technically react to Player's X position).

The remaining problem was, of course, turning off that switch when player comes out of the hiding spot, and suddenly the event detects them again despite having the player visually behind its back. I've been trying to find a way to give the event a real range of sight but ended up going back and forth.
Oh you don't want it to Return, sorry then I misunderstood. I Just mentioned the move route core to bring the Event Back to it's original coordinates.

If the chase is not triggered at all, then there must be a problem with either the fact that you did now use script call to move it left and right or with the Galv Plugin.

Did you try putting the Chase Script at the start with the normal move route commands? If you did and it still did Not Trigger it's probably a compatibility Problem because of the Galv Script call.

Also another thing you can try, since you mentioned the Chase is only triggered after the move route commands have time through, is to put multiple chase Script calls in between the move route commands.
Oh you don't want it to Return, sorry then I misunderstood. I Just mentioned the move route core to bring the Event Back to it's original coordinates.

I misunderstood first then, sorry, because actually the YEP's chase plugin has that feature already (to return to the original spot) so yeah.

If the chase is not triggered at all, then there must be a problem with either the fact that you did now use script call to move it left and right or with the Galv Plugin.

Did you try putting the Chase Script at the start with the normal move route commands? If you did and it still did Not Trigger it's probably a compatibility Problem because of the Galv Script call.

So back when I first tried making the riddle, the Autonomous Route was going with

Code:
this._isDashing = true;
this._chaseRange = 5

and it worked fine. It chased the player and changed animation while running. So until now the Galv's plugin never was an obstacle.

Also, putting a script call for the chase on a basic Move Route command is one of the many things I've tried before, and it doesn't work, with or without Galv's plugin. The event just freezes in place.

Also another thing you can try, since you mentioned the Chase is only triggered after the move route commands have time through, is to put multiple chase Script calls in between the move route commands.

While that does work, I'd have to abandon the running animation then. I haven't tested that method to the end (with switches when the player hides and everything) but I might check this out further— And also maybe I'll find a way to make run both YEP and Galv's plugins.
So back when I first tried making the riddle, the Autonomous Route was going with

Code:
this._isDashing = true;
this._chaseRange = 5
and it worked fine. It chased the player and changed animation while running. So until now the Galv's plugin never was an obstacle.
If that worked, what was the problem with this method again? Sorry I am a bit lost right now.
If this works, then you only have to figure Out the hiding mechanic, right? Like stopping the chase and start whatever behaviour you the event to have from now on?


Also, putting a script call for the chase on a basic Move Route command is one of the many things I've tried before, and it doesn't work, with or without Galv's plugin.
Sorry, I did not means the Basic moveroute but the non-moveroute-core commands in the autonomous route. Like move right or move left instead of Right: 5. These commands after the Chase Script at the start of the autonomous move Route worked did Work Out fine? Even with Galvs Script?
If that worked, what was the problem with this method again? Sorry I am a bit lost right now.
If this works, then you only have to figure Out the hiding mechanic, right? Like stopping the chase and start whatever behaviour you the event to have from now on?
Don't worry, I got lost myself tbh, i've been back and forth so many times with different methods to use javascript and the YEP's plugins, pretty sure i've tried the same methods twice or more without realizing.

The problem with this is that then the event won't go back and forth the map like I want to. And not wanting the event to return to the original spot of its patrolling makes it even more tricky.

Sorry, I did not means the Basic moveroute but the non-moveroute-core commands in the autonomous route. Like move right or move left instead of Right: 5. These commands after the Chase Script at the start of the autonomous move Route worked did Work Out fine? Even with Galvs Script?

It did work fine like this. The problem though remains the same as described above. That's why I ended up trying javascript even though I don't know anything about coding. It got me closer to the desired result but the 'range of sight' was technically non-existent and the event would keep detecting the player even when they're sneaking behind. Here's how it looked like (since the engine is in french, i erased the commands and left comments instead):

Spoiler
d26eeedaa60269b0870070a2f68a4d03.png

Local switch A manages the page you're seeing.
Local switch B is the same page except the event goes to the left instead of right.
This whole process for having the event going left and right, even when interrupted in the middle of patrolling, works fine, without the need to go back to a 'restart spot' first.

So obviously since when the player comes out of the hiding spot behind the event, it reads the
Code:
($gamePlayer.x - 6) <= $gameMap.event(3).x
part and the player gets caught. That's.. pretty much the closest I could get to what I want. But again: that doesn't make it a real range of sight. And that's why atp I'm looking for a way to give it one.
The problem with this is that then the event won't go back and forth the map like I want to
You mean it's not moving at all?

Let's try putting the chase and the patrolling move Route on different Event Pages then:

First Page is an autonomous moveroute, patrolling from left to right without the Galv Script, but with an alert common Event Script from the Event Chase Player Plugin. This common Event Turns in a switch, which triggers the second Event Pages. This Page hast an autonomous moveroute with Just the Galv Script and the Player Chase (or just a move to Player move route command which repeats, should also Work). Then when the Player hides you can activate a third event pages, that stops the Chase and let's the Event do whatever you like.

I can't try it out myself right now, but I think this could Bring you at least one step closer^^
Let's try putting the chase and the patrolling move Route on different Event Pages then:

First Page is an autonomous moveroute, patrolling from left to right without the Galv Script, but with an alert common Event Script from the Event Chase Player Plugin. This common Event Turns in a switch, which triggers the second Event Pages. This Page hast an autonomous moveroute with Just the Galv Script and the Player Chase (or just a move to Player move route command which repeats, should also Work). Then when the Player hides you can activate a third event pages, that stops the Chase and let's the Event do whatever you like.

I might haven't understood everything, but I did try following your steps and with just that, the event's still missing a way to actually see the player, doesn't it..? While I've put the 'this._alertCommonEvent = x' line, nothings says how the player's supposed to be seen beforehand. Unless I didn't pay enough attention, I don't see any other command within YEP's plugin to give the event a range of sight. I don't really get how the CommonEvent line works tbh...

Well I still tried following what you suggested and it's a no-go. The event doesn't move since the event doesn't see the player anyway. So the rest doesn't trigger.

I'll try sorting this out with a common event tho, I haven't searched that much with that option.
Yeah, you are right. The alert does not work without the chase/flee script.
Sorry that I can only give you ideas here, without testing myself, but I do not have access to my projects right now^^

If I understood correctly the only problem with the Galv/Yanfly Combination is that the Event does not move accordingly to it's autonomous Move Route. Let's put the Move Route on Event Page 1 then and the Galv/Yanfly Combo on Page 2. This way it should not interfere with the move route:

Event Page 1, Autonomous Move Route:

this._chaseRange = 5
this._alertCommonEvent = 1
Move Right
Move Right
Move Right
Move Right
Move Right
Move Left
Move Left
Move Left
Move Left
Move Left

The chase command is only in there to trigger the alert for the common event, when the player is in range.

Common Event 1:
Control Switch #0001: ON

The Common Event only turns on a switch, which is the condition of and therefore activates Event Page 2 of your chasing Event:

Event Page 2, Condition: Switch 1, Autonomous Move Route:
this._isDashing = true;
this._chaseRange = 100
this._seePlayer = false

It's a new event page, so the chase has to be activated again. Since the event already saw the player, this has to happen immediately, even is the player is no longer in range. That's why I set a high chase range and also made sure that the event will chase the palyer regardless of it's line of sight.

This way the move route should not be interfered by the Galv Script Call.
Yeah, you are right. The alert does not work without the chase/flee script.
Sorry that I can only give you ideas here, without testing myself, but I do not have access to my projects right now^^
oh don't apologize, that's legit very kind of you to keep trying helping me, no worries! If you're running out of ideas, that's fine, at least it gets me thinking for trying other ways!

This way the move route should not be interfered by the Galv Script Call.
I've said it before, but the Galv's script never interfered with anything.

The only thing that bothered me, however, was the use of the basic 'Move Right/Move Left' combination. Because if it's made for the event to move from A (completely at the map's left) to B (completely at the map's right), then once the player hides, since the event won't go back to a Return Spot, then its Autonomous Route is completely messed up. If the player hides closer to the right of the map, when the event will resume patrolling, it'll get stuck and won't go back and forth properly. It'll get stuck on the wall before it's done Moving Right.

And so, I tried your new method, and somehow it wouldn't work... It should, though, everything was in place, but it somehow didn't work.

I'll try other ways while using Common Events and your suggestions.
I've said it before, but the Galv's script never interfered with anything.
I thought the problem was that the move route did not work correctly when you used the Galv & Yanflys Script?

If the move commands are working correctly and the only problem ist that your event ist running into a wall, then it hast nothing to do with any plugins or scripts your are using.

You can Just Set the moveroute behaviour to "skip if impossible" (or how it's called in the english version^^), then it will skip all the move right commands it can not perform until it geht's to the move left commands.

Is this really the only problem though or is there something Else that didn't work?
I thought the problem was that the move route did not work correctly when you used the Galv & Yanflys Script?
Sorry, we probably got mixed up, I've tried so many ways here and there with the same stuff that I honestly don't remember the exact commands used in what version. But no, never said Galv's was a problem. Until now, it never was.


You can Just Set the moveroute behaviour to "skip if impossible" (or how it's called in the english version^^), then it will skip all the move right commands it can not perform until it geht's to the move left commands.

I do remember trying 'Skip' at some point but that didn't solve the problem. Sorry, I don't recall exactly all the different ways I've tried, now it's basically going back and forth with changed details, I end up not being able to tell you exactly what I tried and what won't work when and how orz

I'm working on this, and sometimes I don't get why stuff that should be logical don't do logical.

What I can say tho is that your suggestion of changing event's page with the Chase line and CommonEvent works, tho it's still tricky to make work the way I'd like.
Yeah I can imagine. Hopefully I did kann t confuse you any further, Just tried to help. But I am honestly still not sure what exactly the problem is xD
Having an Event Chase the Player and changing to a running animation isn't something unusual though and should deilfinitely be doable.
I am sure you'll figure it out^^ Still here if you run into a wall
Having an Event Chase the Player and changing to a running animation isn't something unusual though and should deilfinitely be doable.
yeah lol completely. Too bad they don't add anything to MV anymore (as far as i know) but it definitely lacks of more basics.

AND I FOUND MY SOLUTION HOORAY.

So, i had mentionned on my first post that I'd tried Galv's Event Detector and couldn't find how to use it exactly. Thought it wouldn't help. Turns out it was the right plugin to use, I just didn't know how to.

Only had to put
Code:
Galv.DETECT.event(3,6,true)
on conditionnal branch in a parallel process on the event, which didn't interfere with the javascript i've used for having the event moving from A to B endlessly.

That plugin actually gives the line of sight I've been longing for and it triggers whatever's put under the IF. In my case, it triggered another page of the event where it'd chase the player (Autonomous Route with 'Follow Player' on repeat + this._isDashing for animation) until they'd hide. The plugin's super easy to turn off when hiding, and so is to turn on when coming out of the hiding spot. And with a proper line of sight, the event doesn't detect the player once they're behind its back.

So YEAH, finally it's working the way I want!

Now i kinda feel bad for asking continiously for your help and yet the solution was somewhere else 😅 but thanks to that I did browse more the engine (and actually remembered Common Events exist lol). So thanks a lot for trying so hard anyway!

Original thread: https://forums.rpgmakerweb.com/threads/event-sees-player-in-the-right-direction.183010/