viewing paste Unknown #5848 | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
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;
}
Viewed 1311 times, submitted by lighta.