summaryrefslogtreecommitdiff
path: root/src/map
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-11-23 19:32:40 +0300
committerAndrei Karas <akaras@inbox.ru>2014-11-23 19:32:40 +0300
commit40f0847e0faff7526c4290b83b50f9237c1e1438 (patch)
tree4b18f20e2e2416af341853a373e450ba3548da47 /src/map
parentbf50409735647a80a7145def628822d5235ea753 (diff)
downloadevol-hercules-40f0847e0faff7526c4290b83b50f9237c1e1438.tar.gz
evol-hercules-40f0847e0faff7526c4290b83b50f9237c1e1438.tar.bz2
evol-hercules-40f0847e0faff7526c4290b83b50f9237c1e1438.tar.xz
evol-hercules-40f0847e0faff7526c4290b83b50f9237c1e1438.zip
Partially impliment script command countitemcolor.
Diffstat (limited to 'src/map')
-rw-r--r--src/map/init.c2
-rw-r--r--src/map/script.c40
-rw-r--r--src/map/script.h1
3 files changed, 42 insertions, 1 deletions
diff --git a/src/map/init.c b/src/map/init.c
index bc64e32..6732065 100644
--- a/src/map/init.c
+++ b/src/map/init.c
@@ -75,7 +75,7 @@ HPExport void plugin_init (void)
addScriptCommand("getnpcdir", "*", getNpcDir);
addScriptCommand("setnpcdir", "*", setNpcDir);
addScriptCommand("rif", "is*", rif);
- addScriptCommand("countitemcolor", "*", dummyInt);
+ addScriptCommand("countitemcolor", "v*", countItemColor);
addScriptCommandDeprecated("getclientversion", "", getClientVersion);
// must be replaced to misceffect
addScriptCommand("misceffect2", "i*", dummy);
diff --git a/src/map/script.c b/src/map/script.c
index 2bc9422..efb53a9 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -382,3 +382,43 @@ BUILDIN(rif)
return true;
}
+
+BUILDIN(countItemColor)
+{
+ int nameid, i;
+ int count = 0;
+ struct item_data* id = NULL;
+
+ TBL_PC* sd = script->rid2sd(st);
+ if (!sd)
+ 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;
+ }
+
+ nameid = id->nameid;
+
+ for(i = 0; i < MAX_INVENTORY; i++)
+ {
+ if(sd->status.inventory[i].nameid == nameid)
+ count += sd->status.inventory[i].amount;
+ }
+
+ script_pushint(st, count);
+ return true;
+}
diff --git a/src/map/script.h b/src/map/script.h
index 6fbabc0..cc54dba 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -21,5 +21,6 @@ BUILDIN(setq);
BUILDIN(getNpcDir);
BUILDIN(setNpcDir);
BUILDIN(rif);
+BUILDIN(countItemColor);
#endif // EVOL_MAP_SCRIPT