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