Duplicate NPC Commands

Dastgir

Core Developer
Messages
3,805
Points
0
Discord
Dastgir#1460
IRC Nickname
Dastgir
Github
dastgirp
Emulator
Client Version
2019-02-28 RE
thumb-5682b59e7f9a13880cf7e48c3b2c0ab7-screenhercules017.jpg


File Name: Duplicate NPC Commands

File Submitter: Dastgir

File Submitted: 12 Jan 2015

File Category: Plugins

2 Self Explanatory Commands:

Code:
duplicatenpc("NpcName", "DuplicateName", "DupHiddenName", "map", x, y, dir{, sprite{, xs, ys}});duplicateremove({"NPCname"});
Example Script:

Code:
prontera,150,150,5	script	DupTest	999,{mes strnpcinfo(0);close;OnInit:duplicatenpc(strnpcinfo(0),"Duplicated","","prontera",150,148,5,998);end;OnWhisperGlobal:duplicateremove();}
^ Above script will self-duplicate itself with name "Duplicated" to prontera,150,148 with Sprite ID 998, and upon whispering to any of those npc, the duplicate will be removed.

Requested by GMOcean @ http://herc.ws/board/topic/7718-duplicatenpc-duplicateremove/?view=getnewpost

Click here to download this file

 
Last edited by a moderator:
Sweet mother of god! This, just made things sooo much better. Now I can rewrite sooo many scripts that rely on hard-coded duplicates, and just soft-duplicate them when needed and then remove. Efficiency + Over 100% less resource consumption since they don't all need to be active at once anymore.

Thanks, Dastgir. Though it sucks school started for me... not much time to play with it T.T;

Edit:

Just 1 question. The duplicateremove command. Does it work in such that, it can remove just 1 duplicate or all if so chosen?

Because, I had originally hoped that, we'd be able to remove 1 specific duplicate and/or all of them, by specifying either a DuplicateNPC's name, or the Source NPC name.

(Sorry, don't actually have time to play around with it @work/@school).

 
Last edited by a moderator:
By looking at the file, it removes the duplicate you name/on which duplicateremove() is called, or removes all duplicates if the NPC named/called from is the source NPC. From the example above, if you'll PM "DupTest", it will remove all duplicates, if you'll PM "Duplicated", only that one duplicate will be removed.

Thank you for release!

 
Sweet mother of god! This, just made things sooo much better. Now I can rewrite sooo many scripts that rely on hard-coded duplicates, and just soft-duplicate them when needed and then remove. Efficiency + Over 100% less resource consumption since they don't all need to be active at once anymore.

Thanks, Dastgir. Though it sucks school started for me... not much time to play with it T.T;

Edit:

Just 1 question. The duplicateremove command. Does it work in such that, it can remove just 1 duplicate or all if so chosen?

Because, I had originally hoped that, we'd be able to remove 1 specific duplicate and/or all of them, by specifying either a DuplicateNPC's name, or the Source NPC name.

(Sorry, don't actually have time to play around with it @work/@school).
Garr mentioned it right,In duplicateremov, put the duplicated NPC name, then that duplicated NPC will only be removed. If you put the source NPC name, it will remove all duplicate.

 
First of all, thanks for this great plugin
default_biggrin.png
This is just so cool, and better than before x), but i was wondering if it was possible that every duplicated npc have their own npc variable.

Because for now, they share their variable. And i would need them to have their own variable.

Also duplicated npc doesn't trigger the OnInit label, I know that this is because the map-server is already loaded when my npc is duplicated but i would be cool to be able to set up a little bit our npc. For the moment i call the OnInit label trough a donpcevent.

Thx
default_smile.png


 
Last edited by a moderator:
@@Khazou - If I'm not mistaken, NPC's & their duplicates share the same npc_variables as an intended feature in Hercules (rA as well I think).

You can test this by making an NPC, and hardcoding a duplicate (the default way) and setting a variable, it should set it for both of them.

Either way, whether they share or not, there is a small fix you can do on the script side to make it work as you want. All you would need to do is set the variables using setd/getd and add extra information to it, in this case you can just add the duplicates unique name to the variable.

Ex:

Code:
setd ".variable_name"+ strnpcinfo(3) +"$", "data_here";
 
Last edited by a moderator:
I usually have npc name as

Abc#2

Then set variae in array and use index as 2 using strnpcinfo

 
Ok thanks for your advice i wasn't sure if it was a good method
default_smile.png


I will use setd and getd then, do npc have a maximum of npc variable ?

 
Last edited by a moderator:
Ok thanks for your advice i wasn't sure if it was a good method
default_smile.png


I will use setd and getd then, do npc have a maximum of npc variable ?
No limits...
 
Last edited by a moderator:
Seems like it's not working on lastest Hercules revisions.

Or maybe it's just me. Can anyone confirm ?

 
Seems like it's not working on lastest Hercules revisions.

Or maybe it's just me. Can anyone confirm ?
Tested, its not working properly and throws an error:

[Error]: map_addblock: bl->prev != NULL


if @dastgir can see it would be fantastic

pd: Tested with the lasted Hercules in git

UPDATE:

Implementing my own version of the plugin Based on this one, i get the error.

you have to change this line:

npc->duplicate_sub(nd_source, nd_target, txs, tys, NPO_ONINIT);

to this:

npc->duplicate_sub(nd_target, nd_source, txs, tys, NPO_ONINIT);

and it work perfect

 
Last edited by a moderator:
Could anyone please update this plugin?
Error say's that are to many arguments near this

 

Code:
if (nd != NULL) {
		st->state = END;
		if(nd->src_id == 0) {  // Remove All Duplicates
			npc->unload_duplicates(nd);
			npc->unload(nd, true);
		} else { // Remove single duplicate
			npc->unload(nd, true);
			if (nd->u.scr.script) {
				script->free_code(nd->u.scr.script);
				nd->u.scr.script = NULL;
			}
		}
		npc->read_event_script();
	}
 
Can anyone please update this?
Map server crashing when using the 
duplicateremove

Thread 1 "map-server" received signal SIGSEGV, Segmentation fault.
script_free_code (code=0xfdfdfdfdfdfdfdfd) at script.c:4199
4199            if (code->instances)

 
Back
Top