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.
Replace the try block shown above with this one:
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.
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.