summaryrefslogtreecommitdiff
path: root/src/emap/script.c
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-12 14:45:02 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-12 14:45:02 +0300
commitb697b14764f18978c7894113adbad86637cbcdcc (patch)
tree66fe7dd978ccf0601e877df8766695b4773a0f2a /src/emap/script.c
parent32edcdcf47c804d0bb40299fad5d184b558bb76c (diff)
downloadevol-hercules-b697b14764f18978c7894113adbad86637cbcdcc.tar.gz
evol-hercules-b697b14764f18978c7894113adbad86637cbcdcc.tar.bz2
evol-hercules-b697b14764f18978c7894113adbad86637cbcdcc.tar.xz
evol-hercules-b697b14764f18978c7894113adbad86637cbcdcc.zip
Add script command for get item amount from one craft slot.
New script command: getcraftslotamount id, slot
Diffstat (limited to 'src/emap/script.c')
-rw-r--r--src/emap/script.c34
1 files changed, 34 insertions, 0 deletions
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;
+}