root/npc/custom/eAAC_Scripts/DonationGirl/donate.txt @ 1

Revision 1, 14.9 kB (checked in by jinshiro, 17 years ago)
Line 
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
71prontera,145,179,5      script  Donation Girl   714,{
72
73if (getgmlevel() >= 80) goto L_GM;
74
75L_START:
76mes "[Donation Girl]";
77mes "Hello! I'm the Donation Girl!";
78mes "If you have made a donation,";
79mes "you are entitled to a reward!";
80next;
81menu "More info",-,"Make a claim",L_CHECK,"Statistics",L_STATS;
82L_INFO:
83mes "[Donation Girl]";
84mes "Each month, a lot of money is paid to keep this server running.";
85next;
86mes "[Donation Girl]";
87mes "You can support us by donating any amount of money.";
88next;
89mes "[Donation Girl]";
90mes "To show our appreciation, we will gladly give you a reward.";
91next;
92menu "Continue",L_START,"Cancel",-;
93
94L_CHECK:
95query_sql "SELECT `amount`,`claimed` FROM `donate` WHERE `account_id` = "+getcharid(3), @amount$, @claimed$;
96query_sql "SELECT "+@amount$+" - "+@claimed$, @value$;
97query_sql "SELECT '"+@value$+"' > 0", @enough;
98if(!@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
106L_CLAIM:
107mes "[Donation Girl]";
108mes "Thankyou for donating!";
109mes "You have $"+@value$+" worth of credit!";
110mes "What would you like to claim?";
111next;
112menu "Items",L_CLAIMITEM,"Zeny",L_ZENY;
113
114L_CLAIMITEM:
115mes "[Donation Girl]";
116mes "Very well. Which item would you like?";
117next;
118query_sql "SELECT `id` FROM `donate_item_db` WHERE `price` <= "+@value$+" ORDER BY `id`",@name;
119set @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
124set @m, select(@menu$)-1;
125
126query_sql "SELECT `price` FROM `donate_item_db` WHERE `id` = "+@name[@m], @price$;
127query_sql "SELECT "+@value$+" / "+@price$, @max;
128
129mes "[Donation Girl]";
130mes getitemname(@name[@m])+"s cost $"+@price$+" each.";
131mes "How many "+getitemname(@name[@m])+"s would you like to claim?";
132mes "Maximum: "+@max+".";
133input @quantity;
134mes "[Donation Girl]";
135if(@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        }
140if(!@quantity) {
141        mes "You can't have 0 as an amount!";
142        next;
143        goto L_CLAIM;
144        }
145if(!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        }
150query_sql "SELECT "+@quantity+" * "+@price$, @total$;
151mes "Are you sure you want to claim "+@quantity+" "+getitemname(@name[@m])+"s for $"+@total$+"?";
152next;
153menu "No",L_CLAIM,"Yes",-;
154query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total$+" WHERE `account_id` = "+getcharid(3);
155logmes "Claimed "+@quantity+" "+getitemname(@name[@m])+"s";
156getitem @name[@m],@quantity;
157mes "[Donation Girl]";
158mes "Thankyou for donating! We hope you enjoy your gift!";
159close;
160
161L_ZENY:
162mes "[Donation Girl]";
163if(!$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        }
169query_sql "SELECT "+@value$+" * "+$rate, @maxzeny;
170mes "Very well. You can claim as much as "+@maxzeny+"Z.";
171mes "How much Zeny would you like to claim?";
172input @zeny;
173mes "[Donation Girl]";
174if(@zeny>@maxzeny) {
175        mes "Sorry, but you do not have enough to claim "+@zeny+"Z.";
176        next;
177        goto L_CLAIM;
178        }
179if(!@zeny) {
180        mes "You can't have 0 as an amount!";
181        next;
182        goto L_CLAIM;
183        }
184set @total, @zeny * $rate;
185mes "Are you sure you want to claim "+@zeny+"Z for $"+@total+"?";
186next;
187menu "No",L_CLAIM,"Yes",-;
188query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total+" WHERE `account_id` = "+getcharid(3);
189logmes "Claimed "+@zeny+" zenies";
190set Zeny, Zeny + @zeny;
191mes "[Donation Girl]";
192mes "Thankyou for donating! We hope you enjoy your gift!";
193close;
194
195L_STATS:
196mes "[Donation Girl]";
197query_sql "SELECT IFNULL((SELECT SUM(amount) FROM `donate`),0)", @total$;
198mes "Our fund is at a total of $"+@total$;
199next;
200menu "More info",L_INFO,"Make a claim",L_CHECK,"Statistics",L_STATS;
201
202L_GM:
203mes "[GM Menu]";
204mes "Hello GM!";
205mes "What would you like to do?";
206next;
207query_sql "SHOW VARIABLES LIKE 'version'", @version, @valule$;
208query_sql "SELECT '"+@valule$+"' >= '5.0.8'", @version;
209menu "Add/Remove Donation",L_GM2,"Add/Remove Items",L_ITEM,"(Re)Set Exchange Rate",L_RATE,"Test Script",L_START;
210
211L_GM2:
212menu "Add a donation",L_DONATE,"Remove a donation",L_REMOVE,"View all donations",L_VIEWALL,"Return to main menu",L_GM;
213
214L_ITEM:
215menu "Add an item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS,"Return to main menu",L_GM;
216
217L_NEWITEM:
218mes "[GM Menu]";
219mes "Please enter the item name:";
220input @itemname$;
221set @iid, 0;
222query_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;
223if(!@iid) goto L_INONE;
224query_sql "SELECT 1 FROM `donate_item_db` WHERE `id` = "+@iid, @check;
225mes "[GM Menu]";
226mes "Please enter the cost of each "+@itemname$+":";
227input @cost$;
228if(@version) query_sql "SELECT CAST('"+escape_sql(@cost$)+"' AS DECIMAL)", @cost$;
229query_sql "SELECT '"+escape_sql(@cost$)+"' > 0", @valid;
230if(!@valid) goto L_ZERO;
231mes "[GM Menu]";
232mes "You have specified that donators can claim "+@itemname$+"s for $"+@cost$+" each.";
233mes "Would you like to continue?";
234next;
235menu "No",L_ITEM,"Yes",-;
236mes "[GM Menu]";
237if(!@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        }
251close;
252
253L_INONE:
254mes "[GM Menu]";
255mes "Item "+@itemname$+" does not exist.";
256next;
257goto L_ITEM;
258
259L_DELITEM:
260mes "[GM Menu]";
261mes "Please enter the item name:";
262input @itemname$;
263set @iid, 0;
264query_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;
265if(!@iid) goto L_INONE;
266next;
267mes "[GM Menu]";
268mes "You have specified to delete "+@itemname$+" from the database.";
269mes "Would you like to continue?";
270next;
271menu "No",L_ITEM,"Yes",-;
272query_sql "DELETE FROM `donate_item_db` WHERE `id` = "+@iid;
273logmes "Deleted "+@itemname$+"s from list of claimable items";
274mes "[GM Menu]";
275mes "Item deleted successfully!";
276close;
277
278L_ALLITEMS:
279mes "[GM Menu]";
280query_sql "SELECT `id`,`price` FROM `donate_item_db` ORDER BY `id`", @items, @itemamount$;
281for(set @i, 0; @i < getarraysize(@items); set @i, @i + 1){
282                mes getitemname(@items[@i])+" - $"+@itemamount$[@i];
283        }
284next;
285goto L_GM;
286
287L_DONATE:
288mes "[GM Menu]";
289mes "Please enter the donator's username:";
290input @donator$;
291set @aid, 0;
292query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
293if(!@aid) goto L_NONE;
294set @donated$, "";
295query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$;
296query_sql "SELECT '"+@donated$+"' > 0", @donated;
297switch(@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        }
305next;
306mes "[GM Menu]";
307mes "Please enter the amount donated by "+@donator$;
308input @donating$;
309if(@version) query_sql "SELECT CAST('"+escape_sql(@donating$)+"' AS DECIMAL)", @donating$;
310query_sql "SELECT '"+escape_sql(@donating$)+"' > 0", @valid;
311if(!@valid) goto L_ZERO;
312mes "[GM Menu]";
313mes "You have specified that "+@donator$+" has donated $"+@donating$+".";
314mes "Would you like to continue?";
315next;
316menu "No",L_GM,"Yes",-;
317switch(@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        }
325logmes "Credited "+@donator$+" with $"+@donating$;
326query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @newdonated$;
327mes "[GM Menu]";
328mes "Donation added successfully!";
329mes @donator$+" has donated a total of $"+@newdonated$;
330close;
331
332L_ZERO:
333mes "[GM Menu]";
334mes "You can't have 0 as an amount!";
335next;
336goto L_GM;
337
338L_NONE:
339mes "[GM Menu]";
340mes "Account name "+@donator$+" does not exist.";
341next;
342goto L_GM;
343
344L_REMOVE:
345mes "[GM Menu]";
346mes "Please enter the donator's username:";
347input @donator$;
348set @aid, 0;
349query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
350if(!@aid) goto L_NONE;
351query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$;
352query_sql "SELECT '"+@donated$+"' > 0", @donated;
353mes "[GM Menu]";
354if(!@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        }
393close;
394
395L_VIEWALL:
396mes "[GM Menu]";
397query_sql "SELECT `account_id`,`amount` FROM `donate` ORDER BY `amount` DESC", @donatoraid, @donatedamount$;
398for(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}
404next;
405goto L_GM;
406
407L_RATE:
408mes "[GM Menu]";
409if($rate) mes "$1 is currently worth "+$rate+"Z.";
410mes "How much Zeny is $1 worth?";
411input $rate;
412mes "[GM Menu]";
413mes "The value of $1 successfully changed to "+$rate+"Z.";
414next;
415goto L_GM;
416}
Note: See TracBrowser for help on using the browser.