autopot.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //===== rAthena Script =======================================
  2. //= Auto-Potion
  3. //===== By: ==================================================
  4. //= Euphy
  5. //===== Current Version: =====================================
  6. //= 1.0
  7. //===== Compatible With: =====================================
  8. //= rAthena Project
  9. //===== Description: =========================================
  10. //= Provides an @autopot command to automatically use potions
  11. //= when hit (i.e. 'autobonus2').
  12. //===== Additional Comments: =================================
  13. //= 1.0 First version. [Euphy]
  14. //============================================================
  15. - script #autopot -1,{
  16. OnInit:
  17. bindatcmd("autopot",strnpcinfo(0)+"::OnCommand");
  18. end;
  19. L_Help:
  20. dispbottom "Available commands:";
  21. dispbottom " @autopot <item id> {<min hp % [1..100]> {<delay [50..1000]>}}";
  22. dispbottom " @autopot <on|off>";
  23. dispbottom " @autopot list";
  24. dispbottom " @autopot info";
  25. dispbottom " @autopot help";
  26. return;
  27. L_Info:
  28. dispbottom "------ Auto-Potion Information ------";
  29. dispbottom "POTION: " + getitemname(@autopot_id) + " (" + @autopot_id + ")";
  30. dispbottom "MIN HP: " + @autopot_min + " %";
  31. dispbottom "DELAY: " + @autopot_delay + " ms";
  32. dispbottom "---------------------------------------------";
  33. return;
  34. L_Start:
  35. .@potion = getarg(0);
  36. .@min = getarg(1);
  37. .@delay = getarg(2);
  38. if (.@min < 1 || .@min > 100) .@min = 90;
  39. if (.@delay < 50 || .@delay > 1000) .@delay = 50; // lower values will increase server strain
  40. switch (.@potion) {
  41. case 501:
  42. case 507:
  43. case 545:
  44. case 569: .@effect = EF_POTION1; break;
  45. case 502: .@effect = EF_POTION2; break;
  46. case 503:
  47. case 508:
  48. case 546:
  49. case 579:
  50. case 11500: .@effect = EF_POTION3; break;
  51. case 504:
  52. case 509:
  53. case 547:
  54. case 11501:
  55. case 11503:
  56. case 11548: .@effect = EF_POTION4; break;
  57. case 512:
  58. case 513:
  59. case 515:
  60. case 516:
  61. case 548:
  62. case 549:
  63. case 550:
  64. case 582:
  65. case 607: .@effect = EF_POTION7; break;
  66. default: .@effect = EF_EXIT; break;
  67. }
  68. if (BaseLevel < getiteminfo(.@potion,12)) {
  69. message strcharinfo(0), "Your base level is too low to use '" + getitemname(.@potion) + "'.";
  70. end;
  71. }
  72. @autopot_id = .@potion;
  73. @autopot_min = .@min;
  74. @autopot_delay = .@delay;
  75. @autopot_eff = .@effect;
  76. @autopot_none = 0;
  77. bonus_script "{ callfunc \"start_autopot\"; }",86400,8,0,SI_INCHEALRATE;
  78. message strcharinfo(0), "Auto-Potion started.";
  79. callsub L_Info;
  80. return;
  81. OnCommand:
  82. if (!getarraysize(.@atcmd_parameters$)) {
  83. message strcharinfo(0), "Invalid syntax.";
  84. callsub L_Help;
  85. end;
  86. }
  87. .@command$ = strtolower(.@atcmd_parameters$[0]);
  88. if (.@command$ == "on") {
  89. if (@autopot_min)
  90. message strcharinfo(0), "Auto-Potion is already on.";
  91. else if (@autopot_min_) {
  92. @autopot_min = @autopot_min_;
  93. @autopot_min_ = 0;
  94. message strcharinfo(0), "Auto-Potion enabled.";
  95. callsub L_Info;
  96. } else {
  97. message strcharinfo(0), "Auto-Potion has not been set.";
  98. callsub L_Help;
  99. }
  100. end;
  101. } else if (.@command$ == "off") {
  102. if (!@autopot_min)
  103. message strcharinfo(0), "Auto-Potion is already off.";
  104. else {
  105. @autopot_min_ = @autopot_min;
  106. @autopot_min = 0;
  107. message strcharinfo(0), "Auto-Potion disabled.";
  108. }
  109. end;
  110. } else if (.@command$ == "list") { // credits to AnnieRuru
  111. getinventorylist;
  112. for (; .@i < @inventorylist_count; .@i++) {
  113. if (getiteminfo(@inventorylist_id[.@i],2) == IT_HEALING) {
  114. .@items[.@count] = @inventorylist_id[.@i];
  115. .@menu$ = .@menu$ + sprintf("~ ^0055FF%s^000000 (%dx):", getitemname(@inventorylist_id[.@i]), countitem(@inventorylist_id[.@i]));
  116. .@count++;
  117. }
  118. }
  119. if (.@count) { // 'mes' window needed if player is hit during selection
  120. mes "[ Auto-Potion ]";
  121. mes "Select a healing item.";
  122. .@select = select(.@menu$ + " ^777777Cancel^000000") - 1;
  123. if (.@select != .@count)
  124. callsub L_Start, .@items[.@select], 0, 0;
  125. close2;
  126. } else
  127. message strcharinfo(0), "There are no healing items in your inventory.";
  128. end;
  129. } else if (.@command$ == "info") {
  130. if (@autopot_min) {
  131. message strcharinfo(0), "Auto-Potion information is displayed below.";
  132. callsub L_Info;
  133. } else
  134. message strcharinfo(0), "Auto-Potion is not enabled.";
  135. end;
  136. } else if (.@command$ == "help") {
  137. message strcharinfo(0), "List of commands is displayed below.";
  138. callsub L_Help;
  139. end;
  140. } else {
  141. .@potion = atoi(.@atcmd_parameters$[0]);
  142. if (getiteminfo(.@potion,2) != IT_HEALING) {
  143. message strcharinfo(0), getitemname(.@potion) + " is not a healing item.";
  144. end;
  145. }
  146. callsub L_Start, .@potion, atoi(.@atcmd_parameters$[1]), atoi(.@atcmd_parameters$[2]);
  147. end;
  148. }
  149. }
  150. function script start_autopot {
  151. if (@autopot_active) end;
  152. @autopot_active = 1;
  153. while (Hp && Hp * 100 / MaxHp < @autopot_min) {
  154. if (!countitem(@autopot_id)) {
  155. if (@autopot_none <= gettimetick(2)) {
  156. @autopot_none = gettimetick(2) + 10;
  157. dispbottom "There are no '" + getitemname(@autopot_id) + "' in your inventory.";
  158. }
  159. break;
  160. }
  161. if (getstatus(SC_BERSERK) || getstatus(SC_SATURDAYNIGHTFEVER) || getstatus(SC_GRAVITATION) ||
  162. getstatus(SC_TRICKDEAD) || getstatus(SC_HIDING) || getstatus(SC__SHADOWFORM) || getstatus(SC__INVISIBILITY) ||
  163. getstatus(SC__MANHOLE) || getstatus(SC_KAGEHUMI) || getstatus(SC_HEAT_BARREL_AFTER))
  164. break;
  165. if (getstatus(SC_STONE) || getstatus(SC_FREEZE) || getstatus(SC_STUN) || getstatus(SC_SLEEP))
  166. ;
  167. else {
  168. delitem @autopot_id,1;
  169. consumeitem @autopot_id;
  170. specialeffect2 @autopot_eff;
  171. }
  172. sleep2 @autopot_delay;
  173. }
  174. @autopot_active = 0;
  175. autobonus2 "{}",10000,1,BF_WEAPON|BF_MAGIC;
  176. end;
  177. }