Jump to content
  • 0

How can i duplicate a NPC inside of my script?


Question

3 answers to this question

Recommended Posts

  • 1
Posted

Heya,

This is possible, but it usually means the solution/algoritm you're trying to use is the wrong one to start with. That aside, you can use something similar to:

duplicate "prontera", 154, 182, 4, "SourceNPC", "DuplicatedNPC", 77;

And you'll have to do the changes below:

diff --git a/src/map/npc.hpp b/src/map/npc.hpp
index 0ce0c96a0..ffde62587 100644
--- a/src/map/npc.hpp
+++ b/src/map/npc.hpp
@@ -1219,6 +1219,7 @@ void do_clear_npc(void);
 void do_final_npc(void);
 void do_init_npc(void);
 void npc_event_do_oninit(void);
+const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath);
 
 int npc_event_do(const char* name);
 int npc_event_do_id(const char* name, int rid);
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 604274ecd..9da5d4690 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -24548,6 +24548,38 @@ BUILDIN_FUNC(preg_match) {
 #endif
 }
 
+BUILDIN_FUNC(duplicate)
+{
+	const char *map = script_getstr(st,2);
+	int x = script_getnum(st,3);
+	int y = script_getnum(st,4);
+	int dir = script_getnum(st,5);
+	const char *duplicate_name = script_getstr(st,6);
+	const char *npc_name = script_getstr(st,7);
+	char w1[2048], w2[2048], w3[2048], w4[2048], p[2048];
+	int view_id = script_getnum(st,8);
+	struct npc_data* nd = map_id2nd(st->oid);
+	
+	if (!nd) {
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	sprintf(w1, "%s,%d,%d,%d", map, x, y, dir);
+	sprintf(w2, "duplicate(%s)", duplicate_name);
+	sprintf(w3, "%s", npc_name);
+
+	if (script_hasdata(st,9) && script_hasdata(st,10)) {
+		sprintf(w4, "%d,%d,%d", view_id, script_getnum(st,9), script_getnum(st,10));
+	}
+	else {
+		sprintf(w4, "%d", view_id);
+	}
+
+	sprintf(p, "%s\t%s\t%s\t%s", w1, w2, w3, w4);
+	npc_parse_duplicate(w1,w2,w3,w4, p, p, nd->path);
+	return SCRIPT_CMD_SUCCESS;
+}
+
 /// script command definitions
 /// for an explanation on args, see add_buildin_func
 struct script_function buildin_func[] = {
@@ -25170,6 +25202,8 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(achievement_condition,"i"),
 	BUILDIN_DEF(getvariableofinstance,"ri"),
 	BUILDIN_DEF(convertpcinfo,"vi"),
+	
+	BUILDIN_DEF(duplicate,"siiissi??"),
 #include "../custom/script_def.inc"
 
 	{NULL,NULL,NULL},

 

  • Upvote 2
  • 0
Posted
3 hours ago, luizragna said:

Hello guys. How can i do it the right way?


prontera,100,100,4	script	Duplicator	84,{
  
prontera,162,193,4	duplicate(Healer)	Healer#prt	909 //<-----

}

 

prontera,100,100,4	script	Duplicator	84,{
	script
}

prontera,162,193,4	duplicate(Duplicator)	Healer#prt	909

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...