summaryrefslogtreecommitdiff
path: root/src/emap/script_buildins.c
diff options
context:
space:
mode:
authorJesusaves <cpntb1@ymail.com>2019-11-06 16:00:11 -0300
committerJesusaves <cpntb1@ymail.com>2019-11-06 16:00:11 -0300
commitc87e652672523fd3e37e67f015924e837eecc4df (patch)
tree168db7fa1e4961484f4184f05e7a974f3562683e /src/emap/script_buildins.c
parent5dd8305335159d853c28b531090e22da35346bd4 (diff)
downloadevol-hercules-c87e652672523fd3e37e67f015924e837eecc4df.tar.gz
evol-hercules-c87e652672523fd3e37e67f015924e837eecc4df.tar.bz2
evol-hercules-c87e652672523fd3e37e67f015924e837eecc4df.tar.xz
evol-hercules-c87e652672523fd3e37e67f015924e837eecc4df.zip
countitem() - add support for RID
Diffstat (limited to 'src/emap/script_buildins.c')
-rw-r--r--src/emap/script_buildins.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index 074c1df..e0e22ce 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -2917,3 +2917,52 @@ BUILDIN(debugmes)
return true;
}
+/*==========================================
+ *
+ *------------------------------------------*/
+BUILDIN(countitem)
+{
+ int count = 0;
+ struct item_data* id = NULL;
+ struct map_session_data *sd;
+
+ if (script_hasdata(st,3)) {
+ int account_id = script_getnum(st,3);
+ sd = script->id2sd(st, account_id); // <account id>
+ if (sd == NULL) {
+ return true;
+ }
+ } else {
+ sd = script->rid2sd(st);// attached player
+ if (sd == NULL)
+ return true;
+ }
+
+ if (sd == NULL)
+ return true;
+
+ if( script_isstringtype(st, 2) ) {
+ // item name
+ id = itemdb->search_name(script_getstr(st, 2));
+ } else {
+ // item id
+ id = itemdb->exists(script_getnum(st, 2));
+ }
+
+ if( id == NULL ) {
+ ShowError("buildin_countitem: Invalid item '%s'.\n", script_getstr(st,2)); // returns string, regardless of what it was
+ script_pushint(st,0);
+ return false;
+ }
+
+ int nameid = id->nameid;
+
+ for (int i = 0; i < sd->status.inventorySize; i++) {
+ if (sd->status.inventory[i].nameid == nameid)
+ count += sd->status.inventory[i].amount;
+ }
+
+ script_pushint(st,count);
+ return true;
+}
+