From e2ddbced3c35ca2d1c704c2b724234cc09a37418 Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Thu, 22 Nov 2007 16:06:39 +0000 Subject: * Renamed fakenpcname to setnpcdisplay, fixed and extended it. - See doc/script_commands.txt for information on how to use it git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@11779 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/script.c | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 12 deletions(-) (limited to 'src/map/script.c') 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("", "", ) -> +/// setnpcdisplay("", "") -> +/// setnpcdisplay("", ) -> +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 -- cgit v1.2.3-70-g09d2