diff options
-rw-r--r-- | doc/script_commands.txt | 17 | ||||
-rw-r--r-- | src/map/script.c | 33 | ||||
-rw-r--r-- | src/map/script.h | 1 | ||||
-rw-r--r-- | src/plugins/generate-translations.c | 4 |
4 files changed, 54 insertions, 1 deletions
diff --git a/doc/script_commands.txt b/doc/script_commands.txt index fea7b3c3b..f0758de71 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -1235,6 +1235,23 @@ Clicking Google will open the browser and point to Google website. --------------------------------------- +*mesf("<format>"{,<param>{, <param>{, ...}}}) + +This command will display a box on the screen for the invoking character, +if no such box is displayed already, and will print the string specified +into that box, after applying the same format-string replacements as sprintf(). + +Example: + + mesf("Hello, I'm %s, a level %d %s", strcharinfo(PC_NAME), BaseLevel, jobname(Class)); + // is equivalent to: + mes(sprintf("Hello, I'm %s, a level %d %s", strcharinfo(PC_NAME), BaseLevel, jobname(Class))); + +This command is a combination of mes() and sprintf(). See their documentation +for more details. + +--------------------------------------- + *next; This command will display a 'next' button in the message window for the 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 "<message>"; + * @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; } } |