Users who are viewing this thread

Hello! New modder here. I was looking for how to set Lord personalities definitively in my mod, via modulesystem. I wanted to use different behaviors as reflective of different factions' overall behavior. I.E., Faction 1's general culture is more aggressive and militant than other factions: set all/most of their lords' personalities as martial.

I couldn't find any answer for this question. So I threw spaghetti (code) at the wall and found something stuck! In module_scripts.py, there are scripts to determine many different aspects of the companions. This starts under "initialize_npcs". There is one line that sets their lord reputation, for when you appoint them to be a lord. I copy-pasted that line. Moved it below the last companion, Klethi. Replaced the troop id with the lord's specific troop id. So if we copy/paste Klethi's code, replace "trp_npc16" with the lord's id: "trp_knight_1_1". Knight 1_1 is Count Klargus, of Swadia. If you add this line underneath Klethi, it will set Klargus' reputation to whatever you set at the end of the line.

In this example, from module_scripts.py, under "initialize_npcs", following Klethi's entries, I've set all Swadian lords with the "upstanding" reputation:

Code:
        (troop_set_slot, "trp_npc16", slot_troop_morality_type, tmt_aristocratic), #klethi
        (troop_set_slot, "trp_npc16", slot_troop_morality_value, 4),
        (troop_set_slot, "trp_npc16", slot_troop_2ary_morality_type, tmt_humanitarian),
        (troop_set_slot, "trp_npc16", slot_troop_2ary_morality_value, -1),
        (troop_set_slot, "trp_npc16", slot_troop_personalityclash_object, "trp_npc15"), #klethi
        (troop_set_slot, "trp_npc16", slot_troop_personalityclash2_object, "trp_npc1"), #klethi - borcha
        (troop_set_slot, "trp_npc16", slot_troop_personalitymatch_object, "trp_npc7"),  #deshavi - klethi
        (troop_set_slot, "trp_npc16", slot_troop_home, "p_village_20"), #Uslum
        (troop_set_slot, "trp_npc16", slot_troop_payment_request, 200),
        (troop_set_slot, "trp_npc16", slot_troop_kingsupport_argument, argument_lords),
        (troop_set_slot, "trp_npc16", slot_troop_kingsupport_opponent, "trp_npc12"), #nizar
         (troop_set_slot, "trp_npc16", slot_troop_town_with_contacts, "p_town_9"), #khudan
        (troop_set_slot, "trp_npc16", slot_lord_reputation_type, lrep_roguish), #END OF COMPANION CODE

        (troop_set_slot, "trp_knight_1_1", slot_lord_reputation_type, lrep_upstanding), #THIS CODE SETS THE LORD'S PERSONALITIES.
        (troop_set_slot, "trp_knight_1_2", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_3", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_4", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_5", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_6", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_7", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_8", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_9", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_10", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_11", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_12", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_13", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_14", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_15", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_16", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_17", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_18", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_19", slot_lord_reputation_type, lrep_upstanding), #
        (troop_set_slot, "trp_knight_1_20", slot_lord_reputation_type, lrep_upstanding), #

As you can see, it directly reflects the final line of Klethi's code, simply replacing her troop id with the lord's and replacing the rep_roguish with whichever you like. I assume assigning the lords reputations used for suitors would not go over well, but maybe I'll try it later for kicks and giggles. Hope this helps someone down the line![/ISPOILER]
 
Last edited by a moderator:
Considering your list of lords is in order, exactly as it appears in module_troops.py, without skipping any lords in between, you could use a loop to make the code shorter.
Python:
(store_add,":list_end",trp_knight_1_20,1),
(try_for_range,":lord","trp_knight_1_1",":list_end"),
    (troop_set_slot,":lord",slot_lord_reputation_type,lrep_upstanding),
(try_end),
Variable ":list_end: is the last entry that loop will not reach, so it's your last troop on the list + 1 (that's why we do store_add +1 on it)
Loop goes through your list of lords, and on each repetition the current lord is stored to the variable ":lord" that we provided.
Then we just use 1 command, and executing it on ":lord". Because The loop puts 1 lord at a time into that variable and continues doing so until the end of the list, we only write 1 command, but it gets executed for all lords that get put into ":lord" by the loop.

Good luck with future coding! Loops are your friends :smile:

Also, you may wanna look into script "initialize_aristocracy" - that's where the game sets the lord personalities and other aristocracy related stuff.
The easiest solution would be to just insert your code at the bottom of that script in module_scripts.py.
So just look for "initialize_trade_routes" and go a bit up to the previous script block and that's where you want your code.
Keep in mind that according to my best knowledge this script is called only once, when new game is started.
But so is initialize_npcs, so you need to start a new game for this to appear in your game anyway.
 
Last edited:
Considering your list of lords is in order, exactly as it appears in module_troops.py, without skipping any lords in between, you could use a loop to make the code shorter.
Python:
(store_add,":list_end",trp_knight_1_20,1),
(try_for_range,":lord","trp_knight_1_1",":list_end"),
    (troop_set_slot,":lord",slot_lord_reputation_type,lrep_upstanding),
(try_end),
Variable ":list_end: is the last entry that loop will not reach, so it's your last troop on the list + 1 (that's why we do store_add +1 on it)
Loop goes through your list of lords, and on each repetition the current lord is stored to the variable ":lord" that we provided.
Then we just use 1 command, and executing it on ":lord". Because The loop puts 1 lord at a time into that variable and continues doing so until the end of the list, we only write 1 command, but it gets executed for all lords that get put into ":lord" by the loop.

Good luck with future coding! Loops are your friends :smile:

Also, you may wanna look into script "initialize_aristocracy" - that's where the game sets the lord personalities and other aristocracy related stuff.
The easiest solution would be to just insert your code at the bottom of that script in module_scripts.py.
So just look for "initialize_trade_routes" and go a bit up to the previous script block and that's where you want your code.
Keep in mind that according to my best knowledge this script is called only once, when new game is started.
But so is initialize_npcs, so you need to start a new game for this to appear in your game anyway.
Thanks for the refinement info! I can see how putting this kind of code under initialize aristocracy would be much more logical. The loop thing makes sense and would work for a faction with the same reputation. I ended up doing that for one faction, but I still wanted some variation in the other factions, even if they lean one way or another. I shall continue trying to understand loops, and thanks for the encouragement!
 
Variation can also be done with loops. Let's say you want your Khergits to have 3 different personalities:
- lrep_quarrelsome
- lrep_cunning
- lrep_debauched
then you:
Python:
(try_for_range,":lord","trp_knight_3_1","trp_knight_4_1"), #knight_4_1 is the first Nord, so right after last Khergit

    (store_random_in_range,":rep",0,3), #3 reputations, this command draws from 0 to 3, but not reaching 3, so 0, 1, 2
 
    (try_begin),
        (eq,":rep",0), #if random number is 0, give reputation 1
        (troop_set_slot,":lord",slot_lord_reputation_type,lrep_quarrelsome),
    (else_try),
        (eq,":rep",1), #if random number is 1, give reputation 2
        (troop_set_slot,":lord",slot_lord_reputation_type,lrep_cunning),
    (else_try),
        #no need to check if value = 2, because that's the last option left, give reputation 3
        (troop_set_slot,":lord",slot_lord_reputation_type,lrep_debauched),
    (try_end),
 
(try_end),
Using random numbers like this also guarantees that you won't know the lord's personality until you get to know him. That's kinda how it works in vanilla. Though to be honest personality has very small impact on what's happening in the game. The most important thing I noticed was which quests lord will and will not give (as seen in script_get_quest).

Last 2 pieces of advice from me, as another relatively new modder (of Warband, at least):
1. Clearly mark changes in your code - once there is more of it that you've changed, knowing which one is your will be invaluable (use #comments for that)
2. Put tons of comments in your code that explain what which piece of code does. As someone smarter than me once said, "today you're coding it and it's fine, but in a few months someone is gonna look at your code and have no idea what it does. That person will most likely be you."
 
Back
Top Bottom