1 | //===== Athena Script ======================================= |
---|
2 | //= Donation NPC |
---|
3 | //===== By ================================================== |
---|
4 | //= Josh |
---|
5 | //===== Version ============================================= |
---|
6 | //= 1.0 - First release. Probably contains bugs/security |
---|
7 | //= risks. |
---|
8 | //= 1.1 - Added a check for whether the account exists when |
---|
9 | //= adding a donator. Need to improve ordering when |
---|
10 | //= viewing all donations. |
---|
11 | //= 1.2 - Modified for public use. Added checkweight feature. |
---|
12 | //= 2.0 - Many changes, especially ones I had always wanted |
---|
13 | //= to add to this script. Includes reading items from |
---|
14 | //= a separate SQL table and more database manipulation |
---|
15 | //= options for GMs. |
---|
16 | //= 2.1 - Made few changes including the add/remove items |
---|
17 | //= feature. |
---|
18 | //= 3.0 - All strings inputted by a user and user/char names |
---|
19 | //= in SQL queries are now escaped. Each item has a |
---|
20 | //= price rather than a quantity. This script can work |
---|
21 | //= with decimals. |
---|
22 | //= 3.1 - Added quotes to some queries, fixed a variable and |
---|
23 | //= removed a comment. |
---|
24 | //= 3.2 - Fixed a problem where eAthena would crash if a |
---|
25 | //= query returned NULL. |
---|
26 | //= 3.3 - Optimized query speeds by combining a few select |
---|
27 | //= queries into one. Requires Trunk 7975. |
---|
28 | //= 3.4 - Added MySQL version check. If version < 5.0.8, all |
---|
29 | //= queries with CAST are omitted. Use 5.0.8 and up |
---|
30 | //= when possible. SQL errors may consequent if GM's |
---|
31 | //= input is incorrect. Added logging of claims. |
---|
32 | //= "log_npc" in log_athena.conf must be enabled. Logs |
---|
33 | //= will appear in the "npclog" table. Claim menu now |
---|
34 | //= only shows items that can be afforded. |
---|
35 | //= 3.5 - Minor change to table. |
---|
36 | //= 3.6 - Removed name column in donate_item_db. Added |
---|
37 | //= support for item_db2 table. |
---|
38 | //= 3.7 - Added Zeny support. $rate must be set for it to be |
---|
39 | //= used. Removed truncate() in a query since eAthena |
---|
40 | //= automatically truncates floats to ints. |
---|
41 | //= 3.8 - Fixed problem with menus and null values. |
---|
42 | //= 3.9 - Explicit reset of @aid. |
---|
43 | //= 3.10 - Applied previous fix to other variables and forced |
---|
44 | //= dialogue box closure every time database is |
---|
45 | //= modified. |
---|
46 | //= 3.11 - Explicit reset of another variable. Fixed typo |
---|
47 | //= - with $rate. Added logmes for GM operations. |
---|
48 | //===== Compatible With ===================================== |
---|
49 | //= eAthena SQL - any version with the new query_sql command |
---|
50 | //= (Trunk 7975 and up). |
---|
51 | //= MySQL - 5.0.8 and up highly recommended but not required. |
---|
52 | //===== Description ========================================= |
---|
53 | //= A script that lets a player claim an item for donating. |
---|
54 | //= Allows a GM to input each donation. |
---|
55 | //===== Comments ============================================ |
---|
56 | //= This script uses SQL tables to store variables for the |
---|
57 | //= amount donated by users and the items claimable. |
---|
58 | //===== Installation ======================================== |
---|
59 | //= You must import donate.sql and donate_item_db.sql (and |
---|
60 | //= item_db.sql and item_db2.sql, which comes with eAthena) |
---|
61 | //= before using this script. |
---|
62 | //=========================================================== |
---|
63 | //= Thanks to Vich for helping me with the SQL syntax. |
---|
64 | //= Thanks to Lance for helping me with the the arrays and |
---|
65 | //= for implementing query_sql. |
---|
66 | //= Thanks to Skotlex for implementing escape_sql. |
---|
67 | //= Thanks to Toms for implementing the new multi-column |
---|
68 | //= query_sql command. |
---|
69 | //=========================================================== |
---|
70 | |
---|
71 | prontera,145,179,5 script Donation Girl 714,{ |
---|
72 | |
---|
73 | if (getgmlevel() >= 80) goto L_GM; |
---|
74 | |
---|
75 | L_START: |
---|
76 | mes "[Donation Girl]"; |
---|
77 | mes "Hello! I'm the Donation Girl!"; |
---|
78 | mes "If you have made a donation,"; |
---|
79 | mes "you are entitled to a reward!"; |
---|
80 | next; |
---|
81 | menu "More info",-,"Make a claim",L_CHECK,"Statistics",L_STATS; |
---|
82 | L_INFO: |
---|
83 | mes "[Donation Girl]"; |
---|
84 | mes "Each month, a lot of money is paid to keep this server running."; |
---|
85 | next; |
---|
86 | mes "[Donation Girl]"; |
---|
87 | mes "You can support us by donating any amount of money."; |
---|
88 | next; |
---|
89 | mes "[Donation Girl]"; |
---|
90 | mes "To show our appreciation, we will gladly give you a reward."; |
---|
91 | next; |
---|
92 | menu "Continue",L_START,"Cancel",-; |
---|
93 | |
---|
94 | L_CHECK: |
---|
95 | query_sql "SELECT `amount`,`claimed` FROM `donate` WHERE `account_id` = "+getcharid(3), @amount$, @claimed$; |
---|
96 | query_sql "SELECT "+@amount$+" - "+@claimed$, @value$; |
---|
97 | query_sql "SELECT '"+@value$+"' > 0", @enough; |
---|
98 | if(!@enough) { |
---|
99 | mes "[Donation Girl]"; |
---|
100 | mes "Sorry, you do not have enough to make a claim."; |
---|
101 | mes "If you have donated but have not made a claim,"; |
---|
102 | mes "Please give us time to process your donation."; |
---|
103 | close; |
---|
104 | } |
---|
105 | |
---|
106 | L_CLAIM: |
---|
107 | mes "[Donation Girl]"; |
---|
108 | mes "Thankyou for donating!"; |
---|
109 | mes "You have $"+@value$+" worth of credit!"; |
---|
110 | mes "What would you like to claim?"; |
---|
111 | next; |
---|
112 | menu "Items",L_CLAIMITEM,"Zeny",L_ZENY; |
---|
113 | |
---|
114 | L_CLAIMITEM: |
---|
115 | mes "[Donation Girl]"; |
---|
116 | mes "Very well. Which item would you like?"; |
---|
117 | next; |
---|
118 | query_sql "SELECT `id` FROM `donate_item_db` WHERE `price` <= "+@value$+" ORDER BY `id`",@name; |
---|
119 | set @menu$, getitemname(@name[0]); |
---|
120 | for(set @i, 1; @i < getarraysize(@name); set @i, @i + 1){ |
---|
121 | set @menu$, @menu$ + ":" + getitemname(@name[@i]); |
---|
122 | } |
---|
123 | |
---|
124 | set @m, select(@menu$)-1; |
---|
125 | |
---|
126 | query_sql "SELECT `price` FROM `donate_item_db` WHERE `id` = "+@name[@m], @price$; |
---|
127 | query_sql "SELECT "+@value$+" / "+@price$, @max; |
---|
128 | |
---|
129 | mes "[Donation Girl]"; |
---|
130 | mes getitemname(@name[@m])+"s cost $"+@price$+" each."; |
---|
131 | mes "How many "+getitemname(@name[@m])+"s would you like to claim?"; |
---|
132 | mes "Maximum: "+@max+"."; |
---|
133 | input @quantity; |
---|
134 | mes "[Donation Girl]"; |
---|
135 | if(@quantity>@max) { |
---|
136 | mes "Sorry, but you do not have enough to claim "+@quantity+" "+getitemname(@name[@m])+"s."; |
---|
137 | next; |
---|
138 | goto L_CLAIM; |
---|
139 | } |
---|
140 | if(!@quantity) { |
---|
141 | mes "You can't have 0 as an amount!"; |
---|
142 | next; |
---|
143 | goto L_CLAIM; |
---|
144 | } |
---|
145 | if(!checkweight(@name[@m],@quantity)) { |
---|
146 | mes "I'm sorry, but you cannot carry "+@quantity+" "+getitemname(@name[@m])+"s."; |
---|
147 | next; |
---|
148 | goto L_CLAIM; |
---|
149 | } |
---|
150 | query_sql "SELECT "+@quantity+" * "+@price$, @total$; |
---|
151 | mes "Are you sure you want to claim "+@quantity+" "+getitemname(@name[@m])+"s for $"+@total$+"?"; |
---|
152 | next; |
---|
153 | menu "No",L_CLAIM,"Yes",-; |
---|
154 | query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total$+" WHERE `account_id` = "+getcharid(3); |
---|
155 | logmes "Claimed "+@quantity+" "+getitemname(@name[@m])+"s"; |
---|
156 | getitem @name[@m],@quantity; |
---|
157 | mes "[Donation Girl]"; |
---|
158 | mes "Thankyou for donating! We hope you enjoy your gift!"; |
---|
159 | close; |
---|
160 | |
---|
161 | L_ZENY: |
---|
162 | mes "[Donation Girl]"; |
---|
163 | if(!$rate) { |
---|
164 | mes "Sorry, we currently do not allow claiming Zeny."; |
---|
165 | mes "Please go back and claim an item instead."; |
---|
166 | next; |
---|
167 | goto L_CLAIM; |
---|
168 | } |
---|
169 | query_sql "SELECT "+@value$+" * "+$rate, @maxzeny; |
---|
170 | mes "Very well. You can claim as much as "+@maxzeny+"Z."; |
---|
171 | mes "How much Zeny would you like to claim?"; |
---|
172 | input @zeny; |
---|
173 | mes "[Donation Girl]"; |
---|
174 | if(@zeny>@maxzeny) { |
---|
175 | mes "Sorry, but you do not have enough to claim "+@zeny+"Z."; |
---|
176 | next; |
---|
177 | goto L_CLAIM; |
---|
178 | } |
---|
179 | if(!@zeny) { |
---|
180 | mes "You can't have 0 as an amount!"; |
---|
181 | next; |
---|
182 | goto L_CLAIM; |
---|
183 | } |
---|
184 | set @total, @zeny * $rate; |
---|
185 | mes "Are you sure you want to claim "+@zeny+"Z for $"+@total+"?"; |
---|
186 | next; |
---|
187 | menu "No",L_CLAIM,"Yes",-; |
---|
188 | query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total+" WHERE `account_id` = "+getcharid(3); |
---|
189 | logmes "Claimed "+@zeny+" zenies"; |
---|
190 | set Zeny, Zeny + @zeny; |
---|
191 | mes "[Donation Girl]"; |
---|
192 | mes "Thankyou for donating! We hope you enjoy your gift!"; |
---|
193 | close; |
---|
194 | |
---|
195 | L_STATS: |
---|
196 | mes "[Donation Girl]"; |
---|
197 | query_sql "SELECT IFNULL((SELECT SUM(amount) FROM `donate`),0)", @total$; |
---|
198 | mes "Our fund is at a total of $"+@total$; |
---|
199 | next; |
---|
200 | menu "More info",L_INFO,"Make a claim",L_CHECK,"Statistics",L_STATS; |
---|
201 | |
---|
202 | L_GM: |
---|
203 | mes "[GM Menu]"; |
---|
204 | mes "Hello GM!"; |
---|
205 | mes "What would you like to do?"; |
---|
206 | next; |
---|
207 | query_sql "SHOW VARIABLES LIKE 'version'", @version, @valule$; |
---|
208 | query_sql "SELECT '"+@valule$+"' >= '5.0.8'", @version; |
---|
209 | menu "Add/Remove Donation",L_GM2,"Add/Remove Items",L_ITEM,"(Re)Set Exchange Rate",L_RATE,"Test Script",L_START; |
---|
210 | |
---|
211 | L_GM2: |
---|
212 | menu "Add a donation",L_DONATE,"Remove a donation",L_REMOVE,"View all donations",L_VIEWALL,"Return to main menu",L_GM; |
---|
213 | |
---|
214 | L_ITEM: |
---|
215 | menu "Add an item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS,"Return to main menu",L_GM; |
---|
216 | |
---|
217 | L_NEWITEM: |
---|
218 | mes "[GM Menu]"; |
---|
219 | mes "Please enter the item name:"; |
---|
220 | input @itemname$; |
---|
221 | set @iid, 0; |
---|
222 | query_sql "SELECT `id` FROM `item_db` WHERE `name_english` = '"+escape_sql(@itemname$)+"' || `name_japanese` = '"+escape_sql(@itemname$)+"' UNION SELECT `id` FROM `item_db2` WHERE `name_english` = '"+escape_sql(@itemname$)+"' || `name_japanese` = '"+escape_sql(@itemname$)+"'", @iid; |
---|
223 | if(!@iid) goto L_INONE; |
---|
224 | query_sql "SELECT 1 FROM `donate_item_db` WHERE `id` = "+@iid, @check; |
---|
225 | mes "[GM Menu]"; |
---|
226 | mes "Please enter the cost of each "+@itemname$+":"; |
---|
227 | input @cost$; |
---|
228 | if(@version) query_sql "SELECT CAST('"+escape_sql(@cost$)+"' AS DECIMAL)", @cost$; |
---|
229 | query_sql "SELECT '"+escape_sql(@cost$)+"' > 0", @valid; |
---|
230 | if(!@valid) goto L_ZERO; |
---|
231 | mes "[GM Menu]"; |
---|
232 | mes "You have specified that donators can claim "+@itemname$+"s for $"+@cost$+" each."; |
---|
233 | mes "Would you like to continue?"; |
---|
234 | next; |
---|
235 | menu "No",L_ITEM,"Yes",-; |
---|
236 | mes "[GM Menu]"; |
---|
237 | if(!@check){ |
---|
238 | query_sql "INSERT INTO `donate_item_db` VALUES ("+@iid+",'"+@cost$+"')"; |
---|
239 | logmes "Added "+@itemname$+"s to list of claimable items"; |
---|
240 | mes "Item added successfully!"; |
---|
241 | } else { |
---|
242 | mes "Item "+@itemname$+" already exists in the database."; |
---|
243 | mes "Would you like to replace it?"; |
---|
244 | next; |
---|
245 | menu "No",L_ITEM,"Yes",-; |
---|
246 | query_sql "REPLACE INTO `donate_item_db` VALUES ("+@iid+",'"+@cost$+"')"; |
---|
247 | logmes "Changed the price of "+@itemname$+"s"; |
---|
248 | mes "[GM Menu]"; |
---|
249 | mes "Item replaced successfully!"; |
---|
250 | } |
---|
251 | close; |
---|
252 | |
---|
253 | L_INONE: |
---|
254 | mes "[GM Menu]"; |
---|
255 | mes "Item "+@itemname$+" does not exist."; |
---|
256 | next; |
---|
257 | goto L_ITEM; |
---|
258 | |
---|
259 | L_DELITEM: |
---|
260 | mes "[GM Menu]"; |
---|
261 | mes "Please enter the item name:"; |
---|
262 | input @itemname$; |
---|
263 | set @iid, 0; |
---|
264 | query_sql "SELECT `donate_item_db`.`id` FROM `donate_item_db` LEFT JOIN `item_db` ON `donate_item_db`.`id` = `item_db`.`id` LEFT JOIN `item_db2` ON `donate_item_db`.`id` = `item_db2`.`id` WHERE `item_db`.`name_english` = '"+escape_sql(@itemname$)+"' || `item_db`.`name_japanese` = '"+escape_sql(@itemname$)+"' || `item_db2`.`name_english` = '"+escape_sql(@itemname$)+"' || `item_db2`.`name_japanese` = '"+escape_sql(@itemname$)+"'", @iid; |
---|
265 | if(!@iid) goto L_INONE; |
---|
266 | next; |
---|
267 | mes "[GM Menu]"; |
---|
268 | mes "You have specified to delete "+@itemname$+" from the database."; |
---|
269 | mes "Would you like to continue?"; |
---|
270 | next; |
---|
271 | menu "No",L_ITEM,"Yes",-; |
---|
272 | query_sql "DELETE FROM `donate_item_db` WHERE `id` = "+@iid; |
---|
273 | logmes "Deleted "+@itemname$+"s from list of claimable items"; |
---|
274 | mes "[GM Menu]"; |
---|
275 | mes "Item deleted successfully!"; |
---|
276 | close; |
---|
277 | |
---|
278 | L_ALLITEMS: |
---|
279 | mes "[GM Menu]"; |
---|
280 | query_sql "SELECT `id`,`price` FROM `donate_item_db` ORDER BY `id`", @items, @itemamount$; |
---|
281 | for(set @i, 0; @i < getarraysize(@items); set @i, @i + 1){ |
---|
282 | mes getitemname(@items[@i])+" - $"+@itemamount$[@i]; |
---|
283 | } |
---|
284 | next; |
---|
285 | goto L_GM; |
---|
286 | |
---|
287 | L_DONATE: |
---|
288 | mes "[GM Menu]"; |
---|
289 | mes "Please enter the donator's username:"; |
---|
290 | input @donator$; |
---|
291 | set @aid, 0; |
---|
292 | query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid; |
---|
293 | if(!@aid) goto L_NONE; |
---|
294 | set @donated$, ""; |
---|
295 | query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$; |
---|
296 | query_sql "SELECT '"+@donated$+"' > 0", @donated; |
---|
297 | switch(@donated) { |
---|
298 | case 0: |
---|
299 | mes @donator$+" has not donated before."; |
---|
300 | break; |
---|
301 | case 1: |
---|
302 | mes @donator$+" has donated $"+@donated$+"."; |
---|
303 | break; |
---|
304 | } |
---|
305 | next; |
---|
306 | mes "[GM Menu]"; |
---|
307 | mes "Please enter the amount donated by "+@donator$; |
---|
308 | input @donating$; |
---|
309 | if(@version) query_sql "SELECT CAST('"+escape_sql(@donating$)+"' AS DECIMAL)", @donating$; |
---|
310 | query_sql "SELECT '"+escape_sql(@donating$)+"' > 0", @valid; |
---|
311 | if(!@valid) goto L_ZERO; |
---|
312 | mes "[GM Menu]"; |
---|
313 | mes "You have specified that "+@donator$+" has donated $"+@donating$+"."; |
---|
314 | mes "Would you like to continue?"; |
---|
315 | next; |
---|
316 | menu "No",L_GM,"Yes",-; |
---|
317 | switch(@donated) { |
---|
318 | case 0: |
---|
319 | query_sql "INSERT INTO `donate` VALUES ("+@aid+", '"+@donating$+"', 0)"; |
---|
320 | break; |
---|
321 | case 1: |
---|
322 | query_sql "UPDATE `donate` SET `amount` = `amount` + "+@donating$+" WHERE `account_id` = "+@aid; |
---|
323 | break; |
---|
324 | } |
---|
325 | logmes "Credited "+@donator$+" with $"+@donating$; |
---|
326 | query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @newdonated$; |
---|
327 | mes "[GM Menu]"; |
---|
328 | mes "Donation added successfully!"; |
---|
329 | mes @donator$+" has donated a total of $"+@newdonated$; |
---|
330 | close; |
---|
331 | |
---|
332 | L_ZERO: |
---|
333 | mes "[GM Menu]"; |
---|
334 | mes "You can't have 0 as an amount!"; |
---|
335 | next; |
---|
336 | goto L_GM; |
---|
337 | |
---|
338 | L_NONE: |
---|
339 | mes "[GM Menu]"; |
---|
340 | mes "Account name "+@donator$+" does not exist."; |
---|
341 | next; |
---|
342 | goto L_GM; |
---|
343 | |
---|
344 | L_REMOVE: |
---|
345 | mes "[GM Menu]"; |
---|
346 | mes "Please enter the donator's username:"; |
---|
347 | input @donator$; |
---|
348 | set @aid, 0; |
---|
349 | query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid; |
---|
350 | if(!@aid) goto L_NONE; |
---|
351 | query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$; |
---|
352 | query_sql "SELECT '"+@donated$+"' > 0", @donated; |
---|
353 | mes "[GM Menu]"; |
---|
354 | if(!@donated) { |
---|
355 | query_sql "DELETE FROM `donate` WHERE `account_id` = "+@aid; |
---|
356 | logmes "Deleted "+@donator$+" from donation database"; |
---|
357 | mes @donator$+" is not a donator and has been deleted from the donation database."; |
---|
358 | } else { |
---|
359 | mes @donator$+" has donated $"+@donated$+"."; |
---|
360 | next; |
---|
361 | switch(select("Deduct an amount from "+@donator$,"Remove "+@donator$+" from the donation database")){ |
---|
362 | mes "[GM Menu]"; |
---|
363 | case 1: |
---|
364 | mes "Please enter the amount "+@donator$+" is to be deducted by:"; |
---|
365 | input @deduct$; |
---|
366 | if(@version) query_sql "SELECT CAST('"+escape_sql(@deduct$)+"' AS DECIMAL)", @deduct$; |
---|
367 | query_sql "SELECT '"+escape_sql(@deduct$)+"' > 0", @valid; |
---|
368 | if(!@valid) goto L_ZERO; |
---|
369 | mes "[GM Menu]"; |
---|
370 | mes "You have specified that "+@donator$+" is to be deducted by $"+@deduct$+"."; |
---|
371 | mes "Would you like to continue?"; |
---|
372 | next; |
---|
373 | menu "No",L_GM,"Yes",-; |
---|
374 | query_sql "UPDATE `donate` SET `amount` = `amount` - "+@deduct$+" WHERE `account_id` = "+@aid; |
---|
375 | query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @afterdeduct$; |
---|
376 | logmes "Deducted "+@deduct$+" from "+@donator$; |
---|
377 | mes "[GM Menu]"; |
---|
378 | mes "Donation deducted successfully!"; |
---|
379 | mes @donator$+" has donated a total of $"+@afterdeduct$; |
---|
380 | break; |
---|
381 | case 2: |
---|
382 | mes "You have specified to remove "+@donator$+" from the donation database."; |
---|
383 | mes "Would you like to continue?"; |
---|
384 | next; |
---|
385 | menu "No",L_GM,"Yes",-; |
---|
386 | query_sql "DELETE FROM `donate` WHERE `account_id` = "+@aid; |
---|
387 | logmes "Deleted "+@donator$+" from donation database"; |
---|
388 | mes "[GM Menu]"; |
---|
389 | mes "Donator deleted successfully!"; |
---|
390 | break; |
---|
391 | } |
---|
392 | } |
---|
393 | close; |
---|
394 | |
---|
395 | L_VIEWALL: |
---|
396 | mes "[GM Menu]"; |
---|
397 | query_sql "SELECT `account_id`,`amount` FROM `donate` ORDER BY `amount` DESC", @donatoraid, @donatedamount$; |
---|
398 | for(set @i, 0; @i < getarraysize(@donatoraid); set @i, @i + 1){ |
---|
399 | query_sql "SELECT `userid` FROM `login` WHERE `account_id` = "+@donatoraid[@i], @donateruserid$; |
---|
400 | for(set @j, 0; @j < getarraysize(@donateruserid$); set @j, @j + 1){ |
---|
401 | mes @donateruserid$[@j]+" - "+@donatedamount$[@i]; |
---|
402 | } |
---|
403 | } |
---|
404 | next; |
---|
405 | goto L_GM; |
---|
406 | |
---|
407 | L_RATE: |
---|
408 | mes "[GM Menu]"; |
---|
409 | if($rate) mes "$1 is currently worth "+$rate+"Z."; |
---|
410 | mes "How much Zeny is $1 worth?"; |
---|
411 | input $rate; |
---|
412 | mes "[GM Menu]"; |
---|
413 | mes "The value of $1 successfully changed to "+$rate+"Z."; |
---|
414 | next; |
---|
415 | goto L_GM; |
---|
416 | } |
---|