diff options
Diffstat (limited to 'src/map')
-rw-r--r-- | src/map/npc.c | 35 | ||||
-rw-r--r-- | src/map/npc.h | 3 | ||||
-rw-r--r-- | src/map/script.c | 60 |
3 files changed, 76 insertions, 22 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index 14cf398c4..a65cf5e83 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2042,16 +2042,33 @@ void npc_movenpc(struct npc_data* nd, int x, int y) map_foreachinrange(clif_insight, &nd->bl, AREA_SIZE, BL_PC, &nd->bl); } -int npc_changename(const char* name, const char* newname, short look) +/// Changes the display name of the npc. +/// +/// @param nd Target npc +/// @param newname New display name +void npc_setdisplayname(struct npc_data* nd, const char* newname) { - struct npc_data* nd = (struct npc_data *) strdb_remove(npcname_db, name); - if (nd == NULL) - return 0; - npc_enable(name, 0); - strcpy(nd->name, newname); - nd->class_ = look; - npc_enable(newname, 1); - return 0; + nullpo_retv(nd); + + safestrncpy(nd->name, newname, sizeof(nd->name)); + clif_charnameack(0, &nd->bl); +} + +/// Changes the display class of the npc. +/// +/// @param nd Target npc +/// @param class_ New display class +void npc_setclass(struct npc_data* nd, short class_) +{ + nullpo_retv(nd); + + if( nd->class_ == class_ ) + return; + + clif_clearunit_area(&nd->bl, 0);// fade out + nd->class_ = class_; + status_set_viewdata(&nd->bl, class_); + clif_spawn(&nd->bl);// fade in } /// Parses a function. diff --git a/src/map/npc.h b/src/map/npc.h index a21cfd746..c1a7dbfe9 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -60,7 +60,8 @@ void npc_setcells(struct npc_data* nd); void npc_unsetcells(struct npc_data* nd); void npc_movenpc(struct npc_data* nd, int x, int y); int npc_enable(const char* name, int flag); -int npc_changename(const char* name, const char* newname, short look); // [Lance] +void npc_setdisplayname(struct npc_data* nd, const char* newname); +void npc_setclass(struct npc_data* nd, short class_); struct npc_data* npc_name2id(const char* name); int npc_get_new_npc_id(void); diff --git a/src/map/script.c b/src/map/script.c index ff10c853a..14302250a 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -11391,20 +11391,56 @@ BUILDIN_FUNC(charisalpha) return 0; } -// [Lance] -BUILDIN_FUNC(fakenpcname) +/// Changes the display name and/or display class of the npc. +/// Returns 0 is successful, 1 if the npc does not exist. +/// +/// setnpcdisplay("<npc name>", "<new display name>", <new class id>) -> <int> +/// setnpcdisplay("<npc name>", "<new display name>") -> <int> +/// setnpcdisplay("<npc name>", <new class id>) -> <int> +BUILDIN_FUNC(setnpcdisplay) { - const char *name; - const char *newname; - int look; + const char* name; + const char* newname = NULL; + int class_ = -1; + struct script_data* data; + struct npc_data* nd; + name = script_getstr(st,2); - newname = script_getstr(st,3); - look = script_getnum(st,4); - if(look > 32767 || look < -32768) { - ShowError("buildin_fakenpcname: Invalid look value %d\n",look); - return 1; // Safety measure to prevent runtime errors + data = script_getdata(st,3); + get_val(st, data); + if( script_hasdata(st,4) ) + { + newname = conv_str(st,data); + class_ = script_getnum(st,4); } - npc_changename(name,newname,(short)look); + else if( data_isstring(data) ) + { + newname = conv_str(st,data); + } + else if( data_isint(data) ) + { + class_ = conv_num(st,data); + } + else + { + ShowError("script:setnpcdisplay: expected a string or number\n"); + script_reportdata(data); + return 1; + } + + nd = npc_name2id(name); + if( nd == NULL ) + {// not found + script_pushint(st,1); + return 0; + } + + // update npc + if( newname ) + npc_setdisplayname(nd, newname); + if( class_ != -1 ) + npc_setclass(nd, class_); + script_pushint(st,0); return 0; } @@ -13042,7 +13078,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(unequip,"i"), // unequip command [Spectre] BUILDIN_DEF(getstrlen,"s"), //strlen [Valaris] BUILDIN_DEF(charisalpha,"si"), //isalpha [Valaris] - BUILDIN_DEF(fakenpcname,"ssi"), // [Lance] + BUILDIN_DEF(setnpcdisplay,"sv?"), BUILDIN_DEF(compare,"ss"), // Lordalfa - To bring strstr to scripting Engine. BUILDIN_DEF(getiteminfo,"ii"), //[Lupus] returns Items Buy / sell Price, etc info BUILDIN_DEF(setiteminfo,"iii"), //[Lupus] set Items Buy / sell Price, etc info |