Jump to content

[suggestion] script.c: getusers() - idle and active


Recommended Posts

Posted

I needed this source mod so i suggest to apply it to rAthena.

Modification of getusers():
    2 - Count of all characters in the entire server who are idle.
    3 - Count of all characters in the entire server who are not idle.

 

So here's the diff:

Index: src/map/script.c
===================================================================
--- src/map/script.c    (revision 17248)
+++ src/map/script.c    (working copy)
@@ -9624,15 +9624,18 @@
 BUILDIN_FUNC(getusers)
 {
     int flag, val = 0;
-    struct map_session_data* sd;
+    bool idle = false;
+    TBL_PC *sd, *pl_sd;
     struct block_list* bl = NULL;
+    struct s_mapiterator* iter;
 
     flag = script_getnum(st,2);
 
-    switch(flag&0x07)
+    switch(flag)
     {
-        case 0:
-            if(flag&0x8)
+        case 0: //Count all characters on the map of the invoking character
+        case 8: //Count of all characters on the map of the NPC the script is running in
+            if(flag==8)
             {// npc
                 bl = map_id2bl(st->oid);
             }
@@ -9646,9 +9649,20 @@
                 val = map[bl->m].users;
             }
             break;
-        case 1:
+        case 1: //Count of all characters in the entire server
             val = map_getusers();
             break;
+        case 2: //Count of all characters in the entire server who are idle
+            idle = true;
+        case 3: //Count of all characters in the entire server who are not idle
+            iter = mapit_getallusers();
+            for( val=0, pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
+            {
+                if( pc_isidle(pl_sd) == idle )
+                    val++;
+            }
+            mapit_free(iter);
+            break;
         default:
             ShowWarning("buildin_getusers: Unknown type %d.\n", flag);
             script_pushint(st,0);
Index: src/map/party.c
===================================================================
--- src/map/party.c    (revision 17248)
+++ src/map/party.c    (working copy)
@@ -916,7 +916,7 @@
 
     // count the number of players eligible for exp sharing
     for (i = c = 0; i < MAX_PARTY; i++) {
-        if( (sd[c] = p->data[i].sd) == NULL || sd[c]->bl.m != src->m || pc_isdead(sd[c]) || (battle_config.idle_no_share && pc_isidle(sd[c])) )
+        if( (sd[c] = p->data[i].sd) == NULL || sd[c]->bl.m != src->m || pc_isdead(sd[c]) || pc_isidle(sd[c]) )
             continue;
         c++;
     }
@@ -980,7 +980,7 @@
                 if (i >= MAX_PARTY)
                     i = 0;    // reset counter to 1st person in party so it'll stop when it reaches "itemc"
 
-                if( (psd = p->data[i].sd) == NULL || sd->bl.m != psd->bl.m || pc_isdead(psd) || (battle_config.idle_no_share && pc_isidle(psd)) )
+                if( (psd = p->data[i].sd) == NULL || sd->bl.m != psd->bl.m || pc_isdead(psd) || pc_isidle(psd) )
                     continue;
 
                 if (pc_additem(psd,item_data,item_data->amount,LOG_TYPE_PICKDROP_PLAYER))
@@ -998,7 +998,7 @@
             int count = 0;
             //Collect pick candidates
             for (i = 0; i < MAX_PARTY; i++) {
-                if( (psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || (battle_config.idle_no_share && pc_isidle(psd[count])) )
+                if( (psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || pc_isidle(psd[count]) )
                     continue;
 
                 count++;
@@ -1046,7 +1046,7 @@
     if (sd->state.autotrade)
         return 0;
 
-    if (battle_config.idle_no_share && pc_isidle(sd))
+    if ( pc_isidle(sd) )
         return 0;
 
     return 1;
Index: src/map/pc.h
===================================================================
--- src/map/pc.h    (revision 17248)
+++ src/map/pc.h    (working copy)
@@ -608,7 +608,7 @@
 #define pc_setsit(sd)         ( (sd)->state.dead_sit = (sd)->vd.dead_sit = 2 )
 #define pc_isdead(sd)         ( (sd)->state.dead_sit == 1 )
 #define pc_issit(sd)          ( (sd)->vd.dead_sit == 2 )
-#define pc_isidle(sd)         ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share )
+#define pc_isidle(sd)         ( (sd)->chatID || (sd)->state.vending || (sd)->state.buyingstore || (battle_config.idle_no_share && DIFF_TICK(last_tick, (sd)->idletime) >= battle_config.idle_no_share ) )
 #define pc_istrading(sd)      ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->state.trading )
 #define pc_cant_act(sd)       ( (sd)->npc_id || (sd)->state.vending || (sd)->state.buyingstore || (sd)->chatID || ((sd)->sc.opt1 && (sd)->sc.opt1 != OPT1_BURNING) || (sd)->state.trading || (sd)->state.storage_flag || (sd)->state.prevend )
 
Index: doc/script_commands.txt
===================================================================
--- doc/script_commands.txt    (revision 17248)
+++ doc/script_commands.txt    (working copy)
@@ -2919,6 +2919,8 @@
 
     0 - Count of all characters on the map of the invoking character.
     1 - Count of all characters in the entire server.
+    2 - Count of all characters in the entire server who are idle.
+    3 - Count of all characters in the entire server who are not idle.
     8 - Count of all characters on the map of the NPC the script is
         running in.
 

 

Do you think this is useful for others, too?

  • 2 weeks later...
Posted

in my opinion, counting non-idle players on the server is usually used by event,

so its counted map-wide, not server-wide

I suggest if implementing this, might as well add this idea into getmapusers as well ...

  • Upvote 1
Posted

So we would get something like this:

*getmapusers("<map name>",{<type>})

and maybe
*getareausers("<map name>",<x1>,<y1>,<x2>,<y2>,{<type>})

Types:

0 - Count all users (Default)

1 - Count idle users

2 - Count users who are'nt idle

 

Did I understand you correctly?

  • 6 months later...
  • 2 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...