ok here wat i have already so wat do I change?

if (%CTCPREPLY == on) { did -c $dname 41 }

and

if ($did(41).state == 1) { set %CTCPREPLY on }
else { set %CTCPREPLY off }