viewing paste Unknown #5823 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
Index: src/map/script.c
===================================================================
--- src/map/script.c    (revision 17319)
+++ src/map/script.c    (working copy)
@@ -12803,25 +12803,134 @@
    return 0;
 }
 
-/*==========================================
- * All The Players Full Recovery
- * (HP/SP full restore and resurrect if need)
- *------------------------------------------*/
+/*================================
+ * Map portion of recovery command
+ *--------------------------------*/
+int recovery_sub(struct map_session_data* sd, int revive)
+{
+   if(revive&(1|4) && pc_isdead(sd)) {
+       status_revive(&sd->bl, 100, 100);
+       clif_displaymessage(sd->fd,msg_txt(sd,16));
+   } else if(!pc_isdead(sd) && revive&(1|2)) {
+       status_percent_heal(&sd->bl, 100, 100);
+       clif_displaymessage(sd->fd,msg_txt(sd,680));
+   }
+   return 0;
+}
+
+/*=========================================================================
+ * Fully Recover a Character's HP/SP - [Capuche] & [Akinari] 
+ * recovery <target>,<string>,<revive_flag>,<string>;
+ * <target> :
+ * 0 - Character
+ * 1 - Character Party
+ * 2 - Character Guild
+ * 3 - Map (Character on map)
+ * 4 - All Characters
+ * <string> :
+ * <target> : 0   => Character's name
+ * <target> : 1-2 => Character's Party/Guild Name
+ * <target> : 3   => Map name (player attached map's name by default)
+ * <revive_flag> : 
+ *      : 1 => Revive and Recover (Default)
+ *      : 2 => Only Full Heal
+ *      : 4 => Only Revive
+ * <string> :
+ * <target> : 1-2 => Map name (Null = All)
+ *-------------------------------------------------------------------------*/
 BUILDIN_FUNC(recovery)
 {
-   TBL_PC* sd;
-   struct s_mapiterator* iter;
+   TBL_PC *sd = script_rid2sd(st);
 
-   iter = mapit_getallusers();
-   for( sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter) )
-   {
-       if(pc_isdead(sd))
-           status_revive(&sd->bl, 100, 100);
-       else
-           status_percent_heal(&sd->bl, 100, 100);
-       clif_displaymessage(sd->fd,msg_txt(sd,680));
+   int map = 0, type = 0, revive = 1;
+   const char *mapname;
+
+   type = script_getnum(st,2);
+
+   //We can set the revive flag whenever the second argument isn't a string
+   if(script_hasdata(st,4))
+       revive = script_getnum(st,4);
+
+   switch(type) {
+       case 0:
+           if(script_hasdata(st,3))
+               sd=map_id2sd(script_getnum(st,3));
+           if(sd == NULL) //If we don't have sd by now, bail out
+               return 0;
+           recovery_sub(sd, revive);
+           break;
+       case 1:
+       {
+           if(script_hasdata(st,5)) //Null map shouldn't cause issues, just won't do anything
+               map = map_mapname2mapid(script_getstr(st,5));
+           struct party_data* p;
+           struct map_session_data* pl_sd;
+           //When no party given, we use invoker party
+           int p_id, i;
+           if(script_hasdata(st,3))
+               p_id = script_getnum(st,3);
+           else
+               p_id = (sd)?sd->status.party_id:0;
+           p = party_search(p_id);
+           if(p == NULL)
+               return 0;
+           for (i = 0; i < MAX_PARTY; i++) {
+               if((!(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id)
+                   || (map && pl_sd->bl.m != map))
+                   continue;
+               recovery_sub(pl_sd, revive);
+           }
+           break;
+       }
+       case 2:
+       {
+           if(script_hasdata(st,5)) //Null map shouldn't cause issues, just won't do anything
+               map = map_mapname2mapid(script_getstr(st,5));
+           struct guild* g;
+           struct map_session_data* pl_sd;
+           //When no guild given, we use invoker guild
+           int g_id, i;
+           if(script_hasdata(st,3))
+               g_id = script_getnum(st,3);
+           else
+               g_id = (sd)?sd->status.guild_id:0;
+           g = guild_search(g_id);
+           if(g == NULL)
+               return 0;
+           for (i = 0; i < MAX_GUILD; i++) {
+               if((!(pl_sd = g->member[i].sd) || pl_sd->status.guild_id != g_id)
+                   || (map && pl_sd->bl.m != map))
+                   continue;
+               recovery_sub(pl_sd, revive);
+           }
+           break;
+       }
+       case 3:
+           if(script_hasdata(st,3))
+               map = map_mapname2mapid(script_getstr(st,3));
+           else
+               map = (sd)?sd->bl.m:0; //No sd and no map given - return
+           if(map < 1)
+               return 0;
+       case 4:
+       {
+           struct s_mapiterator *iter;
+           if(script_hasdata(st,3))
+               revive = script_getnum(st,3);
+           iter = mapit_getallusers();
+           for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) {
+               if(type == 3 && sd->bl.m != map)
+                   continue;
+               recovery_sub(sd, revive);
+           }
+           mapit_free(iter);
+           break;
+       }
+       default:
+           ShowWarning("script: buildin_recovery: Invalid type %d\n", type);
+           script_pushint(st,-1);
+           return 1;
    }
-   mapit_free(iter);
    return 0;
 }
 /*==========================================
@@ -17876,7 +17985,7 @@
 #endif
    BUILDIN_DEF(dispbottom,"s"), //added from jA [Lupus]
    BUILDIN_DEF(getusersname,""),
-   BUILDIN_DEF(recovery,""),
+   BUILDIN_DEF(recovery,"i???"),
    BUILDIN_DEF(getpetinfo,"i"),
    BUILDIN_DEF(gethominfo,"i"),
    BUILDIN_DEF(getmercinfo,"i?"),
Viewed 774 times, submitted by Guest.