donate.txt 11 KB

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