Index: src/map/script.c =================================================================== --- src/map/script.c (revision 17319) +++ src/map/script.c (working copy) @@ -12803,27 +12803,161 @@ return 0; } -/*========================================== - * All The Players Full Recovery - * (HP/SP full restore and resurrect if need) - *------------------------------------------*/ -BUILDIN_FUNC(recovery) +/*================================ + * Map portion of recovery command + *--------------------------------*/ +int recovery_sub(struct block_list* bl, va_list ap) { - TBL_PC* sd; - struct s_mapiterator* iter; + struct map_session_data *sd = map_id2sd(bl->id); + int revive = va_arg(ap,int); - 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); + 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)); } - mapit_free(iter); return 0; } + +/*========================================================================= + * Fully Recover a Character's HP/SP - [Capuche] & [Akinari] + * recovery ,,,; + * : + * 0 - Character + * 1 - Character Party + * 2 - Character Guild + * 3 - Map (Character on map) + * 4 - All Characters + * : + * : 0-2 => Character's name + * : 1-3 => Map's name (player attached map's name by default) + * : (Add together flags to specify how you want to heal) + * : 1 => Revive and Recover + * : 2 => Only Full Heal + * : 4 => Only Revive + * : 8 => Party/Guild Map Only (must specify argument 4) + *-------------------------------------------------------------------------*/ +BUILDIN_FUNC(recovery) +{ + TBL_PC *sd = script_rid2sd(st); + + 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); + else if(!script_isstring(st,3)) + revive = script_getnum(st,3); + + switch(type) { + case 0: + case 1: + case 2: + if( script_hasdata(st,3) && script_isstring(st,3)) + sd = map_nick2sd(script_getstr(st,3)); + if( sd == NULL ) //If we don't have sd by now, bail out + return 0; + switch(type) { + case 0: + 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)); + } + break; + case 1: + { + if(revive&(8)) //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 = sd->status.party_id; + int i; + 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) + || (revive&(8) && pl_sd->bl.m != map)) + continue; + if(revive&(1|4) && pc_isdead(pl_sd)) { + status_revive(&pl_sd->bl, 100, 100); + clif_displaymessage(pl_sd->fd,msg_txt(pl_sd,16)); + } else if(!pc_isdead(pl_sd) && revive&(1|2)) { + status_percent_heal(&pl_sd->bl, 100, 100); + clif_displaymessage(pl_sd->fd,msg_txt(pl_sd,680)); + } + } + break; + } + case 2: + { + if(revive&(8)) //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 = sd->status.guild_id; + int i; + 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) + || (revive&(8) && pl_sd->bl.m != map)) + continue; + if(revive&(1|4) && pc_isdead(pl_sd)) { + status_revive(&pl_sd->bl, 100, 100); + clif_displaymessage(pl_sd->fd,msg_txt(pl_sd,16)); + } else if(!pc_isdead(pl_sd) && revive&(1|2)) { + status_percent_heal(&pl_sd->bl, 100, 100); + clif_displaymessage(pl_sd->fd,msg_txt(pl_sd,680)); + } + } + break; + } + } + 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; + map_foreachinmap(recovery_sub, map, BL_PC, revive); + break; + case 4: + { + struct s_mapiterator *iter; + iter = mapit_getallusers(); + for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) { + 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)); + } + } + mapit_free(iter); + break; + } + default: + ShowWarning("script: buildin_recovery: Invalid type %d\n", type); + script_pushint(st,-1); + return 1; + } + return 0; +} /*========================================== * Get your pet info: getpetinfo(n) * n -> 0:pet_id 1:pet_class 2:pet_name @@ -17876,7 +18010,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?"),