diff --git a/doc/script_commands.txt b/doc/script_commands.txt index ca4f58a00b..b4daf38a12 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -3583,14 +3583,15 @@ This command does not count skills which are set as flag 4 (permament granted) ( --------------------------------------- *getmonsterinfo(,) +*getmonsterinfo(,) -This function will look up the monster with the specified ID number in the -mob database and return the info set by TYPE argument. +This function will look up the monster with the specified or in the +mob database and return the info set by argument. It will return -1 if there is no such monster (or the type value is invalid), or "null" if you requested the monster's name. Valid types are: - MOB_NAME - monster's name, if there is no such monster "null" is returned + MOB_NAME - monster's japanese name, if there is no such monster "null" is returned MOB_LV - monster's level MOB_MAXHP - monster's maximum hp MOB_BASEEXP - monster's base experience @@ -3615,6 +3616,7 @@ Valid types are: MOB_ELEMENT - monster's element(doesn't return the element level, only the element ID) MOB_MODE - monster's mode MOB_MVPEXP - monster's mvp experience + MOB_ID - monster's ID For more details, see the sample in 'doc/sample/getmonsterinfo.txt'. diff --git a/src/map/script.cpp b/src/map/script.cpp index b1a0074cca..e61782653d 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -18067,24 +18067,32 @@ BUILDIN_FUNC(delmonsterdrop) * Returns some values of a monster [Lupus] * Name, Level, race, size, etc... getmonsterinfo(monsterID,queryIndex); + getmonsterinfo(monsterName,queryIndex); *------------------------------------------*/ BUILDIN_FUNC(getmonsterinfo) { - int mob_id; + std::shared_ptr mob = nullptr; - mob_id = script_getnum(st,2); - if (!mobdb_checkid(mob_id)) { + if (script_isstring(st, 2)) + mob = mobdb_search_aegisname(script_getstr(st, 2)); + else { + uint16 mob_id = script_getnum(st, 2); + + if (!mob_is_clone(mob_id)) { + mob = mob_db.find(mob_id); + } + } + + if (mob == nullptr) { //ShowError("buildin_getmonsterinfo: Wrong Monster ID: %i\n", mob_id); - if ( script_getnum(st,3) == MOB_NAME ) // requested the name - script_pushconststr(st,"null"); + if (script_getnum(st, 3) == MOB_NAME) // requested the name + script_pushconststr(st, "null"); else - script_pushint(st,-1); + script_pushint(st, -1); return SCRIPT_CMD_SUCCESS; } - std::shared_ptr mob = mob_db.find(mob_id); - - switch ( script_getnum(st,3) ) { + switch ( script_getnum(st, 3) ) { case MOB_NAME: script_pushstrcopy(st,mob->jname.c_str()); break; case MOB_LV: script_pushint(st,mob->lv); break; case MOB_MAXHP: script_pushint(st,mob->status.max_hp); break; @@ -18110,6 +18118,7 @@ BUILDIN_FUNC(getmonsterinfo) case MOB_ELEMENT: script_pushint(st,mob->status.def_ele); break; case MOB_MODE: script_pushint(st,mob->status.mode); break; case MOB_MVPEXP: script_pushint(st,mob->mexp); break; + case MOB_ID: script_pushint(st,mob->id); break; default: script_pushint(st,-1); //wrong Index } return SCRIPT_CMD_SUCCESS; @@ -26724,7 +26733,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(setitemscript,"is?"), //Set NEW item bonus script. Lupus BUILDIN_DEF(disguise,"i?"), //disguise player. Lupus BUILDIN_DEF(undisguise,"?"), //undisguise player. Lupus - BUILDIN_DEF(getmonsterinfo,"ii"), //Lupus + BUILDIN_DEF(getmonsterinfo,"vi"), //Lupus BUILDIN_DEF(addmonsterdrop,"vii??"), //Akinari [Lupus] BUILDIN_DEF(delmonsterdrop,"vi"), //Akinari [Lupus] BUILDIN_DEF(axtoi,"s"), diff --git a/src/map/script.hpp b/src/map/script.hpp index 51aaa454c2..0a0c759771 100644 --- a/src/map/script.hpp +++ b/src/map/script.hpp @@ -379,7 +379,8 @@ enum monsterinfo_types { MOB_RACE, MOB_ELEMENT, MOB_MODE, - MOB_MVPEXP + MOB_MVPEXP, + MOB_ID, }; enum petinfo_types { diff --git a/src/map/script_constants.hpp b/src/map/script_constants.hpp index 25ce19a670..09d5aa5986 100644 --- a/src/map/script_constants.hpp +++ b/src/map/script_constants.hpp @@ -4462,6 +4462,7 @@ export_constant(MOB_ELEMENT); export_constant(MOB_MODE); export_constant(MOB_MVPEXP); + export_constant(MOB_ID); /* petinfo types */ export_constant(PETINFO_ID);