Advertisement
Sehrentos

eAthena npc script gift/rewarder for game masters

Apr 15th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.67 KB | None | 0 0
  1. //===== eAthena Script =======================================
  2. // Gift (npc)
  3. //===== By: ==================================================
  4. // Sehrentos
  5. //===== Current Version: =====================================
  6. // 2.6
  7. //===== Compatible With: =====================================
  8. // eAthena (SQL), rAthena (haven't tested yet)
  9. //===== Description: =========================================
  10. // Create single or multiple gift/s to a player or players.
  11. // - GM Panel.
  12. // - GM can select gift retrieve into account or character.
  13. // - multiple gifts.
  14. // - Players can choose to receive or remove gift.
  15. // - Players can select what gift to pickup fist (menu).
  16. // - Can set single gift to online players and offline.
  17. // - Can set single gift to online accounts and offline.
  18. // - Can set gifts to all players.
  19. // - Can set gifts to all accounts.
  20. // - Can set gifts to all online players only.
  21. // - Can set gifts to all online accounts only.
  22. // - Select GM level to use.
  23. // - Select SQL table for char.
  24. // - Select SQL table for this npc.
  25. //===== Installation: ========================================
  26. // 1. Go/find and Edit 'OnLoadSetup:' at the end of this file.
  27. // 2. Reload your server and see the changes.
  28. // Note: MySQL permissions for Create table needed or manual.
  29. //===== Additional Comments: =================================
  30. // You can freely use/edit this script. I hope you like it...
  31. //===== Updates: =============================================
  32. // 23-10-2011:
  33. // - Fixed weight check when receiving a gift.
  34. // 20-10-2011:
  35. // - Added Setup check to load configs again.
  36. // - Edited INSERT INTO.
  37. // - Edited table names.
  38. //============================================================
  39. geffen,116,110,5 script Gift 125,{
  40. //Check if setups are loaded.
  41. if(!.Setup) {
  42. callsub OnLoadSetup;
  43. }
  44.  
  45. //Show GM Panel if player is GM.
  46. if(getgmlevel() >= .GMin) menu("Open Normaly",-,"Open Management",OnManagement);
  47.  
  48. //Read attached player gifts from SQL table.
  49. if(select("My Account Gifts:My Character Gifts:Leave NPC") == 1) {
  50. set .@query, query_sql("SELECT * FROM `" + .GiftTableName$ + "` WHERE account_id="+getcharid(3), .@gift_id, .@gift_account, .@gift_char, .@gift_item, .@gift_amount); //Account gifts.
  51. } else if(@menu == 2) {
  52. set .@query, query_sql("SELECT * FROM `" + .GiftTableName$ + "` WHERE char_id="+getcharid(0), .@gift_id, .@gift_account, .@gift_char, .@gift_item, .@gift_amount); //Char gifts.
  53. } else goto OnLeave;
  54.  
  55. //Check if player don't have gifts.
  56. if(!.@query) {
  57. mes "[" + strnpcinfo(1) + "]";
  58. mes "Sorry, but you dont have any gifts today...";
  59. close;
  60. }
  61.  
  62. //Build menu from query arrays.
  63. mes "[" + strnpcinfo(1) + "]";
  64. mes "^009900A Gift is received!^000000";
  65. mes "Please select one from the menu.";
  66. for(set .@i, 0; .@i < .@query; set .@i, .@i + 1) {
  67. set .@text$, "(" + .@gift_amount[.@i] + ") " + getitemname(.@gift_item[.@i]);
  68. mes .@text$;
  69. set .@menu$, .@menu$ + .@text$ + ":";
  70. }
  71. next;
  72. set .@mid,select(.@menu$); //Show menu.
  73. set .@mid,.@mid-1;
  74.  
  75. //Item is now selected. Choose what you want to do with it.
  76. mes "[" + strnpcinfo(1) + "]";
  77. mes "What you like to do with (" + .@gift_amount[.@mid] + ") " + getitemname(.@gift_item[.@mid]) + "?";
  78. next;
  79. set .@Select,select("^009900Receive^000000:^ff0000Remove^000000:Nothing");
  80.  
  81. //Receive gift selected.
  82. if(.@Select == 1) {
  83. //Check weight.
  84. if(checkweight(.@gift_item[.@mid], .@gift_amount[.@mid])) {
  85. mes "[" + strnpcinfo(1) + "]";
  86. mes "^009900Received: (" + .@gift_amount[.@mid] + ") " + getitemname(.@gift_item[.@mid]) + ".^000000";
  87. getitem .@gift_item[.@mid], .@gift_amount[.@mid]; //Give item to player.
  88. query_sql( "DELETE FROM `" + .GiftTableName$ + "` WHERE id = " + .@gift_id[.@mid] ); //Remove item from table.
  89. close;
  90. } else {
  91. //Overweight
  92. mes "[" + strnpcinfo(1) + "]";
  93. mes "^ff0000Sorry^000000 you cannot hold this amount of " + getitemname(.@gift_item[.@mid]) + "(s)";
  94. mes "Can you lose some more weight first?";
  95. close;
  96. }
  97. }
  98.  
  99. //Remove gift selected.
  100. else if(.@Select == 2) {
  101. mes "[" + strnpcinfo(1) + "]";
  102. mes "Are you absolutely sure about ^ff0000Removing^000000?";
  103. mes "Gift: ("+.@gift_amount[.@mid]+") "+getitemname(.@gift_item[.@mid])+".";
  104. next;
  105. if(select("Yes:No") == 1) {
  106. mes "[" + strnpcinfo(1) + "]";
  107. mes "^ff0000Removed: ("+.@gift_amount[.@mid]+") "+getitemname(.@gift_item[.@mid])+".^000000";
  108. query_sql("DELETE FROM `" + .GiftTableName$ + "` WHERE id = " + .@gift_id[.@mid]); //Remove item from table.
  109. close;
  110. } else {
  111. mes "[" + strnpcinfo(1) + "]";
  112. mes "Lets keep the goods in a safe place for a while.";
  113. close;
  114. }
  115. }
  116.  
  117. //Nothing selected.
  118. else {
  119. goto OnLeave;
  120. }
  121.  
  122. //GM Panel below:
  123. OnManagement:
  124. if(getgmlevel() < .GMin) goto OnLeave;
  125. mes "[" + strnpcinfo(1) + "]";
  126. mes "Welcome master " + strcharinfo(0) + "!";
  127. mes "How can i help you today?";
  128. next;
  129. if(select("Make Gift:Nothing") != 1) goto OnLeave;
  130. //Make new gift.
  131. mes "[" + strnpcinfo(1) + "]";
  132. mes "Please input the item id.";
  133. mes "Default: 501";
  134. next;
  135. //item_id range of 501 to 30,000.
  136. input .@new_item, 501, 30000;
  137. if(select("Continue:Cancel") != 1) goto OnLeave;
  138. mes "[" + strnpcinfo(1) + "]";
  139. mes "How many items?";
  140. mes "Default: 1";
  141. next;
  142. //item quantity range of 1 to 1,000.
  143. input .@new_value, 1, 1000;
  144. if(select("Continue:Cancel") != 1) goto OnLeave;
  145. mes "[" + strnpcinfo(1) + "]";
  146. mes "Please select type:";
  147. mes "1. Single Account";
  148. mes "2. Single Character";
  149. mes "3. All ^009900Online^000000 Accounts.";
  150. mes "4. All Accounts.";
  151. mes "5. All ^009900Online^000000 Players/Characters.";
  152. mes "6. All Players/Characters.";
  153. mes "7. ^ff0000Cancel.^000000";
  154. next;
  155. switch(select("Single Account:Single Character:^009900Online^000000 Accounts:All Accounts:^009900Online^000000 Characters:All Characters:Cancel"))
  156. {
  157. //Account gift
  158. case 1:
  159. mes "[" + strnpcinfo(1) + "]";
  160. mes "Please select input type:";
  161. mes "By AID or Name?";
  162. next;
  163. if(select("Account ID:Character Name") == 1)
  164. {
  165. mes "[" + strnpcinfo(1) + "]";
  166. mes "Write account id:";
  167. next;
  168. input .@new_account, 2000000, 10000000; //Account id range from 2m to 10m.
  169. set .@Query, query_sql("SELECT account_id FROM `" + .CharTableName$ + "` WHERE account_id = " + .@new_account, .@new_account);
  170. if(!.@Query) goto OnNotExist;
  171. if(select("Continue:Cancel") != 1) goto OnLeave;
  172. mes "[" + strnpcinfo(1) + "]";
  173. mes "^009900Gift is ready to go!^000000";
  174. mes "AID: ^ff0000" + .@new_account + "^000000";
  175. mes "------------------";
  176. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  177. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  178. next;
  179. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  180. mes "[" + strnpcinfo(1) + "]";
  181. mes "Gift sending success!";
  182. //Create gift. <auto_id>, <account_id> <char_id> <item> <value>
  183. query_sql("INSERT INTO `" + .GiftTableName$ + "` (account_id, item, value) VALUES(" + .@new_account + ", " + .@new_item + ", " + .@new_value + ")");
  184.  
  185. }
  186. else
  187. {
  188. mes "[" + strnpcinfo(1) + "]";
  189. mes "Write player name:";
  190. next;
  191. input .@new_name$;
  192. set .@Query, query_sql("SELECT account_id FROM `" + .CharTableName$ + "` WHERE name = '" + .@new_name$ + "'", .@new_account);
  193. if(!.@Query) goto OnNotExist;
  194. if(select("Continue:Cancel") != 1) goto OnLeave;
  195. mes "[" + strnpcinfo(1) + "]";
  196. mes "^009900Gift is ready to go!^000000";
  197. mes "AID: ^ff0000" + .@new_account + "^000000";
  198. mes "Name: ^ff0000"+ .@new_name$ + "^000000";
  199. mes "------------------";
  200. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  201. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  202. next;
  203. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  204. //Check if player is logged in.
  205. if(isloggedin(.@new_account)) {
  206. mes "[" + strnpcinfo(1) + "]";
  207. message .@new_name$, "New reward has been received!";
  208. message .@new_name$, "Talk to " + strnpcinfo(1) + "(npc) in center of Geffen town to receive your rewards.";
  209. message .@new_name$, "Happy gaming!!";
  210. mes "Gift sending success!";
  211. query_sql("INSERT INTO `" + .GiftTableName$ + "` (account_id, item, value) VALUES (" + .@new_account + ", " + .@new_item + ", " + .@new_value + ")");
  212. } else {
  213. //Account was not online.
  214. mes "[" + strnpcinfo(1) + "]";
  215. mes "Gift sending success!";
  216. query_sql("INSERT INTO `" + .GiftTableName$ + "` (account_id, item, value) VALUES (" + .@new_account + ", " + .@new_item + ", " + .@new_value + ")");
  217. }
  218. }
  219. break;
  220.  
  221. //Character gift.
  222. case 2:
  223. mes "[" + strnpcinfo(1) + "]";
  224. mes "Please select input type:";
  225. mes "By CID or Name?";
  226. next;
  227. if(select("Character ID:Character Name") == 1)
  228. {
  229. mes "[" + strnpcinfo(1) + "]";
  230. mes "Write character id:";
  231. next;
  232. input .@new_char,150000, 10000000; //Char id range from 150k to 10m.
  233. set .@Query, query_sql("SELECT account_id, name FROM `" + .CharTableName$ + "` WHERE char_id = " + .@new_char, .@new_accountid, .@new_name$);
  234. if(!.@Query) goto OnNotExist;
  235. if(select("Continue:Cancel") != 1) goto OnLeave;
  236. mes "[" + strnpcinfo(1) + "]";
  237. mes "^009900Gift is ready to go!^000000";
  238. mes "CID: ^ff0000" + .@new_char + "^000000";
  239. mes "Name: ^ff0000" + .@new_name$ + "^000000";
  240. mes "------------------";
  241. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  242. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  243. next;
  244. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  245. //Check if player is logged in.
  246. if(isloggedin(.@new_accountid)) {
  247. mes "[" + strnpcinfo(1) + "]";
  248. mes "Gift sending success!";
  249. message .@new_name$, "New Gift is received! Talk to \"Gift\" npc in center of Geffen town to receive your gift. Happy gaming!!";
  250. //Create gift. <auto_id>, <account_id> <char_id> <item> <value>
  251. query_sql("INSERT INTO `" + .GiftTableName$ + "` (char_id, item, value) VALUES (" + .@new_char + ", " + .@new_item + ", " + .@new_value + ")");
  252. } else {
  253. //not online ask if we still give the gift.
  254. mes "[" + strnpcinfo(1) + "]";
  255. mes "The character is not online!";
  256. mes "Would you still like to send the gift?";
  257. next;
  258. if(select("Yes:No") != 1) goto OnLeave;
  259. mes "[" + strnpcinfo(1) + "]";
  260. mes "Gift sending success!";
  261. //Create gift. <auto_id>, <account_id> <char_id> <item> <value>
  262. query_sql("INSERT INTO `" + .GiftTableName$ + "` (char_id, item, value) VALUES (" + .@new_char + ", " + .@new_item + ", " + .@new_value + ")");
  263. }
  264.  
  265. }
  266. else
  267. {
  268. mes "[" + strnpcinfo(1) + "]";
  269. mes "Write player name:";
  270. next;
  271. input .@new_name$;
  272. set .@Query, query_sql("SELECT char_id, account_id FROM `" + .CharTableName$ + "` WHERE name = '" + .@new_name$ + "'", .@new_char, .@new_accountid);
  273. if(!.@Query) goto OnNotExist;
  274. if(select("Continue:Cancel") != 1) goto OnLeave;
  275. mes "[" + strnpcinfo(1) + "]";
  276. mes "^009900Gift is ready to go!^000000";
  277. mes "CID: ^ff0000" + .@new_char + "^000000";
  278. mes "Name: ^ff0000"+ .@new_name$ + "^000000";
  279. mes "------------------";
  280. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  281. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  282. next;
  283. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  284. //Check if player is logged in.
  285. if(isloggedin(.@new_accountid)) {
  286. mes "[" + strnpcinfo(1) + "]";
  287. message .@new_name$, "New reward has been received!";
  288. message .@new_name$, "Talk to " + strnpcinfo(1) + "(npc) in center of Geffen town to receive your rewards.";
  289. message .@new_name$, "Happy gaming!!";
  290. mes "Gift sending success!";
  291. query_sql("INSERT INTO `" + .GiftTableName$ + "` (char_id, item, value) VALUES (" + .@new_char + ", " + .@new_item + ", " + .@new_value + ")");
  292. } else {
  293. //not online ask if we still give the gift.
  294. mes "[" + strnpcinfo(1) + "]";
  295. mes "The character is not online!";
  296. mes "Would you still like to give the gift?";
  297. next;
  298. if(select("Yes:No") != 1) goto OnLeave;
  299. mes "[" + strnpcinfo(1) + "]";
  300. mes "Gift sending success!";
  301. //Create gift. <auto_id>, <account_id> <char_id> <item> <value>
  302. query_sql("INSERT INTO `" + .GiftTableName$ + "` (char_id, item, value) VALUES (" + .@new_char + ", " + .@new_item + ", " + .@new_value + ")");
  303. }
  304. }
  305. break;
  306.  
  307. //Register gift to all online accounts!
  308. case 3:
  309. mes "[" + strnpcinfo(1) + "]";
  310. mes "^009900Gift is ready to go!^000000";
  311. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  312. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  313. next;
  314. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  315. mes "[" + strnpcinfo(1) + "]";
  316. mes "Please hold...";
  317. set .@Query, query_sql("SELECT account_id FROM `" + .CharTableName$ + "` WHERE online=1",.@account);
  318. for(set .@i, 0; .@i < .@Query; set .@i, .@i + 1) {
  319. sleep2 10; //Slowdown the loop abit.
  320. query_sql("INSERT INTO " + .GiftTableName$ + " (account_id, item, value) VALUES (" + .@account[.@i] + ", " + .@new_item + ", " + .@new_value + ")");
  321. }
  322. mes "Gift registered to (" + .@i + ") accounts!";
  323. break;
  324.  
  325. //Register gift to all accounts!
  326. case 4:
  327. mes "[" + strnpcinfo(1) + "]";
  328. mes "^009900Gift is ready to go!^000000";
  329. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  330. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  331. next;
  332. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  333. mes "[" + strnpcinfo(1) + "]";
  334. mes "Please hold...";
  335. set .@Query, query_sql("SELECT account_id FROM `" + .CharTableName$ + "`",.@account);
  336. for(set .@i, 0; .@i < .@Query; set .@i, .@i + 1) {
  337. sleep2 10; //Slowdown the loop abit.
  338. query_sql("INSERT INTO `" + .GiftTableName$ + "` (account_id, item, value) VALUES (" + .@account[.@i] + ", " + .@new_item + ", " + .@new_value + ")");
  339. }
  340. mes "Gift registered to (" + .@i + ") accounts!";
  341. break;
  342.  
  343. //Register gift to all online characters!
  344. case 5:
  345. mes "[" + strnpcinfo(1) + "]";
  346. mes "^009900Gift is ready to go!^000000";
  347. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  348. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  349. next;
  350. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  351. mes "[" + strnpcinfo(1) + "]";
  352. mes "Please hold...";
  353. set .@Query, query_sql("SELECT char_id FROM `" + .CharTableName$ + "` WHERE online=1",.@char);
  354. for(set .@i, 0; .@i < .@Query; set .@i, .@i + 1) {
  355. sleep2 10; //Slowdown the loop abit.
  356. query_sql("INSERT INTO " + .GiftTableName$ + " (char_id, item, value) VALUES (" + .@char[.@i] + ", " + .@new_item + ", " + .@new_value + ")");
  357. }
  358. mes "Gift registered to (" + .@i + ") players!";
  359. break;
  360.  
  361. //Register gift to all characters!
  362. case 6:
  363. mes "[" + strnpcinfo(1) + "]";
  364. mes "^009900Gift is ready to go!^000000";
  365. mes "Item: ^ff0000" + getitemname(.@new_item) + "^000000";
  366. mes "Quantity: ^ff0000" + .@new_value + "^000000";
  367. next;
  368. if(select("Send Gift:Cancel") != 1) goto OnLeave;
  369. mes "[" + strnpcinfo(1) + "]";
  370. mes "Please hold...";
  371. set .@Query, query_sql("SELECT char_id FROM `" + .CharTableName$ + "`",.@char);
  372. for(set .@i, 0; .@i < .@Query; set .@i, .@i + 1) {
  373. sleep2 10; //Slowdown the loop abit.
  374. query_sql("INSERT INTO `" + .GiftTableName$ + "` (char_id, item, value) VALUES (" + .@char[.@i] + ", " + .@new_item + ", " + .@new_value + ")");
  375. }
  376. mes "Gift registered to (" + .@i + ") players!";
  377. break;
  378.  
  379. //Cancel.
  380. Default:
  381. mes "[" + strnpcinfo(1) + "]";
  382. mes "Have a good day sir!";
  383. break;
  384. }
  385. close;
  386.  
  387. OnLeave:
  388. mes "[" + strnpcinfo(1) + "]";
  389. mes "Have a good day!";
  390. close;
  391.  
  392. OnNotExist:
  393. mes "[" + strnpcinfo(1) + "]";
  394. mes "This player/account does not exist!";
  395. close;
  396.  
  397. //============================================================
  398. // Config/Edit:
  399. //============================================================
  400. OnLoadSetup:
  401. set .Setup, 1; //OnInit is loaded check.
  402. set .GMin, 60; //Minimum GM level to use gm panel.
  403. //Your table names:
  404. set .CharTableName$, "char"; //Char table name(SQL).
  405. set .GiftTableName$, "reward"; //Gift table name(SQL).
  406. //Create gift table <auto_id>, <account_id>, <char_id>, <item>, <value>
  407. query_sql("CREATE TABLE IF NOT EXISTS `" + .GiftTableName$ + "` (`id` INT(11) unsigned NOT NULL auto_increment, `account_id` INT(11) unsigned NOT NULL default 0, `char_id` INT(11) unsigned NOT NULL default 0, `item` SMALLINT unsigned NOT NULL default 0, `value` INT(11) unsigned NOT NULL default 0, PRIMARY KEY (`id`)) ENGINE=MyISAM");
  408. return;
  409.  
  410. //Server start/load event.
  411. OnInit:
  412. callsub OnLoadSetup;
  413. end;
  414. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement