BUILDIN_FUNC(countitem2) {
int count = 0;
int i;
struct item_data* id = NULL;
struct item tmp_it;
struct script_data* data;
TBL_PC* sd = script_rid2sd(st);
if (!sd) {
script_pushint(st,0);
return 0;
}
data = script_getdata(st,2);
get_val(st, data); // convert into value in case of a variable
if( data_isstring(data) )
{// item name
id = itemdb_searchname(conv_str(st, data));
}
else
{// item id
id = itemdb_exists(conv_num(st, data));
}
if( id == NULL )
{
ShowError("buildin_countitem2: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was
script_pushint(st,0);
return 1;
}
tmp_it.nameid = id->nameid;
tmp_it.identify = script_getnum(st, 3);
tmp_it.refine = script_getnum(st, 4);
tmp_it.attribute = script_getnum(st, 5);
tmp_it.card[0] = (short) script_getnum(st, 6);
tmp_it.card[1] = (short) script_getnum(st, 7);
tmp_it.card[2] = (short) script_getnum(st, 8);
tmp_it.card[3] = (short) script_getnum(st, 9);
for (i = 0; i < MAX_INVENTORY; i++)
if ((&sd->status.inventory[i] != NULL)
&& sd->status.inventory[i].amount > 0
&& compare_item(&sd->status.inventory[i], &tmp_it, 1)
)
count += sd->status.inventory[i].amount;
script_pushint(st,count);
return 0;
}