summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog-Trunk.txt2
-rw-r--r--doc/script_commands.txt15
-rw-r--r--src/map/npc.c35
-rw-r--r--src/map/npc.h3
-rw-r--r--src/map/script.c60
5 files changed, 92 insertions, 23 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index e0efb0e0e..928f1881b 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -4,6 +4,8 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO
IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
2007/11/22
+ * Renamed fakenpcname to setnpcdisplay, fixed and extended it. [FlavioJS]
+ - See doc/script_commands.txt for information on how to use it
* Modified mapserver login procedure to make clients from may 2007
and newer not crash when entering mapserver (bugreport:468) [ultramage]
- this changes PACKETVER to 8, causing incompatibility with old clients
diff --git a/doc/script_commands.txt b/doc/script_commands.txt
index 41c455a7d..35b1958f5 100644
--- a/doc/script_commands.txt
+++ b/doc/script_commands.txt
@@ -9,7 +9,7 @@
//= Maeki Rika - A section on general concepts and lots of
//= other updates and additions.
//===== Version ===========================================
-//= 3.09.20071103
+//= 3.10.20071122
//=========================================================
//= 1.0 - First release, filled will as much info as I could
//= remember or figure out, most likely there are errors,
@@ -90,6 +90,8 @@
//= Clarified how npc names work. [FlavioJS]
//= 3.09.20071103
//= Added script function 'strnpcinfo' [ultramage]
+//= 3.10.20071122
+//= Added setnpcdisplay. [FlavioJS]
//===== Description =======================================
//= A reference manual for the eAthena scripting language,
//= sorted out depending on their functionality.
@@ -4879,6 +4881,17 @@ complete the effect.
npctalk "Hello "+strcharinfo(0)+" how are you";
---------------------------------------
+
+*setnpcdisplay("<npc name>", "<display name>", <class id>)
+*setnpcdisplay("<npc name>", "<display name>")
+*setnpcdisplay("<npc name>", <class id>)
+
+Changes the display name and/or display class of the target npc.
+Returns 0 is successful, 1 if the npc does not exist.
+
+Since trunk r11779
+
+---------------------------------------
\\
5,1.- Time-related commands
\\
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