From 9164ea7ec938958245e1ceb75035f90500c8a7c8 Mon Sep 17 00:00:00 2001 From: Haru Date: Sat, 18 Jun 2016 00:19:39 +0200 Subject: Added mesf() command (combination of mes() and sprintf()) Signed-off-by: Haru --- src/map/script.c | 33 +++++++++++++++++++++++++++++++++ src/map/script.h | 1 + src/plugins/generate-translations.c | 4 +++- 3 files changed, 37 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/map/script.c b/src/map/script.c index 926f19bf0..a6a9a9cf9 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -5487,6 +5487,37 @@ BUILDIN(mes) return true; } +/** + * Appends a message to the npc dialog, applying format string conversions (see + * sprintf). + * + * If a dialog doesn't exist yet, one is created. + * + * @code + * mes ""; + * @endcode + */ +BUILDIN(mesf) +{ + struct map_session_data *sd = script->rid2sd(st); + struct StringBuf buf; + + if (sd == NULL) + return true; + + StrBuf->Init(&buf); + + if (!script_sprintf(st, 2, &buf)) { + StrBuf->Destroy(&buf); + return false; + } + + clif->scriptmes(sd, st->oid, StrBuf->Value(&buf)); + StrBuf->Destroy(&buf); + + return true; +} + /// Displays the button 'next' in the npc dialog. /// The dialog text is cleared and the script continues when the button is pressed. /// @@ -20275,6 +20306,7 @@ bool script_add_builtin(const struct script_function *buildin, bool override) { else if( strcmp(buildin->name, "callfunc") == 0 ) script->buildin_callfunc_ref = n; else if( strcmp(buildin->name, "getelementofarray") == 0 ) script->buildin_getelementofarray_ref = n; else if( strcmp(buildin->name, "mes") == 0 ) script->buildin_mes_offset = script->buildin_count; + else if( strcmp(buildin->name, "mesf") == 0 ) script->buildin_mesf_offset = script->buildin_count; else if( strcmp(buildin->name, "select") == 0 ) script->buildin_select_offset = script->buildin_count; else if( strcmp(buildin->name, "_") == 0 ) script->buildin_lang_macro_offset = script->buildin_count; else if( strcmp(buildin->name, "_$") == 0 ) script->buildin_lang_macro_fmtstring_offset = script->buildin_count; @@ -20372,6 +20404,7 @@ void script_parse_builtin(void) { // NPC interaction BUILDIN_DEF(mes,"s"), + BUILDIN_DEF(mesf,"s*"), BUILDIN_DEF(next,""), BUILDIN_DEF(close,""), BUILDIN_DEF(close2,""), diff --git a/src/map/script.h b/src/map/script.h index 7811cd64e..61c6a4583 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -623,6 +623,7 @@ struct script_interface { const char *parser_current_npc_name; /* */ int buildin_mes_offset; + int buildin_mesf_offset; int buildin_select_offset; int buildin_lang_macro_offset; int buildin_lang_macro_fmtstring_offset; diff --git a/src/plugins/generate-translations.c b/src/plugins/generate-translations.c index 7928fec9c..0f69c69a1 100644 --- a/src/plugins/generate-translations.c +++ b/src/plugins/generate-translations.c @@ -116,7 +116,9 @@ void script_add_translatable_string_posthook(const struct script_string_buf *str || script->syntax.lang_macro_active ) { is_translatable_string = true; - } else if (script->syntax.lang_macro_fmtstring_active) { + } else if (script->syntax.last_func == script->buildin_mesf_offset + || script->syntax.lang_macro_fmtstring_active + ) { is_translatable_fmtstring = true; } } -- cgit v1.2.3-70-g09d2