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