From a1ad56d8c1e5d07c3dbe3b3d3d54c94650febeaa Mon Sep 17 00:00:00 2001 From: momacabu Date: Mon, 12 Nov 2012 02:46:28 +0000 Subject: Modified @addwarp to accept a new optional parameter . If is specified, then the warp created will have that name. Otherwise it will use a name chosen by the emulator. If there is already another warp with that name the generic name will be used instead. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@16919 54d463be-8e91-2dee-dedb-b68131a5f0ec --- src/map/atcommand.c | 9 +++++---- src/map/npc.c | 16 +++++++++++++--- src/map/npc.h | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/map') diff --git a/src/map/atcommand.c b/src/map/atcommand.c index 25fc3182d..5d032c457 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -5259,15 +5259,16 @@ ACMD_FUNC(npcmove) *------------------------------------------*/ ACMD_FUNC(addwarp) { - char mapname[32]; + char mapname[32], warpname[NAME_LENGTH+1]; int x,y; unsigned short m; struct npc_data* nd; nullpo_retr(-1, sd); + memset(warpname, '\0', sizeof(warpname)); - if (!message || !*message || sscanf(message, "%31s %d %d", mapname, &x, &y) < 3) { - clif_displaymessage(fd, msg_txt(1156)); // Usage: @addwarp + if (!message || !*message || sscanf(message, "%31s %d %d %23[^\n]", mapname, &x, &y, warpname) < 3) { + clif_displaymessage(fd, msg_txt(1156)); // Usage: @addwarp {} return -1; } @@ -5279,7 +5280,7 @@ ACMD_FUNC(addwarp) return -1; } - nd = npc_add_warp(sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y); + nd = npc_add_warp(warpname, sd->bl.m, sd->bl.x, sd->bl.y, 2, 2, m, x, y); if( nd == NULL ) return -1; diff --git a/src/map/npc.c b/src/map/npc.c index 62a263e5a..0ed3dd68b 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -2008,9 +2008,9 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta } //Add then display an npc warp on map -struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y) +struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y) { - int i; + int i, flag = 0; struct npc_data *nd; CREATE(nd, struct npc_data, 1); @@ -2020,7 +2020,17 @@ struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, shor nd->bl.m = from_mapid; nd->bl.x = from_x; nd->bl.y = from_y; - snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y); + + if (name) + { + safestrncpy(nd->exname, name, ARRAYLENGTH(nd->exname)); + if (npc_name2id(nd->exname) != NULL) + flag = 1; + } + + if (name[0] == '\0' || flag == 1) + snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp_%d_%d_%d", from_mapid, from_x, from_y); + for( i = 0; npc_name2id(nd->exname) != NULL; ++i ) snprintf(nd->exname, ARRAYLENGTH(nd->exname), "warp%d_%d_%d_%d", i, from_mapid, from_x, from_y); safestrncpy(nd->name, nd->exname, ARRAYLENGTH(nd->name)); diff --git a/src/map/npc.h b/src/map/npc.h index 29cf39c77..0379ae634 100644 --- a/src/map/npc.h +++ b/src/map/npc.h @@ -120,7 +120,7 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type); int npc_buylist(struct map_session_data* sd,int n, unsigned short* item_list); int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list); void npc_parse_mob2(struct spawn_data* mob); -struct npc_data* npc_add_warp(short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); +struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y); int npc_globalmessage(const char* name,const char* mes); void npc_setcells(struct npc_data* nd); -- cgit v1.2.3-70-g09d2