vendmachine.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //===== rAthena Script =======================================
  2. //= Vending Machine
  3. //===== By: ==================================================
  4. //= Celestria
  5. //===== Current Version: =====================================
  6. //= 2.4
  7. //===== Compatible With: =====================================
  8. //= rAthena SVN
  9. //===== Description: =========================================
  10. //= sells items to players; occasionally the machine will "jam" :P
  11. //===== Additional Comments: =================================
  12. //= 1.0 - Creted a script for selling numerous items that would occasionally jam on players.
  13. //= - Used numbered variables to allow for multiplacation of the script.
  14. //= 1.1 - Fixed $jamplayer1 not being a string, thanks to Terces.
  15. //= - Changed random number that intiates jam to 1, to allow for faster modification of jam rates.
  16. //= 2.0 - Completely redid the script using a call-function.
  17. //= Now all replica scripts can simply be a copy of Vending Machine,
  18. //= but with variables modified to suit it''s intended use.
  19. //= 2.1 - Fixed an error where if one machine jammed on a menu item (say 3 for example),
  20. //= if another machine also jammed on the same menu item (3 in this case), the original
  21. //= machine to jam would be unjammed.
  22. //= - This fix only allows a machine to jam one item at a time. Will fix in the future.
  23. //= 2.2 - Added in/Renamed some variables to allow a single machine to block on several
  24. //= items simultaneously. This fix also allows the two-item drop to work with every
  25. //= item the machine is jammed on.
  26. //= 2.3 - Added in "Slam" feature, as well as admin ability to turn machine on and off.
  27. //= - Added admin menu. Allows GMs to put machines in/out of service, and to clear
  28. //= all jammed items.
  29. //= 2.4 - Made optimizations according to suggestions made by erKURITA. Script is now significantly shorter.
  30. //============================================================
  31. p_track01,45,58,4 script Vending Machine#1 910,{
  32. set @machine,1; //sets the unique number of this machine
  33. //DO NOT have two machines with the same number
  34. set @jamrate,1000; //Odds of machine jamming will be 1 in @jamrate
  35. set @slam,0; //set this to 0 to turn on the slam feature, any other setting disables it.
  36. set @fallrate,10; //Odds of machine falling on someone who hits it are 1 in @fallrate
  37. set @freerate,10000; //Odds of machine giving an item to someone who hits it are 1 in @freerate
  38. set @admin,99; //sets GM level needed to access Admin menu
  39. // the following sets the items for sale. Script currently only handles 10 items.
  40. setarray @item[0], 12143, 519, 565;
  41. setarray @price[0], 100, 50, 200;
  42. for (set @i,0; @i < 10; set @i,@i+1)
  43. set @itemn$[@i],getitemname(@item[@i]);
  44. set @menu$[0], @itemn$[0]+" - "+@price[0];
  45. set @menu$[1], @itemn$[1]+" - "+@price[1];
  46. set @menu$[2], @itemn$[2]+" - "+@price[2];
  47. set @menu$[3], "Cancel";
  48. set @menu$[4], "";
  49. set @menu$[5], "";
  50. set @menu$[6], "";
  51. set @menu$[7], "";
  52. set @menu$[8], "";
  53. set @menu$[9], "";
  54. set @menu$[10], ""; // "Cancel" only. Used if vending ten items.
  55. callfunc "F_Vend1";
  56. }
  57. //===============================================================================================
  58. // Functions
  59. //
  60. // !!!DO NOT EDIT BELOW THIS LINE!!!
  61. //
  62. //===============================================================================================
  63. function script F_Vend1 {
  64. if(getgmlevel() >= @admin) goto M_Admin;
  65. M_Player:
  66. if($outorder[@machine]) goto M_Ooo;
  67. if(@slam) callfunc "F_Vend2";
  68. mes "You see a vending machine. What would you like to do?";
  69. next;
  70. menu "Buy an item",M_Vend,"Hit it",M_Hit;
  71. M_Vend:
  72. callfunc "F_Vend2";
  73. end;
  74. M_Hit:
  75. callfunc "F_Slam";
  76. end;
  77. M_Admin:
  78. mes "[Admin Mode]";
  79. mes "What would you like to do?";
  80. next;
  81. menu "Player Mode",M_Player,"Post 'Out of Order'",M_Ooo2,"Remove 'Out of Order'",M_Ooo3,"Fix Jammed Items",M_Fix;
  82. M_Ooo:
  83. mes "Out of Order";
  84. close;
  85. M_Ooo2:
  86. set $outorder[@machine],1;
  87. mes "The machine is now Out of Service";
  88. close;
  89. M_Ooo3:
  90. set $outorder[@machine],0;
  91. mes "The machine is now in service.";
  92. close;
  93. M_Fix:
  94. for (set @i,0; @i < 10; set @i,@i+1)
  95. setd "$itemjam"+@i+"$[@machine]","";
  96. mes "All jammed items have been fixed.";
  97. close;
  98. }
  99. function script F_Vend2 {
  100. for (set @i,0; @i < 10; set @i,@i+1)
  101. if(strcharinfo(0)==getd("$itemjam"+@i+"$[@machine]")) goto B_StillJammed;
  102. set @jammed,rand(1,@jamrate);
  103. mes "You peek inside the vending machine to see what's available.";
  104. next;
  105. menu @menu$[0],M_Ite0, @menu$[1],M_Ite1, @menu$[2],M_Ite2, @menu$[3],M_Ite3,
  106. @menu$[4],M_Ite4, @menu$[5],M_Ite5, @menu$[6],M_Ite6, @menu$[7],M_Ite7,
  107. @menu$[8],M_Ite8, @menu$[9],M_Ite9, @menu$[10],M_Ite10;
  108. M_Ite0:
  109. set @num, 0;
  110. goto B_Buy;
  111. M_Ite1:
  112. set @num, 1;
  113. goto B_Buy;
  114. M_Ite2:
  115. set @num, 2;
  116. goto B_Buy;
  117. M_Ite3:
  118. set @num, 3;
  119. goto B_Buy;
  120. M_Ite4:
  121. set @num, 4;
  122. goto B_Buy;
  123. M_Ite5:
  124. set @num, 5;
  125. goto B_Buy;
  126. M_Ite6:
  127. set @num, 6;
  128. goto B_Buy;
  129. M_Ite7:
  130. set @num, 7;
  131. goto B_Buy;
  132. M_Ite8:
  133. set @num, 8;
  134. goto B_Buy;
  135. M_Ite9:
  136. set @num, 9;
  137. goto B_Buy;
  138. M_Ite10:
  139. set @num, 10;
  140. goto B_Buy;
  141. B_Cancel:
  142. mes "On second thoughts, you decide not to buy anything.";
  143. close;
  144. B_StillJammed:
  145. mes "You shake and punch the vending machine, but it appears no matter how much energy you exert, the dang item isn't going to come loose.";
  146. next;
  147. mes "["+strcharinfo(0)+"]";
  148. mes "DANG VENDING MACHINES!";
  149. close;
  150. B_Broke:
  151. mes "As you put your last zeny in, you realise you don't have enough to afford the product.";
  152. mes "Sadly you hit the refund button and pick up what little zeny you have.";
  153. close;
  154. B_Buy:
  155. if (@menu$[@num] == "Cancel") goto B_Cancel;
  156. for (set @i,0; @i < 10; set @i,@i+1)
  157. if(@num==@i) if(getd("$itemjam"+@i+"$[@machine]")) set @jammed,0;
  158. if(Zeny < @price[@num]) goto B_Broke;
  159. set Zeny,Zeny-@price[@num];
  160. if(@jammed == 1) goto B_Jamitem;
  161. mes "Vrrrrrrrr~";
  162. mes "*clunk*";
  163. next;
  164. if(@jammed == 0) goto B_Get2;
  165. getitem @item[@num],1;
  166. mes "A "+@itemn$[@num]+" pops out.";
  167. close;
  168. B_Get2:
  169. getitem @item[@num],2;
  170. mes "What the!?";
  171. mes "Two "+@itemn$[@num]+"s popped out!";
  172. mes "It must be your lucky day.";
  173. for (set @i,0; @i < 10; set @i,@i+1)
  174. if(@num==@i) setd "$itemjam"+@i+"$[@machine]","";
  175. close;
  176. B_Jamitem:
  177. mes "Vrrrrrrrr~";
  178. mes "*click*";
  179. next;
  180. mes "["+strcharinfo(0)+"]";
  181. mes "Dammit!";
  182. mes "I hate it when these damn things jam!";
  183. for (set @i,0; @i < 10; set @i,@i+1)
  184. if(@num==@i) setd "$itemjam"+@i+"$[@machine]",strcharinfo(0);
  185. close;
  186. }
  187. function script F_Slam {
  188. set @fall,rand(1,@fallrate);
  189. set @free,rand(1,@freerate);
  190. R_Item:
  191. set @num,rand(9);
  192. if(@item[@num]==0) goto R_Item;
  193. mes "You give the vending machine a good solid whack.";
  194. next;
  195. mes "...";
  196. next;
  197. if(@fall==1){
  198. mes "The machine shakes, and then falls directly on top of you.";
  199. close2;
  200. percentheal -100,-100;
  201. end;}
  202. if(@free==1){
  203. getitem @item[@num],1;
  204. mes "The machine shakes, and then drops an item.";
  205. close;}
  206. mes "The machine shakes, but nothing happens";
  207. close;
  208. }