vendmachine.txt 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. //=====================================
  2. // Vending Machine Script
  3. // v2.4
  4. //=====================================
  5. // by Celestria
  6. //=====================================
  7. // Changelog:
  8. // 2.4 - Removed Duplicates [Silent]
  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.gat,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. set @itemn$[0], getitemname(@item[0]);
  45. set @itemn$[1], getitemname(@item[1]);
  46. set @itemn$[2], getitemname(@item[2]);
  47. set @itemn$[3], getitemname(@item[3]);
  48. set @itemn$[4], getitemname(@item[4]);
  49. set @itemn$[5], getitemname(@item[5]);
  50. set @itemn$[6], getitemname(@item[6]);
  51. set @itemn$[7], getitemname(@item[7]);
  52. set @itemn$[8], getitemname(@item[8]);
  53. set @itemn$[9], getitemname(@item[9]);
  54. set @menu$[0], @itemn$[0]+" - "+@price[0];
  55. set @menu$[1], @itemn$[1]+" - "+@price[1];
  56. set @menu$[2], @itemn$[2]+" - "+@price[2];
  57. set @menu$[3], "Cancel";
  58. set @menu$[4], "";
  59. set @menu$[5], "";
  60. set @menu$[6], "";
  61. set @menu$[7], "";
  62. set @menu$[8], "";
  63. set @menu$[9], "";
  64. set @menu$[10], ""; // "Cancel" only. Used if vending ten items.
  65. callfunc "F_Vend1";
  66. }
  67. //===============================================================================================
  68. // Functions
  69. //
  70. // !!!DO NOT EDIT BELOW THIS LINE!!!
  71. //
  72. //===============================================================================================
  73. function script F_Vend1 {
  74. if(getgmlevel() >= @admin) goto M_Admin;
  75. M_Player:
  76. if($outorder[@machine]) goto M_Ooo;
  77. if(@slam) callfunc "F_Vend2";
  78. mes "You see a vending machine. What would you like to do?";
  79. next;
  80. menu "Buy an item",M_Vend,"Hit it",M_Hit;
  81. M_Vend:
  82. callfunc "F_Vend2";
  83. end;
  84. M_Hit:
  85. callfunc "F_Slam";
  86. end;
  87. M_Admin:
  88. mes "[Admin Mode]";
  89. mes "What would you like to do?";
  90. next;
  91. menu "Player Mode",M_Player,"Post 'Out of Order'",M_Ooo2,"Remove 'Out of Order'",M_Ooo3,"Fix Jammed Items",M_Fix;
  92. M_Ooo:
  93. mes "Out of Order";
  94. close;
  95. M_Ooo2:
  96. set $outorder[@machine],1;
  97. mes "The machine is now Out of Service";
  98. close;
  99. M_Ooo3:
  100. set $outorder[@machine],0;
  101. mes "The machine is now in service.";
  102. close;
  103. M_Fix:
  104. set $itemjam0$[@machine],"0";
  105. set $itemjam1$[@machine],"0";
  106. set $itemjam2$[@machine],"0";
  107. set $itemjam3$[@machine],"0";
  108. set $itemjam4$[@machine],"0";
  109. set $itemjam5$[@machine],"0";
  110. set $itemjam6$[@machine],"0";
  111. set $itemjam7$[@machine],"0";
  112. set $itemjam8$[@machine],"0";
  113. set $itemjam9$[@machine],"0";
  114. mes "All jammed items have been fixed.";
  115. close;
  116. }
  117. function script F_Vend2 {
  118. if(strcharinfo(0)==$itemjam0$[@machine]) goto B_StillJammed;
  119. if(strcharinfo(0)==$itemjam1$[@machine]) goto B_StillJammed;
  120. if(strcharinfo(0)==$itemjam2$[@machine]) goto B_StillJammed;
  121. if(strcharinfo(0)==$itemjam3$[@machine]) goto B_StillJammed;
  122. if(strcharinfo(0)==$itemjam4$[@machine]) goto B_StillJammed;
  123. if(strcharinfo(0)==$itemjam5$[@machine]) goto B_StillJammed;
  124. if(strcharinfo(0)==$itemjam6$[@machine]) goto B_StillJammed;
  125. if(strcharinfo(0)==$itemjam7$[@machine]) goto B_StillJammed;
  126. if(strcharinfo(0)==$itemjam8$[@machine]) goto B_StillJammed;
  127. if(strcharinfo(0)==$itemjam9$[@machine]) goto B_StillJammed;
  128. set @jammed,rand(1,@jamrate);
  129. mes "You peek inside the vending machine to see what's available.";
  130. next;
  131. menu @menu$[0],M_Ite0, @menu$[1],M_Ite1, @menu$[2],M_Ite2, @menu$[3],M_Ite3,
  132. @menu$[4],M_Ite4, @menu$[5],M_Ite5, @menu$[6],M_Ite6, @menu$[7],M_Ite7,
  133. @menu$[8],M_Ite8, @menu$[9],M_Ite9, @menu$[10],M_Ite10;
  134. M_Ite0:
  135. set @num, 0;
  136. goto B_Buy;
  137. M_Ite1:
  138. set @num, 1;
  139. goto B_Buy;
  140. M_Ite2:
  141. set @num, 2;
  142. goto B_Buy;
  143. M_Ite3:
  144. set @num, 3;
  145. goto B_Buy;
  146. M_Ite4:
  147. set @num, 4;
  148. goto B_Buy;
  149. M_Ite5:
  150. set @num, 5;
  151. goto B_Buy;
  152. M_Ite6:
  153. set @num, 6;
  154. goto B_Buy;
  155. M_Ite7:
  156. set @num, 7;
  157. goto B_Buy;
  158. M_Ite8:
  159. set @num, 8;
  160. goto B_Buy;
  161. M_Ite9:
  162. set @num, 9;
  163. goto B_Buy;
  164. M_Ite10:
  165. set @num, 10;
  166. goto B_Buy;
  167. B_Cancel:
  168. mes "On second thoughts, you decide not to buy anything.";
  169. close;
  170. B_StillJammed:
  171. 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.";
  172. next;
  173. mes "["+strcharinfo(0)+"]";
  174. mes "DANG VENDING MACHINES!";
  175. close;
  176. B_Broke:
  177. mes "As you put your last zeny in, you realise you don't have enough to afford the product.";
  178. mes "Sadly you hit the refund button and pick up what little zeny you have.";
  179. close;
  180. B_Buy:
  181. if (@menu$[@num] == "Cancel") goto B_Cancel;
  182. if(@num==0){if($itemjam0$[@machine]!="0") set @jammed,0;}
  183. if(@num==1){if($itemjam1$[@machine]!="0") set @jammed,0;}
  184. if(@num==2){if($itemjam2$[@machine]!="0") set @jammed,0;}
  185. if(@num==3){if($itemjam3$[@machine]!="0") set @jammed,0;}
  186. if(@num==4){if($itemjam4$[@machine]!="0") set @jammed,0;}
  187. if(@num==5){if($itemjam5$[@machine]!="0") set @jammed,0;}
  188. if(@num==6){if($itemjam6$[@machine]!="0") set @jammed,0;}
  189. if(@num==7){if($itemjam7$[@machine]!="0") set @jammed,0;}
  190. if(@num==8){if($itemjam8$[@machine]!="0") set @jammed,0;}
  191. if(@num==9){if($itemjam9$[@machine]!="0") set @jammed,0;}
  192. if(Zeny < @price[@num]) goto B_Broke;
  193. set Zeny,Zeny-@price[@num];
  194. if(@jammed == 1) goto B_Jamitem;
  195. mes "Vrrrrrrrr~";
  196. mes "*clunk*";
  197. next;
  198. if(@jammed == 0) goto B_Get2;
  199. getitem @item[@num],1;
  200. mes "A "+@itemn$[@num]+" pops out.";
  201. close;
  202. B_Get2:
  203. getitem @item[@num],2;
  204. mes "What the!?";
  205. mes "Two "+@itemn$[@num]+"s popped out!";
  206. mes "It must be your lucky day.";
  207. if(@num==0) set $itemjam0$[@machine],"0";
  208. if(@num==1) set $itemjam1$[@machine],"0";
  209. if(@num==2) set $itemjam2$[@machine],"0";
  210. if(@num==3) set $itemjam3$[@machine],"0";
  211. if(@num==4) set $itemjam4$[@machine],"0";
  212. if(@num==5) set $itemjam5$[@machine],"0";
  213. if(@num==6) set $itemjam6$[@machine],"0";
  214. if(@num==7) set $itemjam7$[@machine],"0";
  215. if(@num==8) set $itemjam8$[@machine],"0";
  216. if(@num==9) set $itemjam9$[@machine],"0";
  217. close;
  218. B_Jamitem:
  219. mes "Vrrrrrrrr~";
  220. mes "*click*";
  221. next;
  222. mes "["+strcharinfo(0)+"]";
  223. mes "Dammit!";
  224. mes "I hate it when these damn things jam!";
  225. if(@num==0) set $itemjam0$[@machine],strcharinfo(0);
  226. if(@num==1) set $itemjam1$[@machine],strcharinfo(0);
  227. if(@num==2) set $itemjam2$[@machine],strcharinfo(0);
  228. if(@num==3) set $itemjam3$[@machine],strcharinfo(0);
  229. if(@num==4) set $itemjam4$[@machine],strcharinfo(0);
  230. if(@num==5) set $itemjam5$[@machine],strcharinfo(0);
  231. if(@num==6) set $itemjam6$[@machine],strcharinfo(0);
  232. if(@num==7) set $itemjam7$[@machine],strcharinfo(0);
  233. if(@num==8) set $itemjam8$[@machine],strcharinfo(0);
  234. if(@num==9) set $itemjam9$[@machine],strcharinfo(0);
  235. close;
  236. }
  237. function script F_Slam {
  238. set @fall,rand(1,@fallrate);
  239. set @free,rand(1,@freerate);
  240. R_Item:
  241. set @num,rand(9);
  242. if(@item[@num]==0) goto R_Item;
  243. mes "You give the vending machine a good solid whack.";
  244. next;
  245. mes "...";
  246. next;
  247. if(@fall==1){
  248. mes "The machine shakes, and then falls directly on top of you.";
  249. close2;
  250. percentheal -100,-100;
  251. end;}
  252. if(@free==1){
  253. getitem @item[@num],1;
  254. mes "The machine shakes, and then drops an item.";
  255. close;}
  256. mes "The machine shakes, but nothing happens";
  257. close;
  258. }