Reborn Posted January 13, 2018 Group: Members Topic Count: 104 Topics Per Day: 0.02 Content Count: 290 Reputation: 3 Joined: 09/29/13 Last Seen: December 28, 2024 Share Posted January 13, 2018 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; } Quote Link to comment Share on other sites More sharing options...
0 pajodex Posted January 14, 2018 Group: Members Topic Count: 79 Topics Per Day: 0.03 Content Count: 439 Reputation: 173 Joined: 12/12/17 Last Seen: Monday at 05:33 PM Share Posted January 14, 2018 (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 January 14, 2018 by pajodex Quote Link to comment Share on other sites More sharing options...
0 Reborn Posted January 14, 2018 Group: Members Topic Count: 104 Topics Per Day: 0.02 Content Count: 290 Reputation: 3 Joined: 09/29/13 Last Seen: December 28, 2024 Author Share Posted January 14, 2018 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. Quote Link to comment Share on other sites More sharing options...
0 pajodex Posted January 14, 2018 Group: Members Topic Count: 79 Topics Per Day: 0.03 Content Count: 439 Reputation: 173 Joined: 12/12/17 Last Seen: Monday at 05:33 PM Share Posted January 14, 2018 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. Quote Link to comment Share on other sites More sharing options...
Question
Reborn
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; }
Link to comment
Share on other sites
3 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.