Making a party follow players party

Users who are viewing this thread

I'm having a bit of trouble getting a party to follow my party. Obviously I'm missing something. The basecode is this. Basically, I'm listening to when a conversation is started and trying to change the beheviour that the conversation party would follow me after the conversation. They will follow for a few seconds, which after they will go back to their normal state. I reckon something needs to be reset maybe?


C#:
        private void conversationListener()
        {
            MobileParty party = MobileParty.ConversationParty;
            MobileParty myParty = MobileParty.MainParty;
            

            MobileParty.ConversationParty.ResetTargetParty();
            MobileParty.ConversationParty.ResetAiBehaviorObject();
            MobileParty.ConversationParty.SetMoveGoAroundParty(myParty);
            SetPartyAiAction.GetActionForGoingAroundParty(party,  myParty);
            InformationManager.DisplayMessage(new InformationMessage("Conversation started with leader" + party));
        }
 
There seems to be two event dispaters for this.
C++:
            CampaignEvents.TickPartialHourlyAiEvent.AddNonSerializedListener((object) this, new Action(this.HourlyTick));
            CampaignEvents.AiHourlyTickEvent.AddNonSerializedListener((object) this, new Action<MobileParty, PartyThinkParams>(this.HourlyTick));

I'm going to try take a closer look if I can get anything going using these events.
 
Upvote 0
Alright, I've made progress. I had some misconceptions on how you should use CampaignBehaviourBase. Basically, if I understood correctly, each behaviour just subscribes to party hourly ticks and does conditional checking on what to do with the party. I originally thought the whole Behaviour base instance is applied conditionally, instead of each behaviour subscribing to tick events.

I managed to get companion parties to follow my party. However, they try to stray off once or twice per day, for a few seconds, and then they come back. So there is still something that I'm missing. It works by talking to your companions party and just leaving the conversation. Id like to add an option to the menu to select them to follow you. Any ideas?

Heres the code so far.

C#:
        private void conversationListener()
        {
            _myParty = MobileParty.MainParty;

            //CampaignEvents.HourlyTickPartyEvent.AddNonSerializedListener((_followerParty), this.HourlyTick);

            CampaignEvents.HourlyTickPartyEvent.AddNonSerializedListener((object) this, new Action<MobileParty>(this.HourlyTick));


            InformationManager.DisplayMessage(new InformationMessage("Conversation started with leader" + _followerParty));
        }

        private void HourlyTick(MobileParty mobileParty)
        {
            if (mobileParty.LeaderHero != null && mobileParty.LeaderHero.Clan != null && mobileParty.LeaderHero.Clan == Clan.PlayerClan && mobileParty.LeaderHero.Name != _myParty.LeaderHero.Name)
            {
                mobileParty.SetInititave(0.33f, 1f, 24f);
                _followerParty.SetMoveEscortParty(_myParty);
                SetPartyAiAction.GetActionForEscortingParty(mobileParty, _myParty);
                InformationManager.DisplayMessage(new InformationMessage("Conversation started with leader" + _followerParty));
            }
        }
 
Upvote 0
Nothing to add, just wanted to say thanks for sharing your progress here. It's not a problem I'm currently working on for my own mod, but I'm sure this thread will be handy for anyone who's working on a similar issue
 
Upvote 0
Nothing to add, just wanted to say thanks for sharing your progress here. It's not a problem I'm currently working on for my own mod, but I'm sure this thread will be handy for anyone who's working on a similar issue

Hopefully this will be of use to somebody. I've played around, trying to find a way to add new options to conversations. However, I haven't had much luck. I did find this though, which to my understanding should add a new option to the conversation. However, game crashes with a null reference, which I wasn't able to solve yet. Any ideas?

C#:
            TextObject _test = new TextObject("test");
            Campaign.Current.ConversationManager.AddToCurrentOptions(_test, "followMe", true, _test);
 
Upvote 0
Hopefully this will be of use to somebody. I've played around, trying to find a way to add new options to conversations. However, I haven't had much luck. I did find this though, which to my understanding should add a new option to the conversation. However, game crashes with a null reference, which I wasn't able to solve yet. Any ideas?

C#:
            TextObject _test = new TextObject("test");
            Campaign.Current.ConversationManager.AddToCurrentOptions(_test, "followMe", true, _test);
Do you have a stack trace? Also, the "skip dialogues" mod added menu options, you can decompile that to see how he did it.
 
Last edited:
Upvote 0
You should be able to add dialogue through the CampaignGameStarter object that is passed as a parameter.

For instance, onGameStart in MBSubModuleBase has an IGameStarter parameter that you could use.

Something like:

C#:
protected override void OnGameStart(Game game, IGameStarter gameStarterObject)
{
    base.OnGameStart(game, gameStarterObject);
    if (gameStarterObject is CampaignGameStarter starter)
        starter.AddPlayerLine("companion_follow_request", "whatever_dialogue_id_this_responds_to", "companion_response_id", "Follow me.", someConditionDelegate, someConsequenceDelegate);
}

The trouble will be finding the companion dialogue start id (for the second parameter), setting up the condition delegate that will cause this to appear (e.g. companion is leading a party of their own), and then setting up the consequence delegate to start your following behavior.

I'd open up dnSpy and read over some of the campaign behavior classes in TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors. They're in the Sandbox module, and most of them involve adding dialogue lines and using the responses to change behavior.
 
Last edited:
Upvote 0
Back
Top Bottom