summaryrefslogtreecommitdiff
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
parent32edcdcf47c804d0bb40299fad5d184b558bb76c (diff)
downloadplugin-b697b14764f18978c7894113adbad86637cbcdcc.tar.gz
plugin-b697b14764f18978c7894113adbad86637cbcdcc.tar.bz2
plugin-b697b14764f18978c7894113adbad86637cbcdcc.tar.xz
plugin-b697b14764f18978c7894113adbad86637cbcdcc.zip
Add script command for get item amount from one craft slot.
New script command: getcraftslotamount id, slot
-rw-r--r--src/emap/init.c1
-rw-r--r--src/emap/script.c34
-rw-r--r--src/emap/script.h1
3 files changed, 36 insertions, 0 deletions
diff --git a/src/emap/init.c b/src/emap/init.c
index 7a00569..b71ac37 100644
--- a/src/emap/init.c
+++ b/src/emap/init.c
@@ -104,6 +104,7 @@ HPExport void plugin_init (void)
addScriptCommand("dumpcraft", "i", dumpCraft);
addScriptCommand("deletecraft", "i", deleteCraft);
addScriptCommand("getcraftslotid", "ii", getCraftSlotId);
+ addScriptCommand("getcraftslotamount", "ii", getCraftSlotAmount);
addScriptCommand("getq", "i", getq);
addScriptCommand("setq", "ii", setq);
addScriptCommand("setnpcdir", "*", setNpcDir);
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;
+}
diff --git a/src/emap/script.h b/src/emap/script.h
index c74a09b..c433baf 100644
--- a/src/emap/script.h
+++ b/src/emap/script.h
@@ -69,5 +69,6 @@ BUILDIN(initCraft);
BUILDIN(dumpCraft);
BUILDIN(deleteCraft);
BUILDIN(getCraftSlotId);
+BUILDIN(getCraftSlotAmount);
#endif // EVOL_MAP_SCRIPT