One quick thing,
var %nick = $nick(#,$r(1,$nick(#,0)))
may need to be changed to
set %nick $nick(#,$r(1,$nick(#,0)))
as \"vars\" get deleted after the script has been exectued, therefore when ya try:
if ($Nick != %Nick) { Halt }
nothings gonna be popping there >.>