diff --git a/doc/script_commands.txt b/doc/script_commands.txt index b4daf38a12..2320056656 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -8199,14 +8199,14 @@ This feature requires packet version 2015-11-04 or newer. --------------------------------------- -*laphine_synthesis() +*laphine_synthesis({}) +*laphine_synthesis({<"item name">}) -Opens the laphine synthesis UI for the attached player. +Opens the laphine synthesis UI for or for the attached player. +If run from within an item script or is optional. This feature requires packet version 2016-06-01 or newer. -This function is intended for use in item scripts. - --------------------------------------- *laphine_upgrade() diff --git a/src/map/clif.cpp b/src/map/clif.cpp index 6bcc986e1b..1d84219e87 100644 --- a/src/map/clif.cpp +++ b/src/map/clif.cpp @@ -23246,21 +23246,24 @@ void clif_parse_laphine_synthesis( int fd, struct map_session_data* sd ){ } } - int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis ); + // If triggered from item + if( sd->itemid == sd->state.laphine_synthesis ){ + int16 index = pc_search_inventory( sd, sd->state.laphine_synthesis ); - if( index < 0 ){ - clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM ); - return; - } - - if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){ - if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){ + if( index < 0 ){ + clif_laphine_synthesis_result( sd, LAPHINE_SYNTHESIS_ITEM ); return; } + + if( ( sd->inventory_data[index]->flag.delay_consume & DELAYCONSUME_NOCONSUME ) == 0 ){ + if( pc_delitem( sd, index, 1, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){ + return; + } + } } for( size_t i = 0; i < count; i++ ){ - index = server_index( p->items[i].index ); + int16 index = server_index( p->items[i].index ); if( pc_delitem( sd, index, p->items[i].count, 0, 0, LOG_TYPE_LAPHINE ) != 0 ){ return; diff --git a/src/map/script.cpp b/src/map/script.cpp index e61782653d..64b69d34da 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -25959,14 +25959,40 @@ BUILDIN_FUNC( laphine_synthesis ){ return SCRIPT_CMD_FAILURE; } - if( sd->itemid == 0 ){ - ShowError( "buildin_laphine_synthesis: Called outside of an item script without item id.\n" ); - return SCRIPT_CMD_FAILURE; - } + t_itemid item_id; - if( sd->inventory_data[sd->itemindex]->flag.delay_consume == 0 ){ - ShowError( "buildin_laphine_synthesis: Called from item %u, which is not a consumed delayed.\n", sd->itemid ); - return SCRIPT_CMD_FAILURE; + if( script_hasdata( st, 2 ) ){ + if( script_isstring( st, 2 ) ){ + const char* item_name = script_getstr( st, 2 ); + + std::shared_ptr item = item_db.searchname( item_name ); + + if( item == nullptr ){ + ShowError("buildin_laphine_synthesis: Item \"%s\" does not exist.\n", item_name ); + return SCRIPT_CMD_FAILURE; + } + + item_id = item->nameid; + }else{ + item_id = script_getnum( st, 2 ); + + if( !item_db.exists( item_id ) ){ + ShowError( "buildin_laphine_synthesis: Item ID %u does not exist.\n", item_id ); + return SCRIPT_CMD_FAILURE; + } + } + }else{ + if( sd->itemid == 0 ){ + ShowError( "buildin_laphine_synthesis: Called outside of an item script without item id.\n" ); + return SCRIPT_CMD_FAILURE; + } + + if( sd->inventory_data[sd->itemindex]->flag.delay_consume == 0 ){ + ShowError( "buildin_laphine_synthesis: Called from item %u, which is not a consumed delayed.\n", sd->itemid ); + return SCRIPT_CMD_FAILURE; + } + + item_id = sd->itemid; } if( sd->state.laphine_synthesis != 0 ){ @@ -25974,10 +26000,10 @@ BUILDIN_FUNC( laphine_synthesis ){ return SCRIPT_CMD_FAILURE; } - std::shared_ptr synthesis = laphine_synthesis_db.find( sd->itemid ); + std::shared_ptr synthesis = laphine_synthesis_db.find( item_id ); if( synthesis == nullptr ){ - ShowError( "buildin_laphine_synthesis: %u is not a valid Laphine Synthesis item.\n", sd->itemid ); + ShowError( "buildin_laphine_synthesis: %u is not a valid Laphine Synthesis item.\n", item_id ); return SCRIPT_CMD_FAILURE; } @@ -27035,7 +27061,7 @@ struct script_function buildin_func[] = { BUILDIN_DEF(navihide, ""), BUILDIN_DEF(getitempos,""), - BUILDIN_DEF(laphine_synthesis, ""), + BUILDIN_DEF(laphine_synthesis, "?"), BUILDIN_DEF(laphine_upgrade, ""), BUILDIN_DEF(randomoptgroup,"i"), BUILDIN_DEF(open_quest_ui, "??"),