/*
CREATE TABLE IF NOT EXISTS `e_npc_trade_item` (
`cid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`name` VARCHAR(30) NOT NULL DEFAULT '',
`nameid` INT(11) UNSIGNED NOT NULL DEFAULT '0',
`amount` INT(11) UNSIGNED NOT NULL DEFAULT '0',
PRIMARY KEY (`cid`,`nameid`,`amount`)
) ENGINE=MyISAM;
*/
prontera,155,175,5 script Item Collector 4_F_KAFRA9,{
doevent "trade_item_main::OnTalk";
}
- script trade_item_main -1,{
function func_DisallowItem {
switch ( getarg( 0,0 ) ) {
default:
return 0;
// case <itemID>:
case 501: // Red Potion
case 502: // Orange Potion
case 4001: // Poring Card
return 1;
}
return 0;
}
OnInit:
// Top Rank
.top_rank = 10;
// NPC take what item ID, 0 = all items.
.only_one_itemid = 512;
end;
OnTalk:
.@is_gm = ( getgmlevel() >= 99 );
mes "^0055FF[ Item Collector ]^000000";
mes "Do you have any used items? You may give it to me.";
mes " ";
mes "I'll always remember who giveaway his items to me.";
next;
switch( select(
"View Top "+.top_rank+" Rank",
"Give Item to NPC",
( .@is_gm ) ? "[GM] Reset" : ""
)) {
default:
do {
switch( select(
"Filter by Name",
( .only_one_itemid ) ? "":"Filter by ItemID",
"Without Filter"
) ) {
case 1: mes "Enter Char Name"; break;
case 2: mes "Enter ItemID"; break;
default: break;
}
if ( @menu && @menu < 3 ) {
next;
input .@input$;
}
.@sql$ = "SELECT `name`, `nameid`, SUM(`amount`) AS `total` "
+ "FROM `e_npc_trade_item` "
+ "WHERE 1 = 1 "
+ ( .only_one_itemid ? "AND `nameid` = "+.only_one_itemid+" " : "" )
+ ( ( @menu == 1 ) ? "AND `name` = '"+escape_sql( .@input$ )+"' " : "" )
+ ( ( @menu == 2 ) ? "AND `nameid` = '"+escape_sql( .@input$ )+"' " : "" )
+ "GROUP BY `cid`,`nameid` "
+ "ORDER BY `total` DESC LIMIT "+.top_rank;
query_sql( .@sql$,.@name$,.@nameid,.@total );
.@size = getarraysize( .@name$ );
mes "Top "+.top_rank+" Records:";
if ( .@size ) {
for ( .@i = 0; .@i < .@size; .@i++ ) {
mes "["+(.@i+1)+".] '"+getitemname( .@nameid[.@i] )+"' ("+.@total[.@i]+"ea) - '"+.@name$[.@i]+"' ";
}
}
else {
mes "no record found.";
}
next;
} while ( 1 );
break;
case 2:
if ( !.only_one_itemid ) {
mes "Pick an item and give to me";
getinventorylist;
for ( .@i = 0; .@i < @inventorylist_count; .@i++ ) {
if ( @inventorylist_bound[.@i] <= 0
&& @inventorylist_expire[.@i] <= 0
&& @inventorylist_equip[.@i] <= 0
&& func_DisallowItem( @inventorylist_id[.@i] ) <= 0
) {
.@menu$ = .@menu$ + getitemname( @inventorylist_id[.@i] ) + " ("+@inventorylist_amount[.@i]+" left)";
.@count++;
}
.@menu$ = .@menu$ + ":";
}
if ( .@count ) {
.@i = select( .@menu$ ) - 1;
.@itemid = @inventorylist_id[.@i];
}
}
else {
.@itemid = .only_one_itemid;
.@count++;
}
if ( .@itemid ) {
mes "How many "+getitemname( .@itemid )+" will be given to me?";
input .@amount,0,countitem( .@itemid );
if ( .@amount ) {
delitem .@itemid,.@amount;
npctalk "Thank you, "+strcharinfo(0)+" donated "+.@amount+"x "+getitemname( .@itemid )+" to me.";
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 );
mes "Thank for your kindness.";
}
}
else {
mes "You dont have any item available to give to NPC.";
}
break;
case 3:
mes "This action cant be undo, confirm your action?";
next;
if ( select( "Yes, confirm.","Cancel" ) == 1 ) {
query_sql( "TRUNCATE `e_npc_trade_item`" );
}
break;
}
close;
}
Comments