Skip to content

Commit

Permalink
talk_print console command
Browse files Browse the repository at this point in the history
Helper to output talk text to console by ID. Tokens are routed through TalkManager MCP. When there are multiple sub-records for this ID, one will be selected at random.
Using this to debug a localization issue. Adding to master as it might come in handy for someone else in the future.
  • Loading branch information
Interkarma committed Oct 10, 2023
1 parent 8fc527a commit fa56017
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Assets/Scripts/Game/TalkManager.cs
Expand Up @@ -3531,7 +3531,7 @@ private string GetAnswerFromTokensArray(ulong questID, List<TextFile.Token[]> an
return TokensToString(tokens);
}

private string TokensToString(TextFile.Token[] tokens, bool addSpaceAtTokenEnd = true)
public static string TokensToString(TextFile.Token[] tokens, bool addSpaceAtTokenEnd = true)
{
// Create return string from expanded tokens
string separatorString = " ";
Expand Down Expand Up @@ -3614,6 +3614,7 @@ public static void RegisterCommands()
ConsoleCommandsDatabase.RegisterCommand(TalkNpcsKnowEverything.name, TalkNpcsKnowEverything.description, TalkNpcsKnowEverything.usage, TalkNpcsKnowEverything.Execute);
ConsoleCommandsDatabase.RegisterCommand(TalkNpcsKnowUsual.name, TalkNpcsKnowUsual.description, TalkNpcsKnowUsual.usage, TalkNpcsKnowUsual.Execute);
ConsoleCommandsDatabase.RegisterCommand(TalkNpcBehaviorOverride.name, TalkNpcBehaviorOverride.description, TalkNpcBehaviorOverride.usage, TalkNpcBehaviorOverride.Execute);
ConsoleCommandsDatabase.RegisterCommand(TalkPrint.name, TalkPrint.description, TalkPrint.usage, TalkPrint.Execute);
}
catch (System.Exception ex)
{
Expand Down Expand Up @@ -3669,6 +3670,37 @@ public static string Execute(params string[] args)
return String.Format("NPC behaviors: " + GameManager.Instance.TalkManager.consoleCommand_NPCBehaviorOverride.ToString());
}
}

private static class TalkPrint
{
public static readonly string name = "talk_print";
public static readonly string description = "Output talk text from the RSC string database. ID must be a talk-related string. Record is selected at random.";
public static readonly string usage = "talk_print {id}";

public static string Execute(params string[] args)
{
if (args == null || args.Length < 1)
return usage;

int id;
if (!int.TryParse(args[0], out id))
return usage;

string output = "Nothing found.";
try
{
TextFile.Token[] tokens = DaggerfallUnity.Instance.TextProvider.GetRandomTokens(id);
MacroHelper.ExpandMacros(ref tokens, GameManager.Instance.TalkManager);
output = TokensToString(tokens);
}
catch (Exception ex)
{
output = string.Format("Command failed. ID {0} is not a talk string.", id);
}

return output;
}
}
}

#endregion
Expand Down

0 comments on commit fa56017

Please sign in to comment.