Help with angry guards.

Hi in my game there is a part where the player has to run through and area, get a key come back, and unlock a cage then escape. There are going to be guards and the walk slowly and nonchalantly around until the player gets within a certain distance. Then they move at top speed until the touch the player then a battle starts. There is no way for the player to save while this is happening, and no way to get additional hp unless they already had items. How am I supposed to do this. I need the guards to be able to "see" and then target the player. They need to not be able to see through objects or to other heights, like if the player is up on a cliff the guard down below couldn't see them. Could I do this with like a region that follows the guards around and when you touch it the guards runs toward you. I have no idea how to pull this off. I don't are if this can be done with scripts or events.
There are a few stealth systems out there that can account for things such as visibility objects and such. I know that Jet made one and I've seen a couple of others. I personally use events with a small snippet that checks for the players proximity in approximation to the event instead most of the time, though that doesn't really account for visibility through objects very well so you'd probably want to go the full on script route instead. 

http://forums.rpgmakerweb.com/index.php?/topic/3336-stealth-system/
The easiest approach I'd take is some scripting.  You can use the real_x and real_y members of each event, together with the distance formula:

sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )

You could then use Region IDs to represent heights, and have a script call which ignores the player if the player has a different Region ID than the event.

This would represent cliff heights and places a guard can see.  

I'd press F11 and look at some of the built-in game scripts, particularly Game_Map and DataManager (the latter has the globals) to see which members exist.

Also, look up the Ruby Programming Language online, since that is the language the scripts are written in.
I like going the pre-made script route, but i can't use jet's script beacuse i can't use it in a commercial game, and i plan on selling my game when i am done.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-angry-guards.26356/