This will limit hiding to once per round, and will autohide if they tried too early (and do sneak attack if they tried to hide when fighting). Put this either in the heartbeat of a persistant object or in your module's heartbeat. Change the 'CHECK_HIDE_DELAY' var to raise or lower the frequency of checks.