OSP Code SP [WB] Randomize Companions' Vassal Banners

Users who are viewing this thread

Companions are always granted banners in the same, descending, order as governed by code in the dialogs file. This results in a repetitive experience of vassalizing companions, and is made worse in that the first banner given already belongs to King Ragnar.

The following code randomizes the banners received by Companions, while ensuring they don't duplicate one another or the player. Duplication with NPC Lords is unavoidable.

The code over-writes part of the module_dialogs.py code where the player grants one of his/her companions a fief.
Code:
[anyone,"member_fief_grant_3", [
        ], "{s5}", "close_window",[
        (call_script, "script_npc_morale", "$g_talk_troop"),
        (assign, ":npc_morale", reg0),
        
        (remove_member_from_party, "$g_talk_troop", "p_main_party"),
        
        
        (try_begin),
          (neg|troop_slot_eq, "$g_talk_troop", slot_troop_occupation, slto_kingdom_hero),
          
          (assign, ":banner_offset", banners_end_offset),
          (val_sub, ":banner_offset", 1),
          (val_sub, ":banner_offset", "$g_companions_banner_id"),                            
          (store_add, ":banner_id", banner_scene_props_begin, ":banner_offset"),                    
          (troop_set_slot, "$g_talk_troop", slot_troop_banner_scene_prop, ":banner_id"),          
          (val_add, "$g_companions_banner_id", 1), 
          
          (troop_set_slot, "$g_talk_troop", slot_troop_occupation, slto_kingdom_hero),
        (try_end),

//...etc...//

Replace the try block shown above with this one:
Code:
[anyone,"member_fief_grant_3",

//...//

        (try_begin),    
             (neg|troop_slot_eq, "$g_talk_troop", slot_troop_occupation, slto_kingdom_hero),
             (store_sub, ":banner_offset", banners_end_offset, 1),
             (assign, ":end_loop", 150), #151 tries to not match the player/companions banner...not all will be used
             (try_for_range, ":unused", 0, ":end_loop"), 
                 (store_random_in_range, ":banner_id", 0, ":banner_offset"),
                 (val_add, ":banner_id", banner_scene_props_begin),
                 (assign, ":duplicate", 0),
                 (assign, ":end", companions_end),
                 (try_for_range, ":troop", active_npcs_including_player_begin, ":end"), #Check player and companions
                     (troop_slot_eq, ":troop", slot_troop_occupation, slto_kingdom_hero), #Check if a Lord
                     (troop_slot_eq, ":troop", slot_troop_banner_scene_prop, ":banner_id"),
                     (assign, ":duplicate", 1), #Duplicate found
                     (assign, ":end", 0), #Break the loop
                 (try_end),
                 (neq, ":duplicate", 1), #No duplicate
                 (assign, ":end_loop", 0), #Then break the loop, else try again
             (try_end),
             (troop_set_slot, "$g_talk_troop", slot_troop_banner_scene_prop, ":banner_id"), 
     
             (troop_set_slot, "$g_talk_troop", slot_troop_occupation, slto_kingdom_hero),     
        (try_end),

//...//

One note: the first try_for_range loop from 0 to 150 is an approximation of a Do...Until/While. There is still a chance that this will fail, particularly if the mod with ~100 new companions is used, in which case the most recently selected random banner will be used. Edit that 150 to a value to your liking, higher for more companions, possibly lower if only using the native 16.

Suggestions welcome.
 
You should probably add proper spacing for that relative section in your original post, so it's easier for others to copy.

Code:
		(try_begin),   
			(neg|troop_slot_eq, "$g_talk_troop", slot_troop_occupation, slto_kingdom_hero),
			(store_sub, ":banner_offset", banners_end_offset, 2), #Since 1 seems to get Ragnar's banner
			(assign, ":end_loop", 150), #151 tries to not match the player/companions banner...not all will be used
			(try_for_range, ":i", 0, ":end_loop"),
                (store_random_in_range, ":banner_id", 0, ":banner_offset"),
                (val_add, ":banner_id", banner_scene_props_begin),
                (assign, ":duplicate", 0),
                (assign, ":end", companions_end),
                (try_for_range, ":troop", active_npcs_including_player_begin, ":end"), #Check player and companions
                (troop_slot_eq, ":troop", slot_troop_occupation, slto_kingdom_hero), #Check if a Lord
                (troop_slot_eq, ":troop", slot_troop_banner_scene_prop, ":banner_id"),
                (assign, ":duplicate", 1), #Duplicate found
                (assign, ":end", 0), #Break the loop
			(try_end),
			(neq, ":duplicate", 1), #No duplicate
			(assign, ":end_loop", 0), #Then break the loop, else try again
		(try_end),
Good work. I'll definitely use this. I'd imagine it'd be an amazing asset to the new companions and heroes mod, too.

A question, since I'm not much of a scripter. On compiling, I'm getting the following error:

Code:
WARNING: Local variable never used: i, at: 0
Does this mean anything, or did I install it incorrectly?
 
First, I appreciate the response.

Schemer said:
You should probably add proper spacing for that relative section in your original post, so it's easier for others to copy.

Fixed...there should be appropriate spacing to the left now. Thanks for pointing that out.

Schemer said:
A question, since I'm not much of a scripter. On compiling, I'm getting the following error:

Code:
WARNING: Local variable never used: i, at: 0
Does this mean anything, or did I install it incorrectly?

Thanks for pointing that out, too. I've changed it to ":unused" and the warning disappeared.
 
Thanks for this, this should be included in many of the current mods, like Diplomacy.

You asked for suggestions: What about allowing the player to choose the banner, like when the player character becomes a Noble? Would be very convenient.
 
is it at FEMP?

Captain_Octavius said:
Thanks for this, this should be included in many of the current mods, like Diplomacy.

You asked for suggestions: What about allowing the player to choose the banner, like when the player character becomes a Noble? Would be very convenient.

any chances of you doing this caba'drin?
 
Back
Top Bottom