Quite a crazy idea. Wouldn't it be easier if you would switch all players team quietly with cs_set_user_team, while not changing their model? That way the cts could plant, and the ts could defuse.
Seriously try go around it. Check if the user, who wants to defuse is pressing the USE key( check in player pre think ) and pointing against the planted bomb entity( use get_user_aiming, because you can set the distance here ). If so, then start a "defuse progress" animation( you can find a good example for that in the zp_extra_lasermine plugin ). If the progress finished, then remove the bomb entity and force a round end, plus display a message in the center.
Simple!
Edit:
Never mind the player pre think - pointing - using part. Your Ham function is better.