Jethro, it appears you might have made a small typo given that you have two pairs of parentheses surrounding that group of if conditions :p
if ((!%f && $istok($strip($1-),$me,32) && $chan != $active || $cid != $activecid)) {
is interpreted as:
if (((!%f) && ($istok($strip($1-),$me,32))) && ($chan != $active)) || ($cid != $activecid) {
meaning if $cid != $activecid, it would trigger regardless of the result of the previous conditions. the solution is of course to use extra () to group the last 2 conditions. there's also a neat little method you can use to combine them:
if (!%f) && ($istok($strip($1-),$me,32)) && ($chan $cid != $active $activecid) {