summaryrefslogtreecommitdiff
path: root/npc/custom/eAAC_Scripts/vendmachine.txt
blob: 17371ef9db1c9b375c5d0d3e1f494b00499afe10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
//===== rAthena Script =======================================
//= Vending Machine
//===== By: ==================================================
//= Celestria
//===== Current Version: =====================================
//= 2.4
//===== Compatible With: =====================================
//= rAthena SVN
//===== Description: =========================================
//= sells items to players; occasionally the machine will "jam" :P
//===== Additional Comments: =================================
//= 1.0 - Creted a script for selling numerous items that would occasionally jam on players.
//=     - Used numbered variables to allow for multiplacation of the script.
//= 1.1 - Fixed $jamplayer1 not being a string, thanks to Terces.
//=     - Changed random number that intiates jam to 1, to allow for faster modification of jam rates.
//= 2.0 - Completely redid the script using a call-function.
//=       Now all replica scripts can simply be a copy of Vending Machine,
//=       but with variables modified to suit it''s intended use.
//= 2.1 - Fixed an error where if one machine jammed on a menu item (say 3 for example),
//=       if another machine also jammed on the same menu item (3 in this case), the original
//=       machine to jam would be unjammed.
//=     - This fix only allows a machine to jam one item at a time. Will fix in the future.
//= 2.2 - Added in/Renamed some variables to allow a single machine to block on several
//=       items simultaneously. This fix also allows the two-item drop to work with every
//=       item the machine is jammed on.
//= 2.3 - Added in "Slam" feature, as well as admin ability to turn machine on and off.
//=     - Added admin menu. Allows GMs to put machines in/out of service, and to clear
//=       all jammed items.
//= 2.4 - Made optimizations according to suggestions made by erKURITA. Script is now significantly shorter.
//============================================================

p_track01,45,58,4	script	Vending Machine#1	910,{

	set @machine,1; //sets the unique number of this machine
	//DO NOT have two machines with the same number

	set @jamrate,1000; //Odds of machine jamming will be 1 in @jamrate

	set @slam,0; //set this to 0 to turn on the slam feature, any other setting disables it.
	set @fallrate,10; //Odds of machine falling on someone who hits it are 1 in @fallrate
	set @freerate,10000; //Odds of machine giving an item to someone who hits it are 1 in @freerate

	set @admin,99; //sets GM level needed to access Admin menu

	// the following sets the items for sale. Script currently only handles 10 items.
	setarray @item[0], 12143, 519, 565;
	setarray @price[0], 100, 50, 200;

	for (set @i,0; @i < 10; set @i,@i+1)
	set @itemn$[@i],getitemname(@item[@i]);

	set @menu$[0], @itemn$[0]+" - "+@price[0];
	set @menu$[1], @itemn$[1]+" - "+@price[1];
	set @menu$[2], @itemn$[2]+" - "+@price[2];
	set @menu$[3], "Cancel";
	set @menu$[4], "";
	set @menu$[5], "";
	set @menu$[6], "";
	set @menu$[7], "";
	set @menu$[8], "";
	set @menu$[9], "";
	set @menu$[10], ""; // "Cancel" only. Used if vending ten items.

	callfunc "F_Vend1";
}





//===============================================================================================
// Functions
//
// !!!DO NOT EDIT BELOW THIS LINE!!!
//
//===============================================================================================

function	script	F_Vend1	{

	if(getgmlevel() >= @admin) goto M_Admin;

M_Player:
	if($outorder[@machine]) goto M_Ooo;
	if(@slam) callfunc "F_Vend2";
	mes "You see a vending machine. What would you like to do?";
	next;
	menu "Buy an item",M_Vend,"Hit it",M_Hit;

M_Vend:
	callfunc "F_Vend2";
	end;

M_Hit:
	callfunc "F_Slam";
	end;

M_Admin:
	mes "[Admin Mode]";
	mes "What would you like to do?";
	next;
	menu "Player Mode",M_Player,"Post 'Out of Order'",M_Ooo2,"Remove 'Out of Order'",M_Ooo3,"Fix Jammed Items",M_Fix;

M_Ooo:
	mes "Out of Order";
	close;

M_Ooo2:
	set $outorder[@machine],1;
	mes "The machine is now Out of Service";
	close;

M_Ooo3:
	set $outorder[@machine],0;
	mes "The machine is now in service.";
	close;

M_Fix:
	for (set @i,0; @i < 10; set @i,@i+1)
	setd "$itemjam"+@i+"$[@machine]","";
	mes "All jammed items have been fixed.";
	close;
}

function	script	F_Vend2	{

	for (set @i,0; @i < 10; set @i,@i+1)
	if(strcharinfo(0)==getd("$itemjam"+@i+"$[@machine]")) goto B_StillJammed;
	set @jammed,rand(1,@jamrate);
	mes "You peek inside the vending machine to see what's available.";
	next;
	menu 	@menu$[0],M_Ite0, @menu$[1],M_Ite1, @menu$[2],M_Ite2, @menu$[3],M_Ite3, 
		@menu$[4],M_Ite4, @menu$[5],M_Ite5, @menu$[6],M_Ite6, @menu$[7],M_Ite7,
		@menu$[8],M_Ite8, @menu$[9],M_Ite9, @menu$[10],M_Ite10;

	M_Ite0:
		set @num, 0;
		goto B_Buy;
	M_Ite1:
		set @num, 1;
		goto B_Buy;
	M_Ite2:
		set @num, 2;
		goto B_Buy;
	M_Ite3:
		set @num, 3;
		goto B_Buy;
	M_Ite4:
		set @num, 4;
		goto B_Buy;
	M_Ite5:
		set @num, 5;
		goto B_Buy;
	M_Ite6:
		set @num, 6;
		goto B_Buy;
	M_Ite7:
		set @num, 7;
		goto B_Buy;
	M_Ite8:
		set @num, 8;
		goto B_Buy;
	M_Ite9:
		set @num, 9;
		goto B_Buy;
	M_Ite10:
		set @num, 10;
		goto B_Buy;


B_Cancel:
	mes "On second thoughts, you decide not to buy anything.";
	close;

B_StillJammed:
	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.";
	next;
	mes "["+strcharinfo(0)+"]";
	mes "DANG VENDING MACHINES!";
	close;

B_Broke:
	mes "As you put your last zeny in, you realise you don't have enough to afford the product.";
	mes "Sadly you hit the refund button and pick up what little zeny you have.";
	close;

B_Buy:
	if (@menu$[@num] == "Cancel") goto B_Cancel;
		for (set @i,0; @i < 10; set @i,@i+1) 
		if(@num==@i) if(getd("$itemjam"+@i+"$[@machine]")) set @jammed,0;
	if(Zeny < @price[@num]) goto B_Broke;
	set Zeny,Zeny-@price[@num];
	if(@jammed == 1) goto B_Jamitem;
	mes "Vrrrrrrrr~";
	mes "*clunk*";
	next;
	if(@jammed == 0) goto B_Get2;
	getitem @item[@num],1;
	mes "A "+@itemn$[@num]+" pops out.";
	close;
B_Get2:
	getitem @item[@num],2;
	mes "What the!?";
	mes "Two "+@itemn$[@num]+"s popped out!";
	mes "It must be your lucky day.";
		for (set @i,0; @i < 10; set @i,@i+1)
		if(@num==@i) setd "$itemjam"+@i+"$[@machine]","";
	close;
B_Jamitem:
	mes "Vrrrrrrrr~";
	mes "*click*";
	next;
	mes "["+strcharinfo(0)+"]";
	mes "Dammit!";
	mes "I hate it when these damn things jam!";
		for (set @i,0; @i < 10; set @i,@i+1)
		if(@num==@i) setd "$itemjam"+@i+"$[@machine]",strcharinfo(0);
	close;
}

function	script	F_Slam	{

	set @fall,rand(1,@fallrate);
	set @free,rand(1,@freerate);
R_Item:
	set @num,rand(9);
	if(@item[@num]==0) goto R_Item;

	mes "You give the vending machine a good solid whack.";
	next;
	mes "...";
	next;
	if(@fall==1){
		mes "The machine shakes, and then falls directly on top of you.";
		close2;
		percentheal -100,-100;
		end;}
	if(@free==1){
		getitem @item[@num],1;
		mes "The machine shakes, and then drops an item.";
		close;}
	mes "The machine shakes, but nothing happens";
	close;
}