diff options
-rw-r--r-- | src/emap/init.c | 3 | ||||
-rw-r--r-- | src/emap/script_buildins.c | 49 | ||||
-rw-r--r-- | src/emap/script_buildins.h | 3 |
3 files changed, 55 insertions, 0 deletions
diff --git a/src/emap/init.c b/src/emap/init.c index a784eec..8838aab 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -231,7 +231,10 @@ HPExport void plugin_init (void) addScriptCommand("homstatus","",homstatus); addScriptCommand("readparam2","i?",readparam2); addScriptCommand("npcshopattach","s?",npcshopattach); + + // Overrides addScriptCommand("debugmes","v*",debugmes); + addScriptCommand("countitem","v?",countitem); do_init_langs(); 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; +} + diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index 5abcb68..e8fdcf7 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -117,6 +117,9 @@ BUILDIN(deployhomunculus); BUILDIN(recallhomunculus); BUILDIN(homstatus); BUILDIN(readparam2); + +// Overrides +BUILDIN(countitem); BUILDIN(debugmes); #endif // EVOL_MAP_SCRIPT_BUILDINS |