/*==========================================
* Countstorageitem,type,item{,charid} [Lighta]
* type : 0 storage, 1 guildinventory
* item : itemid or itemname
*------------------------------------------*/
BUILDIN_FUNC(countstorageitem) {
TBL_PC * sd = ((script_hasdata(st, 11)) ? map_id2sd(script_getnum(st, 11)) : script_rid2sd(st));
int i, type, count = 0;
struct item_data* item_data;
struct guild_storage *gstor;
struct storage_data *stor;
struct item tmp_it;
type = script_getnum(st, 2);
if (sd != NULL && (item_data = itemdb_exists(script_getnum(st, 3))) != NULL) {
tmp_it.nameid = item_data->nameid;
tmp_it.identify = script_getnum(st, 4);
tmp_it.refine = script_getnum(st, 5);
tmp_it.attribute = script_getnum(st, 6);
tmp_it.card[0] = script_getnum(st, 7);
tmp_it.card[1] = script_getnum(st, 8);
tmp_it.card[2] = script_getnum(st, 9);
tmp_it.card[3] = script_getnum(st, 10);
switch (type) {
case 0:
stor = &sd->status.storage;
for (i = 0; i < MAX_STORAGE; i++) {
if ((&stor->items[i] != NULL)
&& stor->items[i].amount > 0
&& compare_item(&stor->items[i], &tmp_it, 1)
)
count += stor->items[i].amount;
}
script_pushint(st, count);
break;
case 1:
if (sd->status.guild_id && (gstor = guild2storage2(sd->status.guild_id))) {
for (i = 0; i < MAX_GUILD_STORAGE; i++) {
if ((&gstor->items[i] != NULL)
&& gstor->items[i].amount > 0
&& compare_item(&gstor->items[i], &tmp_it, 1)
)
count += gstor->items[i].amount;
}
script_pushint(st, count);
}
break;
default:
ShowError("Invalid type specified in countstorageitem");
script_pushint(st, -1);
break;
}
}
return 0;
}