AI stalk bar that fills when in sight/patrol around the player

Hey guys. My question is if anyone knows how to implement a way for an AI character to build up something over sight and when its finished it fires an event.
For example a bar that fills up whenever the AI character sees the player or a timer that depletes whenever the Ai sees the player. And when it reaches 100% it fires an external event. Does anyone know how to implement that in an efficient and resource-friendly way?

While I’m at it I would also like to ask if there is a way to set the AI to “patrol/move to” in a certain area around the player, like a trigger box that is attached to the character and the Ai can only choose a location inside that trigger box?