* Renamed fakenpcname to setnpcdisplay, fixed and extended it.

- See doc/script_commands.txt for information on how to use it

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@11779 54d463be-8e91-2dee-dedb-b68131a5f0ec
This commit is contained in:
FlavioJS 2007-11-22 16:06:39 +00:00
parent 622b38ca4a
commit 508ffb82d9
5 changed files with 92 additions and 23 deletions

View File

@ -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

View File

@ -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.
@ -4878,6 +4880,17 @@ complete the effect.
// who just invoked it.
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

View File

@ -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.

View File

@ -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);

View File

@ -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