Code:
ctcp 300:deop *:*: {
  if (  !$botrank($3) ) { .notice $nick $3 outranks you, you may not deop them. | return }
  .
  .
  rest of the command
  .
  .
}
ctcp 2:deop *:*:.notice $nick You cannot deop users with higher access than yours.
alias botrank {
  var %me = $replace($level($fulladdress),$chr(44),$chr(32))
  var %victim = $replace($level($address($1,5)),$chr(44),$chr(32))
  var %x = 0, %y = 0
  while ( %me ) {
    if ( %x < $gettok(%me,1,32) ) { %x == $gettok(%me,1,32) }
    var %me == $deltok(%me,1,32)
  }
  while ( %victim ) {
    if ( %y < $gettok(%victim,1,32) ) { %y == $gettok(%victim,1,32) }
    var %victim == $deltok(%victim,1,32)
  }
  if ( %x >= %y ) { return $true }
  return $false
}


I haven't tested it, but that should work.