• 0
neXus

Help on converting this to rA

Question

Can anyone help me on converting this src code to rathena.

// duplicatenpc("NpcName", "DuplicateName", "DupHiddenName", "map", x, y, dir{, sprite{, xs, ys}});
BUILDIN(duplicatenpc)
{
	const char *npc_name = script_getstr(st, 2);
	const char *dup_name = script_getstr(st, 3);
	const char *dup_hidden_name = script_getstr(st, 4);
	const char *tmap = script_getstr(st, 5);
	int tx = script_getnum(st, 6);
	int ty = script_getnum(st, 7);
	int tdir = script_getnum(st, 8);
	int tclass_, txs = -1, tys = -1, tmapid;
	struct npc_data *nd_source, *nd_target;
	char targetname[24] = "";

	if(script_hasdata(st, 10))
		txs = (script_getnum(st, 10) < -1) ? -1 : script_getnum(st, 10);
	if(script_hasdata(st, 11))
		tys = (script_getnum(st, 11) < -1) ? -1 : script_getnum(st, 10);

	if(txs == -1 && tys != -1)
		txs = 0;
	if(txs != - 1 && tys == -1)
		tys = 0;

	if(strlen(dup_name) + strlen(dup_hidden_name) > NAME_LENGTH)
	{
		ShowError("duplicatenpc: Name#HiddenName is to long (max %d chars). (%s)\n",NAME_LENGTH, npc_name);
		script_pushint(st, 0);
		return 0;
	}

	nd_source = npc->name2id(npc_name);

	if(script_hasdata(st, 9))
		tclass_ = (script_getnum(st, 9) < -1) ? -1 : script_getnum(st, 9);
	else
		tclass_ = nd_source->class_;

	if( nd_source == NULL)
	{
		ShowError("duplicatenpc: original npc not found for duplicate. (%s)\n", npc_name);
		script_pushint(st, 0);
		return 0;
	}

	tmapid = map->mapname2mapid(tmap);
	if(tmapid < 0)
	{
		ShowError("duplicatenpc: target map not found. (%s)\n", tmap);
		script_pushint(st, 0);
		return 0;
	}

	nd_target = npc->create_npc(nd_source->subtype, tmapid, tx, ty, tdir, tclass_);
	strcat(targetname, dup_name);
	strncat(targetname, "#", 1);
	strncat(targetname, dup_hidden_name, strlen(dup_hidden_name));

	safestrncpy(nd_target->name, targetname , sizeof(nd_target->name));
	safestrncpy(nd_target->exname, targetname, sizeof(nd_target->exname));

	npc->duplicate_sub(nd_source, nd_target, txs, tys, NPO_ONINIT);
	
	
	script_pushint(st, 1);
	return true;
}
BUILDIN(duplicateremove)
{
	struct npc_data *nd;

	if(script_hasdata(st, 2))
	{
		nd = npc->name2id(script_getstr(st, 2));
		if(nd == NULL)
		{
			ShowError("duplicateremove: NPC not found: %s\n", script_getstr(st, 2));
			script_pushint(st, -1);
			return 0;
		}
	}
	else
		nd = (struct npc_data *)map->id2bl(st->oid);

	if (nd == NULL){
	}else if(nd->src_id == 0){	//remove all dupicates for this source npc
		map->foreachnpc(npc->unload_dup_sub,nd->bl.id);
	}else// just remove this duplicate
		npc->unload(nd,true);

	script_pushint(st, 1);
	return true;
}

 

Share this post


Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

I just wanna ask, does this code duplicates an npc?

<map>,<x>,<y>,<pos><TAB>duplicate(<NPCs name source>)<TAB><DUPLICATENPCNAME>#<UNIQUE IDENTIFIER><TAB><SPRITE>
alberta,25,240,6	duplicate(Healer)	Healer#alb	909

Well, if it is in a script command, maybe do a:

*disablenpc "<NPC object name>";

*enablenpc "<NPC object name>";
  
*unloadnpc "<NPC object name>"; // 
This command will fully unload a NPC object and all of it's duplicates.

*doevent "<NPC object name>::<event label>";

or just search what you need here: 

https://github.com/rathena/rathena/blob/master/doc/script_commands.txt

Edited by pajodex

Share this post


Link to post
Share on other sites
  • 0

yes it will duplicate NPC but the difference is this function will work inside the script. unlike the usual duplicate it works outside the script only.

Share this post


Link to post
Share on other sites
  • 0

I'm not sure on how you want it to work, did you try to use:

*disablenpc
*enablenpc

or the likes of it? You can search at /doc/script_commands.txt, maybe it already exist in rA. If not, you can wait for someone to convert it. /heh

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now