--- userpoints_role.module.orig	2008-05-05 18:57:44.000000000 +0400
+++ userpoints_role.module	2008-05-25 22:00:48.000000000 +0400
@@ -39,6 +39,13 @@
           '#title' => t('Points for role :') . $role_point['name'],
           '#default_value' => variable_get($role, 0),
         );
+        $form[$group][$role .'_tid'] = array(
+          '#type' => 'select',
+          '#title' => t('Category'),
+          '#default_value' => variable_get($role .'_tid', 0),
+          '#options'       => userpoints_get_categories(),
+          '#description'   => t('Category of these points'),
+        );
       }
 
       $form[$group][USERPOINTS_EMAIL_ROLE_JOIN] = array(
@@ -76,7 +83,13 @@
       if ($role_point['points'] > 0) {
         // Ignore roles that have 0 in them, since the admin does not want
         // users to join those roles
-        if ($points < $role_point['points']) {
+        if ($role_point['tid'] > 0) {
+          $cat_points = userpoints_get_current_points($uid, $role_point['tid']);
+          if ($cat_points < $role_point['points']) {
+            _userpoints_role_leave($uid, $role_point);
+          }
+        }
+        else if ($points < $role_point['points']) {
           _userpoints_role_leave($uid, $role_point);
         }
       }
@@ -88,7 +101,13 @@
       if ($role_point['points'] > 0) {
         // Ignore roles that have 0 in them, since the admin does not want
         // users to join those roles
-        if ($points >= $role_point['points']) {
+        if ($role_point['tid'] > 0) {
+          $cat_points = userpoints_get_current_points($uid, $role_point['tid']);
+          if ($cat_points < $role_point['points']) {
+            _userpoints_role_join($uid, $role_point);
+          }
+        }
+        else if ($points >= $role_point['points']) {
           _userpoints_role_join($uid, $role_point);
         }
       }
@@ -176,7 +195,8 @@
   return array(
     'rid' => $rid,
     'name' => $name,
-    'points' => (int)variable_get(USERPOINTS_ROLE . $rid, 0)
+    'points' => (int)variable_get(USERPOINTS_ROLE . $rid, 0),
+    'tid' => variable_get(USERPOINTS_ROLE . $rid .'_tid', 0),
   );
 }
 
