From 40f0847e0faff7526c4290b83b50f9237c1e1438 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 23 Nov 2014 19:32:40 +0300 Subject: Partially impliment script command countitemcolor. --- src/map/init.c | 2 +- src/map/script.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/map/script.h | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3-70-g09d2