From b3f44a8e8ef767617c5e09ba689c16aa3c00d448 Mon Sep 17 00:00:00 2001 From: gumi Date: Sun, 26 Apr 2020 20:27:54 -0400 Subject: add buildin getnpcsubtype() to get nd->subtype --- src/emap/init.c | 1 + src/emap/script.c | 7 +++++++ src/emap/script_buildins.c | 24 ++++++++++++++++++++++++ src/emap/script_buildins.h | 1 + 4 files changed, 33 insertions(+) (limited to 'src/emap') diff --git a/src/emap/init.c b/src/emap/init.c index c2699dd..9bc0324 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -215,6 +215,7 @@ HPExport void plugin_init (void) addScriptCommand("setitemoptionbyindex", "iii*", setItemOptionByIndex); addScriptCommand("isinstance", "i", isInstance); addScriptCommand("readbattleparam","ii",readBattleParam); + addScriptCommand("getnpcsubtype", "?", getNpcSubtype); do_init_langs(); diff --git a/src/emap/script.c b/src/emap/script.c index 9e6add6..eec0df3 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -96,6 +96,13 @@ void escript_hardcoded_constants_pre(void) script->set_constant("GENDER_FEMALE", GENDER_FEMALE, false, false); script->set_constant("GENDER_MALE", GENDER_MALE, false, false); script->set_constant("GENDER_HIDDEN", GENDER_HIDDEN, false, false); + + // npc subtypes + script->set_constant("NPCSUBTYPE_WARP", WARP, false, false); + script->set_constant("NPCSUBTYPE_SHOP", SHOP, false, false); + script->set_constant("NPCSUBTYPE_SCRIPT", SCRIPT, false, false); + script->set_constant("NPCSUBTYPE_CASHSHOP", CASHSHOP, false, false); + script->set_constant("NPCSUBTYPE_TOMB", TOMB, false, false); script->constdb_comment(NULL); eskill_addskill_conststants(); } diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c index 2899cc3..94ed92d 100644 --- a/src/emap/script_buildins.c +++ b/src/emap/script_buildins.c @@ -2349,6 +2349,30 @@ BUILDIN(isInstance) return true; } +BUILDIN(getNpcSubtype) +{ + TBL_NPC *nd = map->id2bl(st->oid); + + if (script_hasdata(st, 2)) + { + if (script_isstringtype(st, 2)) { + nd = npc->name2id(script_getstr(st, 2)); + } else { + nd = map->id2bl(script_getnum(st, 2)); + } + } + + if (!nd) + { + ShowWarning("npc not found\n"); + script->reportsrc(st); + return false; + } + + script_pushint(st, nd->subtype); + return true; +} + /*========================================== * return the battle stats of a structure * Supported values are most of UDT_* ones diff --git a/src/emap/script_buildins.h b/src/emap/script_buildins.h index 6c31909..8895abe 100644 --- a/src/emap/script_buildins.h +++ b/src/emap/script_buildins.h @@ -100,5 +100,6 @@ BUILDIN(getItemOptionParamByIndex); BUILDIN(setItemOptionByIndex); BUILDIN(isInstance); BUILDIN(readBattleParam); +BUILDIN(getNpcSubtype); #endif // EVOL_MAP_SCRIPT_BUILDINS -- cgit v1.2.3-70-g09d2