Multisite – maximum number of users with specific role

Ok here is how I did it:

add_action( 'editable_roles' , 'hide_editable_roles' );
function hide_editable_roles( $roles ){
$blog_id = get_current_blog_id(); // Get current subsite id
switch($blog_id) { // Define different max agents numbers depending on subsite id
    case 6: 
    $max_agents = 10; //for subsite id#6 we can have maximum 10 agents
     break;  
    case 7: //for subsite id#7 we can have maximum 3 agents
    $max_agents = 3;
    break;  
    default:
    $max_agents = 3000; //default is 3000 agents
    break;
}
  $agents = get_users( array( 'role' => 'agent' ) ); // here you define the role
  $agents = count( $agents );
    if ($max_agents <= $agents){
        unset( $roles['agent'] ); // here you define the role
    }
    return $roles;
}

tech