the best way would be to hook the engine wait call. doing this it would be possible to execute user defined script within any wait call (any script you need - at least if the script does not start a wait call again ).
If you really need such a plugin we can talk about this.