Okay, add the following line before the query:
PHP Code:
$timecutoff = TIMENOW - $vbulletin->options['cookietimeout'];
And then change the db query to the following:
PHP Code:
$users_online = $vbulletin->db->query_read("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
INNER JOIN " . TABLE_PREFIX . "session AS session
ON session.userid = user.userid
WHERE user.usergroupid IN (" . $groupid . ")
" . $qwhere . "
AND session.loggedin > 0
AND session.lastactivity >= " . $timecutoff . "
GROUP BY user.userid
ORDER BY user.lastactivity DESC
");