MZ I need help making an overworld enemy (Issue related to regions mostly)

Hello and good day to whoever reads.
Allow me to present my problem: It so happens that I´ve been trying to put together an event that works as an overworld enemy. I followed a tutorial that a guy on a different thread made, but the issue lays in that I can´t make the event remain on its designated area. According to the tutorial, once the player is inside of the region labeled with a 2, the event will pursuit them until reaching their position and starting a battle, when the player is in a different region that isn´t 2, the event will only wander around randomly, thing is, that with the random walking cycle command the event tends to sometimes walk away from the 2 region, making the event code fail (thus if I player touches the event when it´s out of the 2 region it won´t do anything) How can I make it so it only walks inside of the 2 region? is there away I can make one region work as quote on quote "barrier" that only works on the event but not in the player? I need enlightenment.

(Images of how the map and the event´s code look)
1763740566975.png

1763740601087.png

1763740630335.png

1763740650012.png


I also have a less Important problem with the event code that it isn´t really the point of this message, that being that whenever the event it´s on the branch of the code that tells it to pursuit the player, it keeps playing a SE that´s suppose to only play once that indicates that the event has seen the player. If any of you know how to deal with this it would also be welcomed.

I think that would be all. Thanks before hand to whoever sees this and sorry if I posted it in a place where I shouldn´t (I´m not used to use this forums).
Greetings,

To fix the issue of the overworld monster event leaving its box, all you need to do is change one line of your event code there.

Code:
If: SB-MonsterRID = 1
Set Movement Route: This Event
Move Backward

This will make it so if your monster touches RID 1, it will move backward one space, thereby keeping it always within its box.

As for the SE playing over and over again, that's because you have this set as a parallel event. This event will keep running over and over again on the map, starting from the top, which includes your SE.

To fix this while keeping your event structured as is, I would recommend encapsulating the movement route within a Loop command while the monster is chasing the player, thereby not running the entire event again constantly.

Begin your loop right above the event commands that setup the chase, after the SE is played. Make sure to include a Break Loop command for when the player touches RID 1, so that the monster will not be stuck in this loop once the chase has ended.

All that said, I think you would be better served if you moved all this code off of your monster and onto a separate event specifically for controlling your monster. Putting it all on the monster itself makes things a little more complex than they need to be imho.

With a separate event, you could turn it on and off as needed without affecting what your monster is doing passively, when it is not chasing your player.

I'd also recommend adding in some small waits within your parallel event, just a few frames at the top would do the trick, so it is not running every frame. Running a parallel event every frame is going to be gobbling up resources and could result in issues if you have multiple monsters on a map.

Happy game making,
-Niniann
Update: Thank you so much for the help!

Regarding the backwards movement idea, it was something I tried in the past but was a bit strange since the event tended to get bugged and ended walking way the region either way. I tried it once more and the solution I found was just to make the areas where the enemies could walk into a 1 region smaller, but in short words it did help a lot.

As for the SE thing, I tried working out the idea of the loop but I think I made the code a lot more complicated while trying to use it. Although, thanks to it I got to simplify things a bit more and found an alternative that works for me, that being playing around with a second tab in the event that would be the exact same but with some differences. Tab 1 works for the idle "not chasing" part, this one would have the SE play, then tab 2 is for the chasing, where I deleted the random walking part of the code and the SE, lastly tab 3 would just be for the respawning time and to ease the frame time of the event so it doesn´t run at all times. (I don´t know if I explained myself in a clear way but that´s more so it).

Concerning the frames issue you mentioned... I´m not having any issues with it despite having multiple enemies on screen, I don´t plan to have more than 4, that would be the maximum a map could have in my project, one or two per map would be the idea.

Once again, thank you so much for the feedback, I appreciate it a lot. Wish you a great day. ☺️

Original thread: https://forums.rpgmakerweb.com/threads/i-need-help-making-an-overworld-enemy-issue-related-to-regions-mostly.181124/