vendmachine.txt 6.5 KB

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