summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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