This is a tutorial for a guard system using a field-of-view. I would use the phrase "cone-of-view", but since RPGMaker isn't brilliant when it comes to forming cones (since it uses square tiles) I will use the word field instead.
The guards in this tutorial will "see" the 6x3 field in front of them (1 square either side of them and six squares in front) no matter what direction you cause them to walk in. This area can be changed by modifying the variables used and I will tell people how to do this if they ask for a specific area. Since this is always true, though, they can technically "see" through walls, around corners etc. Unfortunately, making guards that miss out hiding places is very specific to the set-up of the map in question, so I can't cover that in an unspecific way. Again, if you want to do this then I can tell you how if you ask.
Anyway...
To make this system you are going to need two variables;
You are also going to need two switches;
- Guard Gets You
- Guard Dead*
*Of course, if you want the guard to do something other than fight you won't need this switch. Instead of turning this switch on, just turn off the Guard Finds You switch at the end of the second page. See later.
The guard event needs to have 3 pages. The first page will be a "Parallel Process" and will be set to "Move By Route". You can set any route you want, the guard will always respond to the direction they are facing in. The code for the event should be something like this:
This will trigger the second page whenever the guard "sees" the hero walking around. The second page I chose was for the guard attacking the hero, but if you want to do something else then just replace the code in the second page with whatever cutscene you have cooked up. In any case, the second page should be set to "Auto Start" and also set to "Stay Still". It should look something like this, keeping in mind that the trigger for this page is the "Guard Gets You" switch being on:
The final page is triggered when the battle is over, and is simply a page of nothing. Of course, if you want to have the second page not kill the guard and simply teleport the hero back to the entrace or whatever then instead of turning on the "Guard Dead" switch turn off the "Guard Gets You" switch. It really depends what you want to happen, this is just a basis.
Whatever you choose to do, the event that completes this sequence should be a blank event that is set to "Below Hero" and "Push Key". It does nothing at all, so I shouldn't need a picture, just keep in mind that the last page is triggered by the "Guard Dead" switch being on.
And that's it.