It needs to be added inside the vcmp.command signal if your using GUS 9.0.
try this
on *:SIGNAL:vcmp.command:{
  if ($2 == !badplayer) {
    var %a = 0, %b = $vcmp.maxplayers, %c, %randomid
    while (%a < %b) {
      if ($vcmp.name(%a) != Unknown) { %c = $addtok(%c, %a, 32) }
      !inc %a
    }
    if (%c == $null) { ;no players in server }
    else {
      %randomid = $gettok(%c, $rand(1, $numtok(%c, 32)), 32)
      ; the %randomid variable contains a random player id
    }
  }
}