I use a small custom alias to lookup a connection number based on $cid to check which connection is being dealt with:
alias con {
var %x
scid -a $(%x = %x $cid,)
return $findtok(%x,$cid,32)
}
Simply use $con to return the number. As an example, let's suppose you only want your text event to respond to text occuring in the 2nd open connection:
on *:text:*:*:if ($con = 2) { commands }