autopot.txt 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //===== rAthena Script =======================================
  2. //= Auto-Potion
  3. //===== Description: =========================================
  4. //= Provides an @autopot command to automatically use potions.
  5. //===== Changelogs: ==========================================
  6. //= 1.0 First version. [Euphy]
  7. //= 2.0 rewrite and adding SP option. [sader1992]
  8. //============================================================
  9. - script #autopot -1,{
  10. OnInit:
  11. .HP_Option = true; //Allow HP option
  12. .SP_Option = true; //Allow SP option
  13. .MinDelay = 100; //Minimum Delay Allowed in milliseconds (Default and Recommended: 100) [lower values will increase server strain]
  14. setarray .blackList[0],0; //Array of black listed item ID
  15. if(!.HP_Option && !.SP_Option){
  16. debugmes "Warning: @autopot both hp and sp are Disabled";
  17. debugmes "Warning: @autopot script has been Disabled!";
  18. end;
  19. }
  20. bindatcmd("autopot",strnpcinfo(0)+"::OnCommand",0,99);
  21. end;
  22. L_Help:
  23. dispbottom "Available commands:";
  24. if(.HP_Option && .SP_Option){
  25. dispbottom " @autopot <hp|sp> <item id> {<min hp|sp % [1..100]> {<delay [" + .MinDelay + "..1000]>}}";
  26. dispbottom " @autopot <hp|sp> list";
  27. dispbottom " @autopot <hp|sp> <on|off>";
  28. }else{
  29. dispbottom " @autopot <" + (.HP_Option?"hp":"sp") + "> <item id> {<min " + (.HP_Option?"hp":"sp") + " % [1..100]> {<delay [" + .MinDelay + "..1000]>}}";
  30. dispbottom " @autopot <" + (.HP_Option?"hp":"sp") + "> list";
  31. dispbottom " @autopot <" + (.HP_Option?"hp":"sp") + "> <on|off>";
  32. }
  33. dispbottom " @autopot info";
  34. dispbottom " @autopot help";
  35. dispbottom " @autopot blacklist";
  36. return;
  37. L_Info:
  38. dispbottom "----------Auto-Potion Information-----------";
  39. if(.HP_Option){
  40. dispbottom "HP POTION: " + getitemname(@autopot_hp_ID) + " (" + @autopot_hp_ID + ")";
  41. dispbottom "MIN HP: " + @autopot_hp_Min + " %";
  42. }
  43. if(.SP_Option){
  44. dispbottom "SP POTION: " + getitemname(@autopot_sp_ID) + " (" + @autopot_sp_ID + ")";
  45. dispbottom "MIN SP: " + @autopot_sp_Min + " %";
  46. }
  47. dispbottom "DELAY: " + @autopot_delay + " ms";
  48. dispbottom "---------------------------------------------";
  49. return;
  50. L_Start:
  51. deltimer strnpcinfo(3) + "::OnStart";
  52. .@type$ = getarg(0,0);
  53. .@potion = getarg(1,0);
  54. setd "@autopot_" + .@type$ + "_Min",getarg(2,0);
  55. @autopot_delay = getarg(3,0);
  56. if (getd("@autopot_" + .@type$ + "_Min") < 1 || getd("@autopot_" + .@type$ + "_Min") > 100) setd "@autopot_" + .@type$ + "_Min",90;
  57. if (@autopot_delay < 50 || @autopot_delay > 1000) @autopot_delay = .MinDelay;
  58. if (getiteminfo(.@potion,2) != IT_HEALING) {
  59. dispbottom getitemname(.@potion) + " is not a healing item.";
  60. end;
  61. }
  62. if(inarray(.blackList[0],.@potion) != -1){
  63. message strcharinfo(0), "'" + getitemname(.@potion) + "' is black listed and cannot be used.";
  64. end;
  65. }
  66. if (BaseLevel < getiteminfo(.@potion,12)) {
  67. message strcharinfo(0), "Your base level is too low to use '" + getitemname(.@potion) + "'.";
  68. end;
  69. }
  70. setd "@autopot_" + .@type$ + "_ID",.@potion;
  71. setd "@autopot_" + .@type$ + "_Active",true;
  72. addtimer .@delay,strnpcinfo(3) + "::OnStart";
  73. message strcharinfo(0), "Auto-Potion " + strtoupper(.@type$) + " enabled.";
  74. callsub L_Info;
  75. return;
  76. OnCommand:
  77. if (!getarraysize(.@atcmd_parameters$)) {
  78. message strcharinfo(0), "Invalid syntax.";
  79. callsub L_Help;
  80. end;
  81. }
  82. .@command$[0] = strtolower(.@atcmd_parameters$[0]);
  83. .@command$[1] = strtolower(.@atcmd_parameters$[1]);
  84. if(.@command$[0] == "hp" || .@command$[0] == "sp"){
  85. if((!.HP_Option && .@command$[0] == "hp") || (!.SP_Option && .@command$[0] == "sp")){
  86. message strcharinfo(0), "Auto-Potion " + strtoupper(.@command$[0]) + " is Disabled from The Server.";
  87. end;
  88. }
  89. if(.@command$[1] == "on"){
  90. if(getd("@autopot_" + .@command$[0] + "_Active")){
  91. message strcharinfo(0), "Auto-Potion " + strtoupper(.@command$[0]) + " is already on.";
  92. end;
  93. }
  94. if(!getd("@autopot_" + .@command$[0] + "_ID")){
  95. dispbottom "You need to set a " + strtoupper(.@command$[0]) + " Potion to be used.";
  96. callsub L_Help;
  97. end;
  98. }
  99. callsub L_Start,.@command$[0],getd("@autopot_" + .@command$[0] + "_ID");
  100. end;
  101. }
  102. if(.@command$[1] == "off"){
  103. message strcharinfo(0), "Auto-Potion " + strtoupper(.@command$[0]) + " disabled.";
  104. setd "@autopot_" + .@command$[0] + "_Active",false;
  105. if(!@autopot_hp_Active || !@autopot_sp_Active)
  106. deltimer strnpcinfo(3) + "::OnStart";
  107. end;
  108. }
  109. if(.@command$[1] == "list"){
  110. getinventorylist;
  111. for(.@i = 0;.@i < @inventorylist_count;.@i++){
  112. if (getiteminfo(@inventorylist_id[.@i],2) == IT_HEALING) {
  113. .@items[.@count] = @inventorylist_id[.@i];
  114. .@menu$ = .@menu$ + sprintf("~ ^0055FF%s^000000 (%dx)" + (inarray(.blackList[0],@inventorylist_id[.@i]) != -1? " ^364022Black Listed^000000":"") + (BaseLevel < getiteminfo(@inventorylist_id[.@i],12)? " ^E82C0CNeed Higher Level^000000":"") + ":", getitemname(@inventorylist_id[.@i]), countitem(@inventorylist_id[.@i]));
  115. .@count++;
  116. }
  117. }
  118. if(.@count){
  119. mes "[ Auto-Potion ]";
  120. mes "Select a " + strtoupper(.@command$[0]) + " item.";
  121. .@select = select(.@menu$ + " ^777777Cancel^000000") - 1;
  122. if (.@select != .@count)
  123. callsub L_Start,.@command$[0],.@items[.@select];
  124. close2;
  125. }else{
  126. message strcharinfo(0), "There are no healing items in your inventory.";
  127. }
  128. end;
  129. }
  130. .@potion = atoi(.@command$[1]);
  131. .@percent = atoi(.@atcmd_parameters$[2]);
  132. .@delay = atoi(.@atcmd_parameters$[3]);
  133. if(getitemname(.@potion) != "null"){
  134. callsub L_Start,.@command$[0],.@potion,.@percent,.@delay;
  135. end;
  136. }
  137. message strcharinfo(0), "Auto-Potion : something went wrong!";
  138. callsub L_Help;
  139. end;
  140. }
  141. if(.@command$[0] == "blacklist"){
  142. dispbottom "--------------Black Listed Items--------------";
  143. for(.@i=0;.@i<getarraysize(.blackList);.@i++){
  144. dispbottom " " + getitemname(.blackList[.@i]) + " (" + .blackList[.@i] + ")";
  145. }
  146. dispbottom "---------------------------------------------";
  147. end;
  148. }
  149. if(.@command$[0] == "info"){
  150. if(@autopot_hp_Active || @autopot_sp_Active){
  151. message strcharinfo(0), "Auto-Potion information is displayed below.";
  152. callsub L_Info;
  153. }else{
  154. message strcharinfo(0), "Auto-Potion is not enabled.";
  155. }
  156. end;
  157. }
  158. if(.@command$[0] == "help"){
  159. message strcharinfo(0), "List of commands is displayed below.";
  160. callsub L_Help;
  161. end;
  162. }
  163. message strcharinfo(0), "Invalid syntax.";
  164. callsub L_Help;
  165. end;
  166. OnStart:
  167. if (!getstatus(SC_BERSERK) && !getstatus(SC_SATURDAYNIGHTFEVER) && !getstatus(SC_GRAVITATION) &&
  168. !getstatus(SC_TRICKDEAD) && !getstatus(SC_HIDING) && !getstatus(SC__SHADOWFORM) && !getstatus(SC__INVISIBILITY) &&
  169. !getstatus(SC__MANHOLE) && !getstatus(SC_KAGEHUMI) && !getstatus(SC_HEAT_BARREL_AFTER) &&
  170. !getstatus(SC_STONE) && !getstatus(SC_FREEZE) && !getstatus(SC_STUN) && !getstatus(SC_SLEEP))
  171. {
  172. if(Hp){
  173. if(@autopot_hp_Active && Hp * 100 / MaxHp < @autopot_hp_Min) {
  174. if (countitem(@autopot_hp_ID)) {
  175. delitem @autopot_hp_ID,1;
  176. consumeitem @autopot_hp_ID;
  177. specialeffect2 207;
  178. }
  179. }
  180. if(@autopot_sp_Active && Sp * 100 / MaxSp < @autopot_sp_Min) {
  181. if (countitem(@autopot_sp_ID)) {
  182. delitem @autopot_sp_ID,1;
  183. consumeitem @autopot_sp_ID;
  184. specialeffect2 208;
  185. }
  186. }
  187. }
  188. }
  189. if(@autopot_hp_Active || @autopot_sp_Active)
  190. addtimer @autopot_delay,strnpcinfo(3) + "::OnStart";
  191. end;
  192. }