Dynamic Conversation Options

Users who are viewing this thread

Kaylum

Recruit
Hi all,

Trying to mod in a conversation with a companion in bannerlord which has dynamic options for the player to choose from. I naively added this code to populate the conversation options, this is called when the check if the conversation option is valid just before returning true or false to determine if the conversation can be started:
C#:
for (int i = 0; i < candidateSettlements.Count; i++)
{
  TextObject settlementName = candidateSettlements[i].Name;
  obj.AddRepeatablePlayerLine("make_companions_vassals_choose_settlement_option_choice", "make_companions_vassals_choose_settlement", "close_window", candidateSettlements[i].Name.ToString(), () => true, () => CreateVassal(settlementName));
}

However this leads to every time you close and open the conversation the settlement options keep getting added see the screenshots below:
vRr68pH.png

zjs9Wxm.png


Any help would be appreciated!
 
Last edited by a moderator:
I found a fix for this, you have to clear down options here is the method I found
C#:
public static void CleanRepeatableLine(CampaignGameStarter cgs, string id)
{
    FieldInfo field1 = cgs.GetType().GetField("_conversationManager", BindingFlags.Instance | BindingFlags.NonPublic);
    if (field1.GetValue(cgs) == null)
    {
        return;
    }
    ConversationManager cm = (ConversationManager)field1.GetValue(cgs);
    FieldInfo field2 = cm.GetType().GetField("_sentences", BindingFlags.Instance | BindingFlags.NonPublic);
    if (field2 != null)   
    {
        ((List<ConversationSentence>)field2.GetValue(cm)).RemoveAll(s => id == s.Id);
    }
}
 
Upvote 0
Back
Top Bottom