Hide in closets mechanic?

Can anyone explain how I could make a mechanic where in certain areas, you can hide from enemies by hiding in closets or crates? I'm sure it's simple, but I wanna make sure I'm on the right track. (I haven't started, but I need it for the near future.)

Basically, the enemies are freely roaming around and can spot you if you get too close. If they spot you, you will be chased until they catch you. They also have a larger hearing range and the player has a sound that randomly goes off (like a phone ringing or notification or something) and the enemies will be able to hear this and find you from afar (even if you aren't right next to them). I want the player to be able to hide in things to get the enemies off their backs. If the noise goes off while they're in the hiding spot, the enemies will not detect it.

Thank you!
Just make a conditional in the enemy event that checks if a switch is on.
Then, when you hide, turn on the switch, and when you leave the hiding spot, you turn it off.

Original thread: https://forums.rpgmakerweb.com/threads/hide-in-closets-mechanic.162585/