How can I make an event that ends when the player leaves an area?

I'm working on a horror game and I have an event that I want set up in a specific way. I'm still very new to making games and using the program so I'm probably breaking a very crucial rule by using events as on-map enemy NPCs. Think... Corpse Party or something similar where the enemies can approach the player and if they catch the player, game over. BUT!! If the player leaves the area, their event ends and doesn't re-appear when the player goes back to that room.

I have the event set up to Game Over the player like intended, but now I'm not sure of how to set it up so the event ends when the player leaves the area. I don't know if I should use a Control Switch, Control Self Switch, or Conditional Branch.

Any suggestions on how I may be able to setting this issue?
Create a second page on your event that is chasing the player and have it set to a switch being turned on. (It's been a long time since I've fiddled with Ace, so you'll need to work with me on the explanation).

Set the exit for your players, the one used to leave the room, turn on that switch prior to initiating the move player event. This way, the global switch is turned on and if they go back it should be fine.

To prevent more shenanigans you can also add a second page to that same exit using the same switch that was turned on. This way you have a clear starting point if you have other things that might require a similar set up.

As a heads up, make a spreadsheet or something similar to keep track of these global switches. You'll want to keep note of "used/not uses" "map used on" "Event ID used on". It sounds tedious, and it is, but tedium prevents avoidable mistakes 🙂
If you don't want to use a switch for the second page set it to self switch A and use the script call
$game_self switches[[map id, event id, "A"]] = true

For example
$game_self_switches[[39, 6, "A"]] = true]]
Create a second page on your event that is chasing the player and have it set to a switch being turned on. (It's been a long time since I've fiddled with Ace, so you'll need to work with me on the explanation).

Set the exit for your players, the one used to leave the room, turn on that switch prior to initiating the move player event. This way, the global switch is turned on and if they go back it should be fine.

To prevent more shenanigans you can also add a second page to that same exit using the same switch that was turned on. This way you have a clear starting point if you have other things that might require a similar set up.

As a heads up, make a spreadsheet or something similar to keep track of these global switches. You'll want to keep note of "used/not uses" "map used on" "Event ID used on". It sounds tedious, and it is, but tedium prevents avoidable mistakes 🙂

Not quite sure I follow, but this is how I have the event set up. I should have posted pictures before but I was in a rush.

I have it set up like this:

Game Over Event.png


Event is triggered by an item in inventory -> event chases player: contact means game over/dead -> attempting to set it up so the event ends if a player makes it out of the area thus completely erasing the event so game can continue.

Basically, this is 1 out of a few death triggers I'm trying to set up for my game, and may honestly be one of the most complicated ones I've attempted so far.
If you don't want to use a switch for the second page set it to self switch A and use the script call
$game_self switches[[map id, event id, "A"]] = true

For example
$game_self_switches[[39, 6, "A"]] = true]]

I'm not good with scripting but I'm not against attempting it lol I'll do this as a last resort if I need to so thank you for the script!
This is not a script, but a script call. You use the Script command at the bottom of tab 3 of the Event Command menu. Just type it in there.

Using script calls is a fairly necessary feature of making a game, so it would be good to build up your confidence in using them. This particular one, for example, has lots of uses.

Suppose, for example, you want something e.g. a bit of dialogue to happen, or an NPC to do something when the player reaches that point. The approach may be four tiles wide. Then you would put it in one event and at the end do that script call for all 4 events across the approach. Copy/paste, done.

Perhaps you want to turn a self switch to OFF. Then instead of typing = true you type = false.
This is not a script, but a script call. You use the Script command at the bottom of tab 3 of the Event Command menu. Just type it in there.

Using script calls is a fairly necessary feature of making a game, so it would be good to build up your confidence in using them. This particular one, for example, has lots of uses.

Suppose, for example, you want something e.g. a bit of dialogue to happen, or an NPC to do something when the player reaches that point. The approach may be four tiles wide. Then you would put it in one event and at the end do that script call for all 4 events across the approach. Copy/paste, done.

Perhaps you want to turn a self switch to OFF. Then instead of typing = true you type = false.

So then basically what I would do is set up the script using script call but what event should I use it in? The NPC or the doors for the area calling to turn that event off?

I deeply apologize for my barrage of questions but I'm very new to RPG Maker and this is the very first game I've put effort into actually making. I've dabbled in the maker here and there but never went full on into making a game until I decided to do the one I'm working on now. So please, bare with me...

Here is a mash up of the event I'm using for the enemy NPC + Map
.
NPC Page 1.png
Put that script call into the event which transfers the player out of that map.

I'm afraid that your screenshot is too small and blurry for me to make out clearly, but it looks like the death page is conditioned by self switch B. Presumably there is nothing on the next page (page 4). If that is so, then make it conditioned by self switch C and change the script call to read:
Code:
$game_self_switches[[map id, event id, "C"]] = true

I would like to suggest that you have a look at Dreadshadow's playable tutorial on the Event Commands Menu which you can find here. Being interactive it is quicker and easier to learn from than watching or reading a tutorial. The bonus is that you can open it up in your editor and see how everything was done. Spending a couple of hours on that now will save you a ton of time and frustration in the long run.

If you haven't already done so, you might also have a look at Andars compilation of info for new users which is here. Lots of really useful things there, including another playable tutorial on Variables and Switches. Again you can open it up in the editor.
I've played through about half of "Events" and figured I wouldn't exactly need the script call command but I guess I was wrong. And you're correct, the 4th tab is empty and the 3rd tab with the death trigger is where I'm stuck.

Anyway, I have 2 different ways, whuch is basically progress into either of the 2 progression areas.

Also, after attempting the script in my test game it ended up breaking the gateway to exit the area.
So I added it to my test game and got this after leaving the room, maybe I set it up wrong?

Error.png
1599867270824.png
$game_self_switches
not $game_self_switch

Please don't make duplicate threads for the same question.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-make-an-event-that-ends-when-the-player-leaves-an-area.127090/