donate.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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 inputed 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. //===== Compatible With =====================================
  29. //= eAthena - any version that contains the new query_sql
  30. //= command (Trunk 7975).
  31. //===== Description =========================================
  32. //= A script that lets a player claim an item for donating.
  33. //= Allows a GM to input each donation.
  34. //===== Comments ============================================
  35. //= This script uses SQL tables to store variables for the
  36. //= amount donated by users and the items claimable.
  37. //===== Installation ========================================
  38. //= You must execute donate.sql and donate_item_db.sql before
  39. //= using this script.
  40. //===========================================================
  41. //= Thanks to Vich for helping me with the SQL syntax.
  42. //= Thanks to Lance for helping me with the the arrays and
  43. //= for implementing query_sql.
  44. //= Thanks to Skotlex for implementing escape_sql.
  45. //= Thanks to Toms for implementing the new multi-column
  46. //= query_sql command.
  47. //===========================================================
  48. prontera.gat,145,179,5 script Donation Girl 714,{
  49. if (getgmlevel() >= 80) goto L_GM;
  50. L_START:
  51. mes "[Donation Girl]";
  52. mes "Hello! I'm the Donation Girl!";
  53. mes "If you have made a donation,";
  54. mes "you are entitled to a reward!";
  55. next;
  56. menu "More info",-,"Make a claim",L_CHECK,"Statistics",L_STATS;
  57. L_INFO:
  58. mes "[Donation Girl]";
  59. mes "Each month, a lot of money is paid to keep this server running.";
  60. next;
  61. mes "[Donation Girl]";
  62. mes "You can support us by donating any amount of money.";
  63. next;
  64. mes "[Donation Girl]";
  65. mes "To show our appreciation, we will gladly give you a reward.";
  66. next;
  67. menu "Continue",L_START,"Cancel",-;
  68. close;
  69. L_CHECK:
  70. query_sql "SELECT `amount`,`claimed` FROM `donate` WHERE `account_id` = "+getcharid(3)+"", @amount$, @claimed$;
  71. query_sql "SELECT MIN(price) FROM `donate_item_db`", @min$;
  72. query_sql "SELECT '"+@amount$+"' - '"+@claimed$+"'", @value$;
  73. query_sql "SELECT '"+@value$+"' >= '"+@min$+"'", @enough;
  74. if(@enough) goto L_CLAIM;
  75. mes "[Donation Girl]";
  76. mes "Sorry, you do not have enough to make a claim.";
  77. mes "If you have donated but have not made a claim,";
  78. mes "Please give us time to process your donation.";
  79. close;
  80. L_CLAIM:
  81. mes "[Donation Girl]";
  82. mes "Thankyou for donating!";
  83. mes "You have $"+@value$+" worth of credit!";
  84. mes "Would you like to claim an item now?";
  85. next;
  86. menu "No",-,"Yes",L_YES;
  87. mes "[Donation Girl]";
  88. mes "Ok! You are able to collect your item(s) any time!";
  89. close;
  90. L_YES:
  91. mes "[Donation Girl]";
  92. mes "Very well. Which item would you like?";
  93. next;
  94. query_sql "SELECT `name` FROM `donate_item_db` ORDER BY `name` ASC",$@name$;
  95. set $@menu$, $@name$[0];
  96. for(set $@i, 1; $@i < 127; set $@i, $@i + 1){
  97. set $@menu$, $@menu$ + ":" + $@name$[$@i];
  98. }
  99. set @menu, (select($@menu$))-1;
  100. query_sql "SELECT `id`,`price` FROM `donate_item_db` WHERE `name` = '"+$@name$[@menu]+"'", @id, @price$;
  101. query_sql "SELECT TRUNCATE("+@value$+" / "+@price$+",0)", @max;
  102. mes "[Donation Girl]";
  103. mes ""+$@name$[@menu]+"s cost $"+@price$+" each.";
  104. mes "How many "+$@name$[@menu]+"s would you like to claim?";
  105. mes "Maximum: "+@max+".";
  106. input @quantity;
  107. if(@quantity>@max) {
  108. mes "[Donation Girl]";
  109. mes "Sorry, but you do not have enough to claim "+@quantity+" "+$@name$[@menu]+"s.";
  110. next;
  111. goto L_CLAIM;
  112. }
  113. if(!@quantity) {
  114. mes "[Donation Girl]";
  115. mes "You can't have 0 as an amount!";
  116. next;
  117. goto L_CLAIM;
  118. }
  119. if (checkweight(@id,@quantity) == 0) {
  120. mes "[Donation Girl]";
  121. mes "I'm sorry, but you cannot carry "+@quantity+" "+$@name$[@menu]+"s.";
  122. next;
  123. goto L_CLAIM;
  124. }
  125. query_sql "SELECT "+@quantity+" * "+@price$+"", @total$;
  126. mes "Are you sure you want to claim "+@quantity+" "+$@name$[@menu]+"s for $"+@total$+"?";
  127. next;
  128. menu "No",L_CLAIM,"Yes",-;
  129. query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total$+" WHERE `account_id` = '"+getcharid(3)+"'";
  130. getitem @id,@quantity;
  131. mes "[Donation Girl]";
  132. mes "Thankyou for donating! We hope you enjoy your gift!";
  133. close;
  134. L_STATS:
  135. mes "[Donation Girl]";
  136. query_sql "SELECT IFNULL((SELECT SUM(amount) FROM `donate`),0)", @total$;
  137. mes "Our fund is at a total of $"+@total$+"";
  138. next;
  139. menu "More info",L_INFO,"Make a claim",L_CHECK,"Statistics",L_STATS;
  140. close;
  141. L_GM:
  142. mes "[GM Menu]";
  143. mes "Hello GM!";
  144. mes "What would you like to do?";
  145. next;
  146. menu "Add/Remove Donation",L_GM2,"Add/Remove Items",L_ITEM,"Test Script",L_START;
  147. close;
  148. L_GM2:
  149. menu "Add a donation",L_DONATE,"Remove a donation",L_REMOVE,"View all donations",L_VIEWALL;
  150. close;
  151. L_ITEM:
  152. menu "Add an item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS,"Return to main menu",L_GM;
  153. close;
  154. L_NEWITEM:
  155. mes "[GM Menu]";
  156. mes "Please enter the item name:";
  157. input @itemname$;
  158. query_sql "SELECT `id` FROM `item_db` WHERE `name_english` = '"+escape_sql(@itemname$)+"'", @iid;
  159. query_sql "SELECT `id` FROM `donate_item_db` WHERE `name` = '"+escape_sql(@itemname$)+"'", @check;
  160. if(@iid==0) goto L_INONE;
  161. mes "[GM Menu]";
  162. mes "Please enter the cost of each "+@itemname$+":";
  163. input @cost$;
  164. query_sql "SELECT "+escape_sql(@cost$)+" = 0", @invalid;
  165. if(@invalid) goto L_ZERO;
  166. query_sql "SELECT CAST('"+escape_sql(@cost$)+"' AS DECIMAL)", @cost$;
  167. mes "[GM Menu]";
  168. mes "You have specified that donators can claim "+@itemname$+"s for $"+@cost$+" each.";
  169. mes "Would you like to continue?";
  170. next;
  171. menu "No",L_ITEM,"Yes",-;
  172. if(@check!=0) goto L_REPLACE;
  173. query_sql "INSERT INTO `donate_item_db` VALUES ('"+@iid+"', '"+escape_sql(@itemname$)+"', '"+@cost$+"')";
  174. mes "[GM Menu]";
  175. mes "Item added successfully!";
  176. next;
  177. menu "Add annother item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS;
  178. close;
  179. L_REPLACE:
  180. mes "[GM Menu]";
  181. mes "Item "+@itemname$+" already exists in the database.";
  182. mes "Would you like to replace it?";
  183. next;
  184. menu "No",L_ITEM,"Yes",-;
  185. query_sql "REPLACE INTO `donate_item_db` VALUES ('"+@iid+"', '"+@itemname$+"', '"+@cost$+"')";
  186. mes "[GM Menu]";
  187. mes "Item replaced successfully!";
  188. next;
  189. menu "Add annother item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS;
  190. close;
  191. L_INONE:
  192. mes "[GM Menu]";
  193. mes "Item "+@itemname$+" does not exist.";
  194. next;
  195. goto L_ITEM;
  196. L_DELITEM:
  197. mes "[GM Menu]";
  198. mes "Please enter the item name:";
  199. input @itemname$;
  200. query_sql "SELECT `id` FROM `donate_item_db` WHERE `name` = '"+escape_sql(@itemname$)+"'", @iid;
  201. if(@iid==0) goto L_INONE;
  202. next;
  203. mes "[GM Menu]";
  204. mes "You have specified to delete "+@itemname$+" from the database.";
  205. mes "Would you like to continue?";
  206. next;
  207. menu "No",L_ITEM,"Yes",-;
  208. query_sql "DELETE FROM `donate_item_db` WHERE `id` = '"+@iid+"'";
  209. mes "[GM Menu]";
  210. mes "Item deleted successfully!";
  211. next;
  212. menu "Add an item",L_NEWITEM,"Remove another item",L_DELITEM,"View all items",L_ALLITEMS;
  213. close;
  214. L_ALLITEMS:
  215. mes "[GM Menu]";
  216. query_sql "SELECT `name`,`price` FROM `donate_item_db` ORDER BY `name` ASC", @items$, @itemamount$;
  217. for(set @i, 0; @i < getarraysize(@items$); set @i, @i + 1){
  218. mes ""+@items$[@i]+" - $"+@itemamount$[@i]+"";
  219. }
  220. next;
  221. goto L_GM;
  222. L_DONATE:
  223. mes "[GM Menu]";
  224. mes "Please enter the donator's username:";
  225. input @donator$;
  226. query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
  227. if(@aid==0) goto L_NONE;
  228. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid+"", @donated$;
  229. query_sql "SELECT '"+@donated$+"' > 0", @donated;
  230. switch(@donated) {
  231. case 0:
  232. mes ""+@donator$+" has not donated before.";
  233. break;
  234. case 1:
  235. mes ""+@donator$+" has donated $"+@donated$+".";
  236. break;
  237. }
  238. next;
  239. mes "[GM Menu]";
  240. mes "Please enter the amount donated by "+@donator$+"";
  241. input @donating$;
  242. query_sql "SELECT "+escape_sql(@donating$)+" = 0", @invalid;
  243. if(@invalid) goto L_ZERO;
  244. query_sql "SELECT CAST('"+escape_sql(@donating$)+"' AS DECIMAL)", @donating$;
  245. mes "[GM Menu]";
  246. mes "You have specified that "+@donator$+" has donated $"+@donating$+".";
  247. mes "Would you like to continue?";
  248. next;
  249. menu "No",L_GM,"Yes",-;
  250. switch(@donated) {
  251. case 0:
  252. query_sql "INSERT INTO `donate` VALUES ('"+@aid+"', '"+@donating$+"', '0')";
  253. break;
  254. case 1:
  255. query_sql "UPDATE `donate` SET `amount` = `amount` + "+@donating$+" WHERE `account_id` = '"+@aid+"'";
  256. break;
  257. }
  258. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid+"", @newdonated$;
  259. mes "[GM Menu]";
  260. mes "Donation added successfully!";
  261. mes ""+@donator$+" has donated a total of $"+@newdonated$+"";
  262. next;
  263. goto L_GM;
  264. L_ZERO:
  265. mes "[GM Menu]";
  266. mes "You can't have 0 as an amount!";
  267. next;
  268. goto L_GM;
  269. L_NONE:
  270. mes "[GM Menu]";
  271. mes "Account name "+@donator$+" does not exist.";
  272. next;
  273. goto L_GM;
  274. L_REMOVE:
  275. mes "[GM Menu]";
  276. mes "Please enter the donator's username:";
  277. input @donator$;
  278. query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
  279. if(@aid==0) goto L_NONE;
  280. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid+"", @donated$;
  281. query_sql "SELECT '"+@donated$+"' > 0", @donated;
  282. if(@donated==0) {
  283. query_sql "DELETE FROM `donate` WHERE `account_id` = '"+@aid+"'";
  284. mes ""+@donator$+" is not a donator and has been deleted from the donation database.";
  285. goto L_GM;
  286. }
  287. mes ""+@donator$+" has donated $"+@donated$+".";
  288. next;
  289. menu "Deduct an amount from "+@donator$+"",L_MINUS,"Remove "+@donator$+" from the donation database",L_DELETE;
  290. close;
  291. L_MINUS:
  292. mes "[GM Menu]";
  293. mes "Please enter the amount "+@donator$+" is to be deducted by:";
  294. input @deduct$;
  295. query_sql "SELECT "+escape_sql(@deduct$)+" = 0", @invalid;
  296. if(@invalid) goto L_ZERO;
  297. query_sql "SELECT CAST('"+escape_sql(@deduct$)+"' AS DECIMAL)", @deduct$;
  298. mes "[GM Menu]";
  299. mes "You have specified that "+@donator$+" is to be deducted by $"+@deduct$+".";
  300. mes "Would you like to continue?";
  301. next;
  302. menu "No",L_GM,"Yes",-;
  303. query_sql "UPDATE `donate` SET `amount` = `amount` - "+@deduct$+" WHERE `account_id` = '"+@aid+"'";
  304. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid+"", @afterdeduct$;
  305. mes "[GM Menu]";
  306. mes "Donation deducted successfully!";
  307. mes ""+@donator$+" has donated a total of $"+@afterdeduct$+"";
  308. next;
  309. goto L_GM;
  310. L_DELETE:
  311. mes "[GM Menu]";
  312. mes "You have specified to remove "+@donator$+" from the donation database.";
  313. mes "Would you like to continue?";
  314. next;
  315. menu "No",L_GM,"Yes",-;
  316. query_sql "DELETE FROM `donate` WHERE `account_id` = '"+@aid+"'";
  317. mes "[GM Menu]";
  318. mes "Donator deleted successfully!";
  319. next;
  320. goto L_GM;
  321. L_VIEWALL:
  322. mes "[GM Menu]";
  323. query_sql "SELECT `account_id`,`amount` FROM `donate` ORDER BY `amount` DESC", @donatoraid, @donatedamount$;
  324. for(set @i, 0; @i < getarraysize(@donatoraid); set @i, @i + 1){
  325. query_sql "SELECT `userid` FROM `login` WHERE `account_id` = '"+@donatoraid[@i]+"'", @donateruserid$;
  326. for(set @j, 0; @j < getarraysize(@donateruserid$); set @j, @j + 1){
  327. mes ""+@donateruserid$[@j]+" - "+@donatedamount$[@i]+"";
  328. }
  329. }
  330. next;
  331. goto L_GM;
  332. }