Jump to content
  • 0

Help on converting this to rA


Question

Posted

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;
}

 

3 answers to this question

Recommended Posts

  • 0
Posted (edited)

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

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...