Advertisement
Emistry

[RO] Item Collector with Rank 1.3

Aug 30th, 2016
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. /*
  2. CREATE TABLE IF NOT EXISTS `e_npc_trade_item` (
  3. `cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  4. `name` VARCHAR(30) NOT NULL DEFAULT '',
  5. `nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  6. `amount` INT(11) UNSIGNED NOT NULL DEFAULT '0',
  7. PRIMARY KEY (`cid`,`nameid`,`amount`)
  8. ) ENGINE=MyISAM;
  9. */
  10.  
  11. prontera,155,175,5 script Item Collector 4_F_KAFRA9,{
  12. doevent "trade_item_main::OnTalk";
  13. }
  14.  
  15.  
  16. - script trade_item_main -1,{
  17. function func_DisallowItem {
  18. switch ( getarg( 0,0 ) ) {
  19. default:
  20. return 0;
  21. // case <itemID>:
  22. case 501: // Red Potion
  23. case 502: // Orange Potion
  24. case 4001: // Poring Card
  25. return 1;
  26. }
  27. return 0;
  28. }
  29.  
  30. OnInit:
  31. // Top Rank
  32. .top_rank = 10;
  33.  
  34. // NPC take what item ID, 0 = all items.
  35. .only_one_itemid = 512;
  36. end;
  37.  
  38. OnTalk:
  39. .@is_gm = ( getgmlevel() >= 99 );
  40.  
  41. mes "^0055FF[ Item Collector ]^000000";
  42. mes "Do you have any used items? You may give it to me.";
  43. mes " ";
  44. mes "I'll always remember who giveaway his items to me.";
  45. next;
  46. switch( select(
  47. "View Top "+.top_rank+" Rank",
  48. "Give Item to NPC",
  49. ( .@is_gm ) ? "[GM] Reset" : ""
  50. )) {
  51. default:
  52. do {
  53.  
  54. switch( select(
  55. "Filter by Name",
  56. ( .only_one_itemid ) ? "":"Filter by ItemID",
  57. "Without Filter"
  58. ) ) {
  59. case 1: mes "Enter Char Name"; break;
  60. case 2: mes "Enter ItemID"; break;
  61. default: break;
  62. }
  63.  
  64. if ( @menu && @menu < 3 ) {
  65. next;
  66. input .@input$;
  67. }
  68.  
  69. .@sql$ = "SELECT `name`, `nameid`, SUM(`amount`) AS `total` "
  70. + "FROM `e_npc_trade_item` "
  71. + "WHERE 1 = 1 "
  72. + ( .only_one_itemid ? "AND `nameid` = "+.only_one_itemid+" " : "" )
  73. + ( ( @menu == 1 ) ? "AND `name` = '"+escape_sql( .@input$ )+"' " : "" )
  74. + ( ( @menu == 2 ) ? "AND `nameid` = '"+escape_sql( .@input$ )+"' " : "" )
  75. + "GROUP BY `cid`,`nameid` "
  76. + "ORDER BY `total` DESC LIMIT "+.top_rank;
  77. query_sql( .@sql$,.@name$,.@nameid,.@total );
  78. .@size = getarraysize( .@name$ );
  79.  
  80. mes "Top "+.top_rank+" Records:";
  81. if ( .@size ) {
  82. for ( .@i = 0; .@i < .@size; .@i++ ) {
  83. mes "["+(.@i+1)+".] '"+getitemname( .@nameid[.@i] )+"' ("+.@total[.@i]+"ea) - '"+.@name$[.@i]+"' ";
  84. }
  85. }
  86. else {
  87. mes "no record found.";
  88. }
  89. next;
  90. } while ( 1 );
  91. break;
  92. case 2:
  93. if ( !.only_one_itemid ) {
  94. mes "Pick an item and give to me";
  95. getinventorylist;
  96. for ( .@i = 0; .@i < @inventorylist_count; .@i++ ) {
  97. if ( @inventorylist_bound[.@i] <= 0
  98. && @inventorylist_expire[.@i] <= 0
  99. && @inventorylist_equip[.@i] <= 0
  100. && func_DisallowItem( @inventorylist_id[.@i] ) <= 0
  101. ) {
  102. .@menu$ = .@menu$ + getitemname( @inventorylist_id[.@i] ) + " ("+@inventorylist_amount[.@i]+" left)";
  103. .@count++;
  104. }
  105. .@menu$ = .@menu$ + ":";
  106. }
  107. if ( .@count ) {
  108. .@i = select( .@menu$ ) - 1;
  109. .@itemid = @inventorylist_id[.@i];
  110. }
  111. }
  112. else {
  113. .@itemid = .only_one_itemid;
  114. .@count++;
  115. }
  116. if ( .@itemid ) {
  117. mes "How many "+getitemname( .@itemid )+" will be given to me?";
  118. input .@amount,0,countitem( .@itemid );
  119. if ( .@amount ) {
  120. delitem .@itemid,.@amount;
  121. npctalk "Thank you, "+strcharinfo(0)+" donated "+.@amount+"x "+getitemname( .@itemid )+" to me.";
  122. query_sql( "INSERT INTO `e_npc_trade_item` ( `cid`,`name`,`nameid`,`amount` ) VALUES ( "+getcharid(0)+",'"+escape_sql( strcharinfo(0) )+"',"+.@itemid+","+.@amount+" ) ON DUPLICATE KEY UPDATE `amount` = `amount` + "+.@amount );
  123. mes "Thank for your kindness.";
  124. }
  125. }
  126. else {
  127. mes "You dont have any item available to give to NPC.";
  128. }
  129. break;
  130. case 3:
  131. mes "This action cant be undo, confirm your action?";
  132. next;
  133. if ( select( "Yes, confirm.","Cancel" ) == 1 ) {
  134. query_sql( "TRUNCATE `e_npc_trade_item`" );
  135. }
  136. break;
  137. }
  138. close;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement