[Modding Question][1.4.3] Trying to add my own CampaignBehavior, need some tips

Currently Viewing (Users: 0, Guests: 1)

VolsungaSaga

Recruit
Best answers
0
Hello,

I made a little mod called Changeable Body Sliders , for the purpose of allowing you to change your character's weight and build. My next step is to have a campaign behavior that sets every Hero's body properties (that is, build and weight) to some calculated value based on their skills and attributes upon every DailyTick. I'm doing it like this, as opposed to only once when the campaign is fully loaded, because there's a DynamicBodyCampaignBehavior (in namespace TaleWorlds.CampaignSystem.SandBox.CampaignBehaviors, for the curious DLL trawler) that implements similar behavior on every daily tick. It gets loaded in Campaign.cs, so it is active in any campaign (as of 1.4.3). However, as I'm sure you are all aware, this behavior seems to not be working correctly and it tends to turn people into skeletons, like the Horseman of Famine.

I'd like to ask you guys a few questions:
  • It seems as though it's possible to remove a behavior via the RemoveBehavior<T>() function in CampaignManager, but is it advisable to use this function to get rid of the DynamicBodyCampaignBehavior? I feel as though that could break things pretty severely if misused.
    • If I can't remove a behavior safely (which would bring into question why such a method exists), is there any way to ensure that my DailyTick() event override fires after another DailyTick, so that any bad tick effects can be overridden by mine? The broader question: Is the order of event firing both deterministic and knowable?
  • Sort of unrelated, but there's a crash bug in my mod that happens when changing your gender after your maturity level is changed via the age slider (that is, you go from adult to tween,teen, etc.). This happens reproducibly, and it's too easy to make happen. So, is there a way to limit how far the age slider can go? I couldn't find anything in the FaceGenBody.xml file (I think that's what it's called, unsure). Ideally, I want to stop it from reaching the point at which the body's maturity type changes, wherever it happens to be. I know that Detailed Character Creation let you change yourself to a kid, but I'm not sure if it also had this bug and whether the underlying crash bug is in pre-1.4.2 builds of Bannerlord.
As I write this, ways to figure out all this information pop into my head, but I feel that this question would foster some healthy discussion and reveal new questions to ask that may not be so easily answered just by looking.
 

Midnightknight

Regular
WBWF&SVC
Best answers
4
For your first question, if a behavior have no interface, it is called only when registered in the event list. So yes it's safe to remove any behavior that have not any specific interface used to call it directly.
The answer might sound definitive but it might be some exceptions.
How events are triggered depends of your load order, so it's not that easy to tell who will fire first, and it's best to not really rely on this if you can, and if you plan to use threading with some wait or delay to achieve a delayed dailytick you should be extra careful about what you are changing cause no object in M&B2 is thread safe, meaning if they are modified by something else at the same time, you will mostly crash your game. And something else include other mods.

For your second question i have no clue, haven't time to check about this so far.