viewing paste Unknown #6067 | 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 52 53 54 55 56 57 58
/*==========================================
 * 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;
}
Viewed 1180 times, submitted by lighta.