autopot.txt 7.4 KB

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