Implemented dynamic NPCs (#7402)
This is required for features like #6640 Added COLOR_LIGHT_YELLOW Cleaned up color definitions, its useless to store them as string first. Dynamic NPCs will stay when you switch map and come back in time. Dynamic NPCs will be removed instantly when you log out. You can only create one dynamic NPC at a time. Thanks to @Atemo!
This commit is contained in:
@@ -25193,7 +25193,40 @@ BUILDIN_FUNC(duplicate)
|
||||
ys = nd->u.scr.ys;
|
||||
}
|
||||
|
||||
npc_data* dnd = npc_duplicate_npc( nd, name, mapid, x, y, class_, dir, xs, ys );
|
||||
npc_data* dnd = npc_duplicate_npc( *nd, name, mapid, x, y, class_, dir, xs, ys );
|
||||
|
||||
if( dnd == nullptr ){
|
||||
script_pushstrcopy( st, "" );
|
||||
return SCRIPT_CMD_FAILURE;
|
||||
}else{
|
||||
script_pushstrcopy( st, dnd->exname );
|
||||
return SCRIPT_CMD_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate a NPC for a player.
|
||||
* Return the duplicate Unique name on success or empty string on failure.
|
||||
* duplicate_dynamic("<NPC name>"{,<character ID>});
|
||||
*/
|
||||
BUILDIN_FUNC(duplicate_dynamic){
|
||||
const char* old_npcname = script_getstr( st, 2 );
|
||||
struct npc_data* nd = npc_name2id( old_npcname );
|
||||
|
||||
if( nd == nullptr ){
|
||||
ShowError( "buildin_duplicate_dynamic: No such NPC '%s'.\n", old_npcname );
|
||||
script_pushstrcopy( st, "" );
|
||||
return SCRIPT_CMD_FAILURE;
|
||||
}
|
||||
|
||||
struct map_session_data* sd;
|
||||
|
||||
if( !script_charid2sd( 3, sd ) ){
|
||||
script_pushstrcopy( st, "" );
|
||||
return SCRIPT_CMD_FAILURE;
|
||||
}
|
||||
|
||||
struct npc_data* dnd = npc_duplicate_npc_for_player( *nd, *sd );
|
||||
|
||||
if( dnd == nullptr ){
|
||||
script_pushstrcopy( st, "" );
|
||||
@@ -27427,6 +27460,7 @@ struct script_function buildin_func[] = {
|
||||
BUILDIN_DEF(openstorage2,"ii?"),
|
||||
BUILDIN_DEF(unloadnpc, "s"),
|
||||
BUILDIN_DEF(duplicate, "ssii?????"),
|
||||
BUILDIN_DEF(duplicate_dynamic, "s?"),
|
||||
|
||||
// WoE TE
|
||||
BUILDIN_DEF(agitstart3,""),
|
||||
|
||||
Reference in New Issue
Block a user