From c34cd6898f05357e1b056bd483ea0da12fed066d Mon Sep 17 00:00:00 2001 From: vietlubu Date: Sun, 14 Jan 2024 20:10:55 +0700 Subject: [PATCH 1/3] Allow call openlapineupgradeui() and openlapineupgradeui() without itemid --- doc/script_commands.txt | 4 ++-- src/map/script.c | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 08ddf2b376d..69d21c73390 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -10997,13 +10997,13 @@ Opens refinery user interface for the player returns true on success and false on failure --------------------------------------- -*openlapineddukddakboxui() +*openlapineddukddakboxui({}) Opens lapine ddukddak user interface for the player returns true on success and false on failure --------------------------------------- -*openlapineupgradeui() +*openlapineupgradeui({}) Opens lapine ddukddak upgrade user interface for the player returns true on success and false on failure diff --git a/src/map/script.c b/src/map/script.c index 843cd817461..3d2773eaa8b 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27941,7 +27941,7 @@ static BUILDIN(openlapineddukddakboxui) struct map_session_data *sd = script_rid2sd(st); if (sd == NULL) return false; - const int item_id = script_getnum(st, 2); + const int item_id = (script_getnum(st, 2) == 0) ? sd->itemid : script_getnum(st, 2); struct item_data *it = itemdb->exists(item_id); if (it == NULL) { ShowError("buildin_openlapineddukddakboxui: Item %d is not valid\n", item_id); @@ -27962,7 +27962,8 @@ static BUILDIN(openlapineupgradeui) if (sd == NULL) return false; - const int item_id = script_getnum(st, 2); + const int item_id = (script_getnum(st, 2) == 0) ? sd->itemid : script_getnum(st, 2); + struct item_data *it = itemdb->exists(item_id); if (it == NULL || it->lapineupgrade == NULL) { ShowError("buildin_openlapineupgradeui: Item %d is not valid\n", item_id); @@ -29183,8 +29184,8 @@ static void script_parse_builtin(void) BUILDIN_DEF(identify, "i"), BUILDIN_DEF(identifyidx, "i"), - BUILDIN_DEF(openlapineddukddakboxui, "i"), - BUILDIN_DEF(openlapineupgradeui, "i"), + BUILDIN_DEF(openlapineddukddakboxui, "?"), + BUILDIN_DEF(openlapineupgradeui, "?"), BUILDIN_DEF(callfunctionofnpc, "vs*"), From 774ce183ce58a8b822fa8637620db599f0ad54c5 Mon Sep 17 00:00:00 2001 From: vietlubu Date: Thu, 18 Jan 2024 15:47:02 +0700 Subject: [PATCH 2/3] Update get item condition. suport open UI by item name --- doc/script_commands.txt | 2 ++ src/map/script.c | 57 ++++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index 69d21c73390..1eefdfcb025 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -10998,12 +10998,14 @@ returns true on success and false on failure --------------------------------------- *openlapineddukddakboxui({}) +*openlapineddukddakboxui({}) Opens lapine ddukddak user interface for the player returns true on success and false on failure --------------------------------------- *openlapineupgradeui({}) +*openlapineupgradeui({}) Opens lapine ddukddak upgrade user interface for the player returns true on success and false on failure diff --git a/src/map/script.c b/src/map/script.c index 3d2773eaa8b..2a9f2698b6e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27941,16 +27941,37 @@ static BUILDIN(openlapineddukddakboxui) struct map_session_data *sd = script_rid2sd(st); if (sd == NULL) return false; - const int item_id = (script_getnum(st, 2) == 0) ? sd->itemid : script_getnum(st, 2); - struct item_data *it = itemdb->exists(item_id); - if (it == NULL) { - ShowError("buildin_openlapineddukddakboxui: Item %d is not valid\n", item_id); + + struct item_data *it = NULL; + if (script_hasdata(st, 2)) { + if (script_isstring(st, 2)) { + const char *item_name = script_getstr(st, 2); + it = itemdb->search_name(item_name); + if (it == NULL) { + ShowError("buildin_openlapineddukddakboxui: Item %s is not valid\n", item_name); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + } else { + it = itemdb->exists(script_getnum(st, 2)); + } + } else { + if (sd->itemid > 0) { + it = itemdb->exists(sd->itemid); + } + } + + if (it == NULL || it->lapineddukddak == NULL) { + ShowError("buildin_openlapineddukddakboxui: Item Id %d is not valid\n", it->nameid); script->reportfunc(st); script->reportsrc(st); script_pushint(st, false); return true; } - clif->lapineDdukDdak_open(sd, item_id); + + clif->lapineDdukDdak_open(sd, it->nameid); script_pushint(st, true); return true; } @@ -27962,18 +27983,36 @@ static BUILDIN(openlapineupgradeui) if (sd == NULL) return false; - const int item_id = (script_getnum(st, 2) == 0) ? sd->itemid : script_getnum(st, 2); + struct item_data *it = NULL; + if (script_hasdata(st, 2)) { + if (script_isstring(st, 2)) { + const char *item_name = script_getstr(st, 2); + it = itemdb->search_name(item_name); + if (it == NULL) { + ShowError("buildin_openlapineupgradeui: Item %s is not valid\n", item_name); + script->reportfunc(st); + script->reportsrc(st); + script_pushint(st, false); + return true; + } + } else { + it = itemdb->exists(script_getnum(st, 2)); + } + } else { + if (sd->itemid > 0) { + it = itemdb->exists(sd->itemid); + } + } - struct item_data *it = itemdb->exists(item_id); if (it == NULL || it->lapineupgrade == NULL) { - ShowError("buildin_openlapineupgradeui: Item %d is not valid\n", item_id); + ShowError("buildin_openlapineupgradeui: Item Id %d is not valid\n", it->nameid); script->reportfunc(st); script->reportsrc(st); script_pushint(st, false); return true; } - clif->lapineUpgrade_open(sd, item_id); + clif->lapineUpgrade_open(sd, it->nameid); script_pushint(st, true); return true; } From 08a9688ef363595a504ce008414ef7a4c6d6cdb0 Mon Sep 17 00:00:00 2001 From: vietlubu Date: Tue, 12 Mar 2024 16:24:03 +0700 Subject: [PATCH 3/3] Check it if that NULL before show error message --- src/map/script.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/map/script.c b/src/map/script.c index 2a9f2698b6e..73a3cc962c5 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -27964,7 +27964,11 @@ static BUILDIN(openlapineddukddakboxui) } if (it == NULL || it->lapineddukddak == NULL) { - ShowError("buildin_openlapineddukddakboxui: Item Id %d is not valid\n", it->nameid); + if (it != NULL) { + ShowError("buildin_openlapineddukddakboxui: Item Id %d is not valid\n", it->nameid); + } else { + ShowError("buildin_openlapineddukddakboxui: Item is NULL\n"); + } script->reportfunc(st); script->reportsrc(st); script_pushint(st, false); @@ -28005,7 +28009,11 @@ static BUILDIN(openlapineupgradeui) } if (it == NULL || it->lapineupgrade == NULL) { - ShowError("buildin_openlapineupgradeui: Item Id %d is not valid\n", it->nameid); + if (it != NULL) { + ShowError("buildin_openlapineddukddakboxui: Item Id %d is not valid\n", it->nameid); + } else { + ShowError("buildin_openlapineddukddakboxui: Item is NULL\n"); + } script->reportfunc(st); script->reportsrc(st); script_pushint(st, false);