I think your problem might be this line:

Code:
var %i 1 %chan = $iif($1,$1,$active)


Change it to:

Code:
var %i = 1, %chan = $iif($1,$1,$active)


Using your code I was unable to loop through the nicknames, which I believe might have been the cause.