From b697b14764f18978c7894113adbad86637cbcdcc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 12 Jan 2016 14:45:02 +0300 Subject: Add script command for get item amount from one craft slot. New script command: getcraftslotamount id, slot --- src/emap/script.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/emap/script.c') diff --git a/src/emap/script.c b/src/emap/script.c index 07950ab..0a63090 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -1918,3 +1918,37 @@ BUILDIN(getCraftSlotId) } return true; } + +BUILDIN(getCraftSlotAmount) +{ + getSD() + + const struct craft_slot *crslot = craft_get_slot(script_getnum(st, 2), + script_getnum(st, 3)); + if (!crslot) + return false; + const int len = VECTOR_LENGTH(crslot->items); + if (len > 0) + { + int slot; + int amount = 0; + for (slot = 0; slot < len; slot ++) + { + struct item_pair *pair = &VECTOR_INDEX(crslot->items, slot); + const int invIndex = pair->index; + const int item_id = sd->status.inventory[invIndex].nameid; + if (item_id > 0) + { + const int item_amount = sd->status.inventory[invIndex].amount; + if (item_amount > 0) + amount += pair->amount; + } + } + script_pushint(st, amount); + } + else + { + script_pushint(st, 0); + } + return true; +} -- cgit v1.2.3-70-g09d2