· last year · Jan 27, 2024, 02:15 PM
1/*
2CREATE TABLE IF NOT EXISTS `ero_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
11prontera,155,175,5 script Item Collector::item_collector_npc 4_F_KAFRA9,{
12 doevent "trade_item_main::OnTalk";
13}
14
15
16- script trade_item_main -1,{
17
18 OnInit:
19 // Top Rank
20 .top_rank = 10;
21
22 // NPC take what item ID (empty = all items)
23 setarray .itemid, 512;
24
25 // list of not allowed items
26 setarray .blacklist_itemid, 501, 502, 4001;
27
28 .itemid_size = getarraysize(.itemid);
29 for (.@i = 0; .@i < .itemid_size; .@i++) {
30 .itemid$ = (.@i > 0 ? "," : "") + .itemid$ + .itemid[.@i];
31 .is_allow[.itemid[.@i]] = 1;
32 }
33 .allow_all_item = !.itemid_size;
34 .blacklist_itemid_size = getarraysize(.blacklist_itemid);
35 for (.@i = 0; .@i < .blacklist_itemid_size; .@i++)
36 .is_blacklist[.blacklist_itemid[.@i]] = 1;
37 end;
38
39 OnTalk:
40 .@is_gm = (getgmlevel() >= 99);
41
42 mes "^0055FF[ Item Collector ]^000000";
43 mes "Do you have any used items? You may give it to me.";
44 if (!.allow_all_item) {
45 for (.@i = 0; .@i < .itemid_size; .@i++)
46 mes "\n~ " + mesitemlink(.itemid[.@i], false);
47 }
48 mes " ";
49 mes "I'll always remember who giveaway his items to me.";
50 switch(select(
51 "View Top "+.top_rank+" Rank",
52 "Give Item to NPC",
53 (.@is_gm) ? "^FF0000[GM]^000000 Reset Ranking" : ""
54 )) {
55 default:
56 case 1:
57 do {
58 clear;
59 mes "[ View Top "+.top_rank+" Rank ]";
60 switch(select(
61 "Any",
62 "Filter by Character Name",
63 (.allow_all_item) ? "":"Filter by ItemID"
64 )) {
65 default:
66 break;
67 case 2:
68 .@filter_by = 1;
69 mes "Enter Character Name";
70 break;
71 case 3:
72 .@filter_by = 2;
73 mes "Enter ItemID";
74 break;
75 }
76
77 if (.@filter_by && .@filter_by != 3)
78 input .@input$;
79
80 .@sql$ = "SELECT `name`, `nameid`, SUM(`amount`) AS `total` "
81 + "FROM `ero_npc_trade_item` "
82 + "WHERE 1 = 1 "
83 + (.allow_all_item ? "" : "AND `nameid` IN ("+escape_sql(.itemid$)+") ")
84 + ((.@filter_by == 1) ? "AND `name` IN ("+escape_sql(.@input$)+") " : "")
85 + ((.@filter_by == 2) ? "AND `nameid` IN ("+escape_sql(.@input$)+") " : "")
86 + "GROUP BY `cid`, `nameid`, `name`"
87 + "ORDER BY `total` DESC LIMIT "+.top_rank;
88 query_sql(.@sql$, .@name$, .@nameid, .@total);
89 .@size = getarraysize(.@name$);
90
91 if (!.@size) {
92 mes "no record found.";
93 break;
94 }
95 for (.@i = 0; .@i < .@size; .@i++)
96 mes "["+(.@i+1)+".] "+mesitemlink(.@nameid[.@i], false, .@name$[.@i])+" ("+F_InsertComma(.@total[.@i])+")";
97 next;
98 } while (true);
99 break;
100 case 2:
101 clear;
102 mes "[ Give Item to NPC ]";
103 if (!.allow_all_item) {
104 mes "I accept the following items:";
105 for (.@i = 0; .@i < .itemid_size; .@i++)
106 mes "\n~ " + mesitemlink(.itemid[.@i], false);
107 }
108 getinventorylist;
109 for (.@i = 0; .@i < @inventorylist_count; .@i++) {
110 if (@inventorylist_bound[.@i] <= 0
111 && @inventorylist_expire[.@i] <= 0
112 && @inventorylist_equip[.@i] <= 0
113 && @inventorylist_tradable[.@i]
114 && .is_blacklist[@inventorylist_id[.@i]] == 0
115 && (.allow_all_item || .is_allow[@inventorylist_id[.@i]])
116 ) {
117 .@menu$ = .@menu$ + replacestr(getitemname(@inventorylist_id[.@i]), ":", " ") + " ("+F_InsertComma(@inventorylist_amount[.@i])+" left)";
118 .@count++;
119 }
120 .@menu$ = .@menu$ + ":";
121 }
122 if (.@count)
123 .@i = select(.@menu$) - 1;
124
125 if (!@inventorylist_id[.@i]) {
126 mes "Unfortunately, you dont have any item available to give to NPC.";
127 close;
128 }
129 clear;
130 mes "[ Give Item to NPC ]";
131 mes "How many "+mesitemlink(@inventorylist_id[.@i], false)+" will be given to me?";
132 mes "(You have "+F_InsertComma(@inventorylist_amount[.@i])+" left)";
133 input .@amount, 0, @inventorylist_amount[.@i];
134 clear;
135 mes "[ Give Item to NPC ]";
136 if (.@amount) {
137 delitemidx @inventorylist_idx[.@i], .@amount;
138 clear;
139 mes "[ Give Item to NPC ]";
140 mes "Thank you, you donated "+.@amount+"x "+mesitemlink(@inventorylist_id[.@i], false)+" to me.";
141 npctalk "<Item Collector> Thank you, '"+strcharinfo(0)+"' donated "+.@amount+"x "+itemlink(@inventorylist_id[.@i], @inventorylist_refine[.@i], @inventorylist_card1[.@i], @inventorylist_card2[.@i], @inventorylist_card3[.@i], @inventorylist_card4[.@i], @inventorylist_enchantgrade[.@i])+" to me.", "item_collector_npc";
142 query_sql("INSERT INTO `e_npc_trade_item` (`cid`,`name`,`nameid`,`amount`) VALUES ("+getcharid(0)+",'"+escape_sql(strcharinfo(0))+"',"+@inventorylist_id[.@i]+","+.@amount+") ON DUPLICATE KEY UPDATE `amount` = `amount` + "+.@amount);
143 }
144 mes "Thank for your kindness.";
145 break;
146 case 3:
147 clear;
148 mes "[ Reset Ranking ]";
149 mes "This action cant be undo, confirm your action?";
150 if (select("Yes, confirm.","Cancel") == 1) {
151 query_sql("TRUNCATE `e_npc_trade_item`");
152 clear;
153 mes "[ Reset Ranking ]";
154 mes "All record has been deleted.";
155 }
156 break;
157 }
158 close;
159}
160
161
162