Official Module System Documentation: Part 04

From Mount&Blade Modding Wiki
Revision as of 16:43, 25 June 2012 by Swyter (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


In Part 2 of this documentation, we learned how to make new parties; unique locations on the map. They are not to be confused with party templates, which we will be addressing here.

In the simplest terms, party templates are a set of guidelines from which parties on the map are spawned. This marks the most notable difference between parties and party templates -- parties are unique entities on the map, whereas templates do not physically exist in the game world. They serve only as a list of guidelines from which to spawn parties. Therefore, certain operations that use a party_id for input will not work when they are fed a party_template_id.

Parties that are spawned from a template do not have to be unique. There can be many parties of the same template; each will have a random number of troops depending on the player's level and the minimum/maximum troop limits defined in the template.


[edit] 4.1 -- Breakdown of Module_Party_Templates

The file begins with the usual Python list: party_templates = [, followed by several templates that are hardwired into the game and should not be edited.

You'll notice that the tuples in module_party_templates are very similar to those in module_parties, but the two are not interchangeable.

Example of a party template:

 ("farmers","farmers",icon_peasant|pf_auto_start_dialog,0,fac_innocents,merchant_personality,[(trp_farmer,11,22),(trp_peasant_woman,16,44)]),

Here is a template we've all encountered in-game. Parties of this template will be called "farmers", they will automatically start dialogue when you encounter one, they will behave cowardly in-game, and they each have two troop stacks made up of farmers and peasant women.


Breakdown of the tuple fields:

1 ) Party-template id. Used for referencing party-templates in other files. 2 ) Party-template name. The name that parties of this template will use. 3 ) Party flags. You will notice that all templates in module_party_templates have pf_auto_start_dialogue set. This flag will automatically start a map dialogue when the player encounters a party of this template. 4 ) Menu. Deprecated as in module_parties. Use the value 0 here. 5 ) Faction. 6 ) Personality. This field contains flags which determine party behaviour on the map. 7 ) List of stacks. Each stack record is a tuple that contains the following fields:

   7.1) Troop-id. 
   7.2) Minimum number of troops in the stack. 
   7.3) Maximum number of troops in the stack. 
   7.4) Member flags(optional). You will have to add an extra field in order to set member flags. For example, (trp_swadian_crossbowman,5,14,pmf_is_prisoner)

There can be at most 6 stacks in a party template.


Farmers tuple examination:

1 ) Party-template id = "farmers" 2 ) Party-template name = "farmers" 3 ) Party flags = icon_peasant|pf_auto_start_dialog 4 ) Menu = 0 5 ) Faction = fac_innocents 6 ) Personality = merchant_personality 7 ) List of stacks:

   7.1) Troop-id = trp_farmer, trp_peasant_woman
   7.2) Minimum number of troops in the stack = 11, 16
   7.3) Maximum number of troops in the stack = 22, 44 
   7.4) Member flags(optional) = None are set.


If you've followed the documentation since Part 1, you should be fairly adept at reading tuples by this point, and you will have noticed the one field in this tuple that's unlike any other field we've encountered before: Field number 6, the Personality flags field. We will cover this field and its functions in the next segment.


[edit] 4.2 -- Personality

As mentioned in the tuple breakdown, the Personality field determines party behaviour on the map. Here you can assign custom scores for Courage and Aggressiveness, or use one of the preset personalities such as merchant_personality. These presets are constants, each containing a Courage and an Aggressiveness score. The presets are all defined in header_parties.py, so open that file now and scroll to the bottom to see the constant definitions for yourself. There you will also notice the list of possible Courage and Aggressiveness settings.

The constant merchant_personality is used in many templates throughout the file. Parties with this personality will be friendly, they will not go out to attack the enemy or raid weaker parties. This is because merchant_personality sets the party's Aggressiveness to aggresiveness_0. A party with aggresiveness_0 will never attack another party, whereas normal combative parties with the preset soldier_personality will have aggresiveness_8. This will let them attack other parties if the attackers' faction is on bad terms with the defenders' faction, and if the would-be attackers aren't badly outnumbered.

Courage is the score that determines when parties will run away from another, larger party. Higher Courage means they will be less quick to turn away when the numbers aren't entirely favourable. merchant_personality parties have a Courage of 8, where soldier_personality have a Courage of 11.

These settings scale from 0 to 15, allowing you to precisely set the desired behaviour for your party templates. New modders, however, are recommended to stick with the presets. They cover the full range of personalities you should need for your first mod.

Finally, for bandit templates, there is the flag banditness. This causes the bandit party to constantly consider other nearby parties as prey, and if the prey is carrying significant amounts of gold and/or trade goods, the bandit party will attack. Ideally, a bandit party should have low aggressiveness or low troop numbers so that it does not attack soldier parties.


[edit] 4.3 -- Creating New Templates

Copy the tuple for "farmers" and paste it at the bottom of your file, before the closing bracket.


 ("new_template","new_template",icon_peasant|pf_auto_start_dialog,0,fac_innocents,merchant_personality,[(trp_farmer,11,22),(trp_peasant_woman,16,44)]),

In this example we've changed the identifier from "farmers" to "new_template", and we've done likewise for the name. Once we've done this, we can begin to edit the specifics of this template.

For our first tweak, let us change the template's faction to fac_neutral, and merchant_personality to soldier_personality.


 ("new_template","new_template",icon_peasant|pf_auto_start_dialog,0,fac_neutral,soldier_personality,[(trp_farmer,11,22),(trp_peasant_woman,16,44)]),

From now on, parties of this template will be of the Neutral faction, and they will attack an enemy party if they see one.

Next, let's play with the troop composition.


 ("new_template","new_template",icon_peasant|pf_auto_start_dialog,0,fac_neutral,soldier_personality,[(trp_geoffrey,1,1),(trp_new_troop,16,44)]),

This example has a few notable changes -- most importantly, it's now being led by trp_geoffrey, the Hero troop we created in Part 3 of this documentation. Since there can't be more than one of Geoffrey, we've changed his minimum and maximum troop numbers to 1.

As his followers, we've assigned a contingent of trp_new_troop, the regulars we also created in Part 3. There will be never be less than 16 "new troops" in this party, but as the player gains in level, the size will be gradually adjusted. Eventually this "new_template" can spawn with as many as 44 "new troops" -- but never more than 44.


Save the file and click on build_module.bat. If everything went well, you will now be able to use the new template in your module code, but parties of a party template must be spawned -- they do not just show up of their own volition. If we were to run the game at this point, we would not see any parties of our "new template" running around.

We will learn how to spawn parties of a template in an upcoming part of this documentation. For the moment, let us leave Geoffrey and his little band while we find out how to create new items in the next part of this documentation. Please move on to Part 5 now.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox