//Version 2013/02/23
//Author goddameit
//Web http://goo.gl/0vY9GV
//
//item_db.txt
//12130,Cookie_Bag,Cookie Bag,2,2,,70,,,,,0xFFFFFFFF,7,2,,,,,,{ getitem 12130,1; callfunc "CustomStorage",100,select("Store","Pick")-1;},{},{}
//
//New SQL table
/*
CREATE TABLEcustom_storage SELECT * FROM storage;
ALTER TABLE `custom_storage` ADD PRIMARY KEY ( `id` );
ALTER TABLE `custom_storage` CHANGE `id` `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT;
TRUNCATE TABLE `custom_storage`;
*/
function script CustomStorage {
function clean {
deletearray @n[0],128;
deletearray @nam[0],128;
deletearray @nid[0],128;
deletearray @inventorylist_id[0],128;
deletearray @inventorylist_amount[0],128;
deletearray @inventorylist_equip[0],128;
deletearray @inventorylist_refine[0],128;
deletearray @inventorylist_identify[0],128;
deletearray @inventorylist_attribute[0],128;
deletearray @inventorylist_card1[0],128;
deletearray @inventorylist_card2[0],128;
deletearray @inventorylist_card3[0],128;
deletearray @inventorylist_card4[0],128;
deletearray @inventorylist_expire[0],128;
set @inventorylist_count,0;
}
if(getarg(1))
{
clean;
query_sql("SELECT nameid,id,amount FROM `custom_storage` WHERE `account_id` = "+getcharid(3)+"",@n,@nid,@nam);
set @select$,"";
for(set .@i,0;.@i<getarraysize(@n);set .@i,.@i+1)
set @select$,@select$+":["+getitemname(@n[.@i])+"]x["+@nam[.@i]+"]";
if(input(@ss,1,@nam[set(@menu,select(@select$)-2)]))
set @ss,@nam[@menu];
getitem @n[@menu],@ss;
if(set(.@zz,@nam[@menu]-@ss)>0)
query_sql "UPDATE `custom_storage` set amount = "+.@zz+" where id = "+@nid[@menu];
else
query_sql "DELETE FROM `custom_storage` WHERE `id` = "+@nid[@menu];
mes "Complete";
clean;
close;
}
clean;
getinventorylist;
set @select$,"";
for(set .@i,0;.@i<@inventorylist_count;set .@i,.@i+1)
set @select$,@select$+":["+getitemname(@inventorylist_id[.@i])+"]x["+@inventorylist_amount[.@i]+"]";
if(@inventorylist_equip[set(@menu,select(@select$)-2)]||@inventorylist_expire[@menu])
{
clean;
mes "Fail";
close;
}
if(input(@ss,1,@inventorylist_amount[@menu]))
set @ss,@inventorylist_amount[@menu];
query_sql("SELECT nameid,id,amount FROM `custom_storage` WHERE `account_id` = "+getcharid(3)+"",.@n,.@nid,.@nam);
if(getarg(0)<getarraysize(.@n))
{
clean;
close;
}
for(set .@h,set(.@g,0);.@n[.@h];set .@h,.@h+1)
if(.@n[.@h]==@inventorylist_id[@menu])
{
if(set(.@g,getiteminfo(.@n[.@h],2))>=4&&.@g<=10&&.@g!=6)
set .@g,0;
else
set .@g,.@nam[.@h]+@ss;
break;
}
if(!.@g)
query_sql "INSERT `custom_storage` VALUES ( NULL,"+getcharid(3)
+","+@inventorylist_id[@menu]+","+@ss+",0,"+@inventorylist_identify[@menu]
+","+@inventorylist_refine[@menu]+","+@inventorylist_attribute[@menu]
+","+@inventorylist_card0[@menu]+","+@inventorylist_card1[@menu]
+","+@inventorylist_card2[@menu]+","+@inventorylist_card3[@menu]+",0)";
else
query_sql "UPDATE `custom_storage` set amount = "+.@g+" where id = "+.@nid[.@h];
delitem @inventorylist_id[@menu],@ss;
mes "Complete";
clean;
close;
}