donate.txt 12 KB

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