donate.txt 12 KB

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