From mistake i deleted the last post o.0, anyway try this version.Make shure that number of players from same team with spectated player is > 1.
EDIT:
-Little update, and i've tested it, works fine.
-The plugin switches to another player from same team with spectated player...so if spectated player is CT then will pick a random player from CT and switch to him.
Maybe i will make this more complex:
*Menu.
*Switch to a random player from all players or specfied team.
*Can restrict spec only for some players, not for all.