donate.txt 15 KB

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