yuhsing

Untitled

Oct 14th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1.  
  2. /*=========================================================================
  3. * Fully Recover a Character's HP/SP - [Capuche] & [Akinari]
  4. * recovery <type>{,<option>,<revive_flag>{,<map name>}};
  5. * <type> determines <option>:
  6. * 0 : char_id
  7. * 1 : party_id
  8. * 2 : guild_id
  9. * 3 : map_name
  10. * 4 : all characters
  11. * <revive_flag>:
  12. * 1 : Revive and heal all players (default)
  13. * 2 : Heal living players only
  14. * 4 : Revive dead players only
  15. * <map name>:
  16. * for types 1-2 : map_name (null = all maps)
  17. *-------------------------------------------------------------------------*/
  18. BUILDIN_FUNC(recovery)
  19. {
  20. TBL_PC *sd = script_rid2sd(st);
  21.  
  22. int map = 0, type = 0, revive = 1;
  23.  
  24. type = script_getnum(st,2);
  25.  
  26. if(script_hasdata(st,4))
  27. revive = script_getnum(st,4);
  28.  
  29. switch(type) {
  30. case 0:
  31. if(script_hasdata(st,3))
  32. sd=map_charid2sd(script_getnum(st,3));
  33. if(sd == NULL) //If we don't have sd by now, bail out
  34. return 0;
  35. recovery_sub(sd, revive);
  36. break;
  37. case 1:
  38. {
  39. struct party_data* p;
  40. struct map_session_data* pl_sd;
  41. //When no party given, we use invoker party
  42. int p_id, i;
  43. if(script_hasdata(st,5)) {//Bad maps shouldn't cause issues
  44. map = map_mapname2mapid(script_getstr(st,5));
  45. if(map < 1) { //But we'll check anyways
  46. ShowDebug("recovery: bad map name given (%s)\n", script_getstr(st,5));
  47. return 1;
  48. }
  49. }
  50. if(script_hasdata(st,3))
  51. p_id = script_getnum(st,3);
  52. else
  53. p_id = (sd)?sd->status.party_id:0;
  54. p = party_search(p_id);
  55. if(p == NULL)
  56. return 0;
  57. for (i = 0; i < MAX_PARTY; i++) {
  58. if((!(pl_sd = p->data[i].sd) || pl_sd->status.party_id != p_id)
  59. || (map && pl_sd->bl.m != map))
  60. continue;
  61. recovery_sub(pl_sd, revive);
  62. }
  63. break;
  64. }
  65. case 2:
  66. {
  67. struct guild* g;
  68. struct map_session_data* pl_sd;
  69. //When no guild given, we use invoker guild
  70. int g_id, i;
  71. if(script_hasdata(st,5)) {//Bad maps shouldn't cause issues
  72. map = map_mapname2mapid(script_getstr(st,5));
  73. if(map < 1) { //But we'll check anyways
  74. ShowDebug("recovery: bad map name given (%s)\n", script_getstr(st,5));
  75. return 1;
  76. }
  77. }
  78. if(script_hasdata(st,3))
  79. g_id = script_getnum(st,3);
  80. else
  81. g_id = (sd)?sd->status.guild_id:0;
  82. g = guild_search(g_id);
  83. if(g == NULL)
  84. return 0;
  85. for (i = 0; i < MAX_GUILD; i++) {
  86. if((!(pl_sd = g->member[i].sd) || pl_sd->status.guild_id != g_id)
  87. || (map && pl_sd->bl.m != map))
  88. continue;
  89. recovery_sub(pl_sd, revive);
  90. }
  91. break;
  92. }
  93. case 3:
  94. if(script_hasdata(st,3))
  95. map = map_mapname2mapid(script_getstr(st,3));
  96. else
  97. map = (sd)?sd->bl.m:0; //No sd and no map given - return
  98. if(map < 1)
  99. return 1;
  100. case 4:
  101. {
  102. struct s_mapiterator *iter;
  103. if(script_hasdata(st,3) && !script_isstring(st,3))
  104. revive = script_getnum(st,3); // recovery 4,<revive_flag>;
  105. iter = mapit_getallusers();
  106. for (sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); sd = (TBL_PC*)mapit_next(iter)) {
  107. if(type == 3 && sd->bl.m != map)
  108. continue;
  109. recovery_sub(sd, revive);
  110. }
  111. mapit_free(iter);
  112. break;
  113. }
  114. default:
  115. ShowWarning("script: buildin_recovery: Invalid type %d\n", type);
  116. script_pushint(st,-1);
  117. return 1;
  118. }
  119. script_pushint(st,1); //Successfully executed without errors
  120. return 0;
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132. BUILDIN_DEF(recovery,"i???"),
Advertisement
Add Comment
Please, Sign In to add comment