donate.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 inputted 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. //= 3.4 - Added MySQL version check. If version < 5.0.8, all
  29. //= queries with CAST are omitted. Use 5.0.8 and up
  30. //= when possible. SQL errors may consequent if GM's
  31. //= input is incorrect. Added logging of claims.
  32. //= "log_npc" in log_athena.conf must be enabled. Logs
  33. //= will appear in the "npclog" table. Claim menu now
  34. //= only shows items that can be afforded.
  35. //= 3.5 - Minor change to table.
  36. //= 3.6 - Removed name column in donate_item_db. Added
  37. //= support for item_db2 table.
  38. //= 3.7 - Added Zeny support. $rate must be set for it to be
  39. //= used. Removed truncate() in a query since eAthena
  40. //= automatically truncates floats to ints.
  41. //= 3.8 - Fixed problem with menus and null values.
  42. //= 3.9 - Explicit reset of @aid.
  43. //= 3.10 - Applied previous fix to other variables and forced
  44. //= dialogue box closure every time database is
  45. //= modified.
  46. //= 3.11 - Explicit reset of another variable. Fixed typo
  47. //= - with $rate. Added logmes for GM operations.
  48. //===== Compatible With =====================================
  49. //= eAthena SQL - any version with the new query_sql command
  50. //= (Trunk 7975 and up).
  51. //= MySQL - 5.0.8 and up highly recommended but not required.
  52. //===== Description =========================================
  53. //= A script that lets a player claim an item for donating.
  54. //= Allows a GM to input each donation.
  55. //===== Comments ============================================
  56. //= This script uses SQL tables to store variables for the
  57. //= amount donated by users and the items claimable.
  58. //===== Installation ========================================
  59. //= You must import donate.sql and donate_item_db.sql (and
  60. //= item_db.sql and item_db2.sql, which comes with eAthena)
  61. //= before using this script.
  62. //===========================================================
  63. //= Thanks to Vich for helping me with the SQL syntax.
  64. //= Thanks to Lance for helping me with the the arrays and
  65. //= for implementing query_sql.
  66. //= Thanks to Skotlex for implementing escape_sql.
  67. //= Thanks to Toms for implementing the new multi-column
  68. //= query_sql command.
  69. //===========================================================
  70. prontera,145,179,5 script Donation Girl 714,{
  71. if (getgmlevel() >= 80) goto L_GM;
  72. L_START:
  73. mes "[Donation Girl]";
  74. mes "Hello! I'm the Donation Girl!";
  75. mes "If you have made a donation,";
  76. mes "you are entitled to a reward!";
  77. next;
  78. menu "More info",-,"Make a claim",L_CHECK,"Statistics",L_STATS;
  79. L_INFO:
  80. mes "[Donation Girl]";
  81. mes "Each month, a lot of money is paid to keep this server running.";
  82. next;
  83. mes "[Donation Girl]";
  84. mes "You can support us by donating any amount of money.";
  85. next;
  86. mes "[Donation Girl]";
  87. mes "To show our appreciation, we will gladly give you a reward.";
  88. next;
  89. menu "Continue",L_START,"Cancel",-;
  90. L_CHECK:
  91. query_sql "SELECT `amount`,`claimed` FROM `donate` WHERE `account_id` = "+getcharid(3), @amount$, @claimed$;
  92. query_sql "SELECT "+@amount$+" - "+@claimed$, @value$;
  93. query_sql "SELECT '"+@value$+"' > 0", @enough;
  94. if(!@enough) {
  95. mes "[Donation Girl]";
  96. mes "Sorry, you do not have enough to make a claim.";
  97. mes "If you have donated but have not made a claim,";
  98. mes "Please give us time to process your donation.";
  99. close;
  100. }
  101. L_CLAIM:
  102. mes "[Donation Girl]";
  103. mes "Thankyou for donating!";
  104. mes "You have $"+@value$+" worth of credit!";
  105. mes "What would you like to claim?";
  106. next;
  107. menu "Items",L_CLAIMITEM,"Zeny",L_ZENY;
  108. L_CLAIMITEM:
  109. mes "[Donation Girl]";
  110. mes "Very well. Which item would you like?";
  111. next;
  112. query_sql "SELECT `id` FROM `donate_item_db` WHERE `price` <= "+@value$+" ORDER BY `id`",@name;
  113. set @menu$, getitemname(@name[0]);
  114. for(set @i, 1; @i < getarraysize(@name); set @i, @i + 1){
  115. set @menu$, @menu$ + ":" + getitemname(@name[@i]);
  116. }
  117. set @m, select(@menu$)-1;
  118. query_sql "SELECT `price` FROM `donate_item_db` WHERE `id` = "+@name[@m], @price$;
  119. query_sql "SELECT "+@value$+" / "+@price$, @max;
  120. mes "[Donation Girl]";
  121. mes getitemname(@name[@m])+"s cost $"+@price$+" each.";
  122. mes "How many "+getitemname(@name[@m])+"s would you like to claim?";
  123. mes "Maximum: "+@max+".";
  124. input @quantity;
  125. mes "[Donation Girl]";
  126. if(@quantity>@max) {
  127. mes "Sorry, but you do not have enough to claim "+@quantity+" "+getitemname(@name[@m])+"s.";
  128. next;
  129. goto L_CLAIM;
  130. }
  131. if(!@quantity) {
  132. mes "You can't have 0 as an amount!";
  133. next;
  134. goto L_CLAIM;
  135. }
  136. if(!checkweight(@name[@m],@quantity)) {
  137. mes "I'm sorry, but you cannot carry "+@quantity+" "+getitemname(@name[@m])+"s.";
  138. next;
  139. goto L_CLAIM;
  140. }
  141. query_sql "SELECT "+@quantity+" * "+@price$, @total$;
  142. mes "Are you sure you want to claim "+@quantity+" "+getitemname(@name[@m])+"s for $"+@total$+"?";
  143. next;
  144. menu "No",L_CLAIM,"Yes",-;
  145. query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total$+" WHERE `account_id` = "+getcharid(3);
  146. logmes "Claimed "+@quantity+" "+getitemname(@name[@m])+"s";
  147. getitem @name[@m],@quantity;
  148. mes "[Donation Girl]";
  149. mes "Thankyou for donating! We hope you enjoy your gift!";
  150. close;
  151. L_ZENY:
  152. mes "[Donation Girl]";
  153. if(!$rate) {
  154. mes "Sorry, we currently do not allow claiming Zeny.";
  155. mes "Please go back and claim an item instead.";
  156. next;
  157. goto L_CLAIM;
  158. }
  159. query_sql "SELECT "+@value$+" * "+$rate, @maxzeny;
  160. mes "Very well. You can claim as much as "+@maxzeny+"Z.";
  161. mes "How much Zeny would you like to claim?";
  162. input @zeny;
  163. mes "[Donation Girl]";
  164. if(@zeny>@maxzeny) {
  165. mes "Sorry, but you do not have enough to claim "+@zeny+"Z.";
  166. next;
  167. goto L_CLAIM;
  168. }
  169. if(!@zeny) {
  170. mes "You can't have 0 as an amount!";
  171. next;
  172. goto L_CLAIM;
  173. }
  174. set @total, @zeny * $rate;
  175. mes "Are you sure you want to claim "+@zeny+"Z for $"+@total+"?";
  176. next;
  177. menu "No",L_CLAIM,"Yes",-;
  178. query_sql "UPDATE `donate` SET `claimed` = `claimed` + "+@total+" WHERE `account_id` = "+getcharid(3);
  179. logmes "Claimed "+@zeny+" zenies";
  180. set Zeny, Zeny + @zeny;
  181. mes "[Donation Girl]";
  182. mes "Thankyou for donating! We hope you enjoy your gift!";
  183. close;
  184. L_STATS:
  185. mes "[Donation Girl]";
  186. query_sql "SELECT IFNULL((SELECT SUM(amount) FROM `donate`),0)", @total$;
  187. mes "Our fund is at a total of $"+@total$;
  188. next;
  189. menu "More info",L_INFO,"Make a claim",L_CHECK,"Statistics",L_STATS;
  190. L_GM:
  191. mes "[GM Menu]";
  192. mes "Hello GM!";
  193. mes "What would you like to do?";
  194. next;
  195. query_sql "SHOW VARIABLES LIKE 'version'", @version, @valule$;
  196. query_sql "SELECT '"+@valule$+"' >= '5.0.8'", @version;
  197. menu "Add/Remove Donation",L_GM2,"Add/Remove Items",L_ITEM,"(Re)Set Exchange Rate",L_RATE,"Test Script",L_START;
  198. L_GM2:
  199. menu "Add a donation",L_DONATE,"Remove a donation",L_REMOVE,"View all donations",L_VIEWALL,"Return to main menu",L_GM;
  200. L_ITEM:
  201. menu "Add an item",L_NEWITEM,"Remove an item",L_DELITEM,"View all items",L_ALLITEMS,"Return to main menu",L_GM;
  202. L_NEWITEM:
  203. mes "[GM Menu]";
  204. mes "Please enter the item name:";
  205. input @itemname$;
  206. set @iid, 0;
  207. query_sql "SELECT `id` FROM `item_db` WHERE `name_english` = '"+escape_sql(@itemname$)+"' || `name_japanese` = '"+escape_sql(@itemname$)+"' UNION SELECT `id` FROM `item_db2` WHERE `name_english` = '"+escape_sql(@itemname$)+"' || `name_japanese` = '"+escape_sql(@itemname$)+"'", @iid;
  208. if(!@iid) goto L_INONE;
  209. query_sql "SELECT 1 FROM `donate_item_db` WHERE `id` = "+@iid, @check;
  210. mes "[GM Menu]";
  211. mes "Please enter the cost of each "+@itemname$+":";
  212. input @cost$;
  213. if(@version) query_sql "SELECT CAST('"+escape_sql(@cost$)+"' AS DECIMAL)", @cost$;
  214. query_sql "SELECT '"+escape_sql(@cost$)+"' > 0", @valid;
  215. if(!@valid) goto L_ZERO;
  216. mes "[GM Menu]";
  217. mes "You have specified that donators can claim "+@itemname$+"s for $"+@cost$+" each.";
  218. mes "Would you like to continue?";
  219. next;
  220. menu "No",L_ITEM,"Yes",-;
  221. mes "[GM Menu]";
  222. if(!@check){
  223. query_sql "INSERT INTO `donate_item_db` VALUES ("+@iid+",'"+@cost$+"')";
  224. logmes "Added "+@itemname$+"s to list of claimable items";
  225. mes "Item added successfully!";
  226. } else {
  227. mes "Item "+@itemname$+" already exists in the database.";
  228. mes "Would you like to replace it?";
  229. next;
  230. menu "No",L_ITEM,"Yes",-;
  231. query_sql "REPLACE INTO `donate_item_db` VALUES ("+@iid+",'"+@cost$+"')";
  232. logmes "Changed the price of "+@itemname$+"s";
  233. mes "[GM Menu]";
  234. mes "Item replaced successfully!";
  235. }
  236. close;
  237. L_INONE:
  238. mes "[GM Menu]";
  239. mes "Item "+@itemname$+" does not exist.";
  240. next;
  241. goto L_ITEM;
  242. L_DELITEM:
  243. mes "[GM Menu]";
  244. mes "Please enter the item name:";
  245. input @itemname$;
  246. set @iid, 0;
  247. query_sql "SELECT `donate_item_db`.`id` FROM `donate_item_db` LEFT JOIN `item_db` ON `donate_item_db`.`id` = `item_db`.`id` LEFT JOIN `item_db2` ON `donate_item_db`.`id` = `item_db2`.`id` WHERE `item_db`.`name_english` = '"+escape_sql(@itemname$)+"' || `item_db`.`name_japanese` = '"+escape_sql(@itemname$)+"' || `item_db2`.`name_english` = '"+escape_sql(@itemname$)+"' || `item_db2`.`name_japanese` = '"+escape_sql(@itemname$)+"'", @iid;
  248. if(!@iid) goto L_INONE;
  249. next;
  250. mes "[GM Menu]";
  251. mes "You have specified to delete "+@itemname$+" from the database.";
  252. mes "Would you like to continue?";
  253. next;
  254. menu "No",L_ITEM,"Yes",-;
  255. query_sql "DELETE FROM `donate_item_db` WHERE `id` = "+@iid;
  256. logmes "Deleted "+@itemname$+"s from list of claimable items";
  257. mes "[GM Menu]";
  258. mes "Item deleted successfully!";
  259. close;
  260. L_ALLITEMS:
  261. mes "[GM Menu]";
  262. query_sql "SELECT `id`,`price` FROM `donate_item_db` ORDER BY `id`", @items, @itemamount$;
  263. for(set @i, 0; @i < getarraysize(@items); set @i, @i + 1){
  264. mes getitemname(@items[@i])+" - $"+@itemamount$[@i];
  265. }
  266. next;
  267. goto L_GM;
  268. L_DONATE:
  269. mes "[GM Menu]";
  270. mes "Please enter the donator's username:";
  271. input @donator$;
  272. set @aid, 0;
  273. query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
  274. if(!@aid) goto L_NONE;
  275. set @donated$, "";
  276. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$;
  277. query_sql "SELECT '"+@donated$+"' > 0", @donated;
  278. switch(@donated) {
  279. case 0:
  280. mes @donator$+" has not donated before.";
  281. break;
  282. case 1:
  283. mes @donator$+" has donated $"+@donated$+".";
  284. break;
  285. }
  286. next;
  287. mes "[GM Menu]";
  288. mes "Please enter the amount donated by "+@donator$;
  289. input @donating$;
  290. if(@version) query_sql "SELECT CAST('"+escape_sql(@donating$)+"' AS DECIMAL)", @donating$;
  291. query_sql "SELECT '"+escape_sql(@donating$)+"' > 0", @valid;
  292. if(!@valid) goto L_ZERO;
  293. mes "[GM Menu]";
  294. mes "You have specified that "+@donator$+" has donated $"+@donating$+".";
  295. mes "Would you like to continue?";
  296. next;
  297. menu "No",L_GM,"Yes",-;
  298. switch(@donated) {
  299. case 0:
  300. query_sql "INSERT INTO `donate` VALUES ("+@aid+", '"+@donating$+"', 0)";
  301. break;
  302. case 1:
  303. query_sql "UPDATE `donate` SET `amount` = `amount` + "+@donating$+" WHERE `account_id` = "+@aid;
  304. break;
  305. }
  306. logmes "Credited "+@donator$+" with $"+@donating$;
  307. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @newdonated$;
  308. mes "[GM Menu]";
  309. mes "Donation added successfully!";
  310. mes @donator$+" has donated a total of $"+@newdonated$;
  311. close;
  312. L_ZERO:
  313. mes "[GM Menu]";
  314. mes "You can't have 0 as an amount!";
  315. next;
  316. goto L_GM;
  317. L_NONE:
  318. mes "[GM Menu]";
  319. mes "Account name "+@donator$+" does not exist.";
  320. next;
  321. goto L_GM;
  322. L_REMOVE:
  323. mes "[GM Menu]";
  324. mes "Please enter the donator's username:";
  325. input @donator$;
  326. set @aid, 0;
  327. query_sql "SELECT `account_id` FROM `login` WHERE `userid` = '"+escape_sql(@donator$)+"'", @aid;
  328. if(!@aid) goto L_NONE;
  329. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @donated$;
  330. query_sql "SELECT '"+@donated$+"' > 0", @donated;
  331. mes "[GM Menu]";
  332. if(!@donated) {
  333. query_sql "DELETE FROM `donate` WHERE `account_id` = "+@aid;
  334. logmes "Deleted "+@donator$+" from donation database";
  335. mes @donator$+" is not a donator and has been deleted from the donation database.";
  336. } else {
  337. mes @donator$+" has donated $"+@donated$+".";
  338. next;
  339. switch(select("Deduct an amount from "+@donator$,"Remove "+@donator$+" from the donation database")){
  340. mes "[GM Menu]";
  341. case 1:
  342. mes "Please enter the amount "+@donator$+" is to be deducted by:";
  343. input @deduct$;
  344. if(@version) query_sql "SELECT CAST('"+escape_sql(@deduct$)+"' AS DECIMAL)", @deduct$;
  345. query_sql "SELECT '"+escape_sql(@deduct$)+"' > 0", @valid;
  346. if(!@valid) goto L_ZERO;
  347. mes "[GM Menu]";
  348. mes "You have specified that "+@donator$+" is to be deducted by $"+@deduct$+".";
  349. mes "Would you like to continue?";
  350. next;
  351. menu "No",L_GM,"Yes",-;
  352. query_sql "UPDATE `donate` SET `amount` = `amount` - "+@deduct$+" WHERE `account_id` = "+@aid;
  353. query_sql "SELECT `amount` FROM `donate` WHERE `account_id` = "+@aid, @afterdeduct$;
  354. logmes "Deducted "+@deduct$+" from "+@donator$;
  355. mes "[GM Menu]";
  356. mes "Donation deducted successfully!";
  357. mes @donator$+" has donated a total of $"+@afterdeduct$;
  358. break;
  359. case 2:
  360. mes "You have specified to remove "+@donator$+" from the donation database.";
  361. mes "Would you like to continue?";
  362. next;
  363. menu "No",L_GM,"Yes",-;
  364. query_sql "DELETE FROM `donate` WHERE `account_id` = "+@aid;
  365. logmes "Deleted "+@donator$+" from donation database";
  366. mes "[GM Menu]";
  367. mes "Donator deleted successfully!";
  368. break;
  369. }
  370. }
  371. close;
  372. L_VIEWALL:
  373. mes "[GM Menu]";
  374. query_sql "SELECT `account_id`,`amount` FROM `donate` ORDER BY `amount` DESC", @donatoraid, @donatedamount$;
  375. for(set @i, 0; @i < getarraysize(@donatoraid); set @i, @i + 1){
  376. query_sql "SELECT `userid` FROM `login` WHERE `account_id` = "+@donatoraid[@i], @donateruserid$;
  377. for(set @j, 0; @j < getarraysize(@donateruserid$); set @j, @j + 1){
  378. mes @donateruserid$[@j]+" - "+@donatedamount$[@i];
  379. }
  380. }
  381. next;
  382. goto L_GM;
  383. L_RATE:
  384. mes "[GM Menu]";
  385. if($rate) mes "$1 is currently worth "+$rate+"Z.";
  386. mes "How much Zeny is $1 worth?";
  387. input $rate;
  388. mes "[GM Menu]";
  389. mes "The value of $1 successfully changed to "+$rate+"Z.";
  390. next;
  391. goto L_GM;
  392. }