Another response to something odd noted a number of different places across the forums: your warlord/noble/monarch character is fool enough to wander unsuspecting into towns and villages without an escort for protection and thus can get caught outnumbered by ruffians or unawares by an assassin at any turn.
The following trigger can be added to the appropriate mission_templates to allow a set number of your NPC companions join you as you visit towns and villages. As coded, the number of bodyguards available to a player is governed by their renown and leadership skill: 1 bodyguard per 3 levels of leadership or 400 points of renown up to a maximum of 4 bodyguards. The guards are taken from the non-wounded NPC/heroes/companions that player has in their party, in the order they appear in the party list...just as they would be taken for a bandit raid mission or some such.
Without further ado...
UPDATED!
Also, to avoid odd dialog if the player chooses to talk with their guard/escort, one line is needed in module_dialogs
The following trigger can be added to the appropriate mission_templates to allow a set number of your NPC companions join you as you visit towns and villages. As coded, the number of bodyguards available to a player is governed by their renown and leadership skill: 1 bodyguard per 3 levels of leadership or 400 points of renown up to a maximum of 4 bodyguards. The guards are taken from the non-wounded NPC/heroes/companions that player has in their party, in the order they appear in the party list...just as they would be taken for a bandit raid mission or some such.
Without further ado...
UPDATED!
Create a common trigger block, as follows, near the top of module_mission_templates...with the other common triggers. It must include the first line importing skill definitions (as coded, at least).
Add the trigger at the end of the consequences block of the following mission templates:
"bandits_at_night", "castle_visit", "village_center", "town_center", "town_default"
by finding the closing
]
),
at the very end of the template, right before the next one begins.
and adding "+ bodyguard_triggers," to the bracket so it looks like:
] + bodyguard_triggers,
),
Code:
from header_skills import *
bodyguard_triggers = [
(ti_after_mission_start, 0, ti_once, [(neq, "$g_mt_mode", tcm_disguised)], #condition for not sneaking in; to exclude prison-breaks, etc change to (eq, "$g_mt_mode", tcm_default")
[
#Get number of bodyguards
(store_skill_level, ":leadership", skl_leadership, "trp_player"),
(troop_get_slot, ":renown", "trp_player", slot_troop_renown),
(val_div, ":leadership", 3),
(val_div, ":renown", 400),
(store_add, ":max_guards", ":renown", ":leadership"),
(val_min, ":max_guards", 4),
(ge, ":max_guards", 1),
#Get player info
(get_player_agent_no, ":player"),
(agent_get_team, ":playerteam", ":player"),
(agent_get_horse, ":use_horse", ":player"), #If the player spawns with a horse, the bodyguard will too.
#Prepare Scene/Mission Template
(assign, ":entry_point", 0),
(assign, ":mission_tpl", 0),
(try_begin),
(party_slot_eq, "$current_town", slot_party_type, spt_village),
(assign, ":entry_point", 11), #Village Elder's Entry
(assign, ":mission_tpl", "mt_village_center"),
(else_try),
(this_or_next|eq, "$talk_context", tc_prison_break),
(this_or_next|eq, "$talk_context", tc_escape),
(eq, "$talk_context", tc_town_talk),
(assign, ":entry_point", 24), #Prison Guard's Entry
(try_begin),
(party_slot_eq, "$current_town", slot_party_type, spt_castle),
(assign, ":mission_tpl", "mt_castle_visit"),
(else_try),
(assign, ":mission_tpl", "mt_town_center"),
(try_end),
(else_try),
(eq, "$talk_context", tc_tavern_talk),
(assign, ":entry_point", 17), #First NPC Tavern Entry
(try_end),
(try_begin),
(neq, "$talk_context", tc_tavern_talk),
(gt, ":use_horse", 0),
(mission_tpl_entry_set_override_flags, ":mission_tpl", ":entry_point", 0),
(try_end),
(store_current_scene, ":cur_scene"),
(modify_visitors_at_site, ":cur_scene"),
#Find and Spawn Bodyguards
(assign, ":bodyguard_count", 0),
(party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
(try_for_range, ":i", 0, ":num_of_stacks"),
(party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
(neq, ":troop_id", "trp_player"),
(troop_is_hero, ":troop_id"),
(neg|troop_is_wounded, ":troop_id"),
(val_add, ":bodyguard_count", 1),
(try_begin), #For prison-breaks
(this_or_next|eq, "$talk_context", tc_escape),
(eq, "$talk_context", tc_prison_break),
(troop_set_slot, ":troop_id", slot_troop_will_join_prison_break, 1),
(try_end),
(add_visitors_to_current_scene, ":entry_point", ":troop_id", 1),
(eq, ":bodyguard_count", ":max_guards"),
(assign, ":num_of_stacks", 0), #Break Loop
(try_end), #Stack Loop
(gt, ":bodyguard_count", 0), #If bodyguards spawned...
(set_show_messages, 0),
(team_give_order, ":playerteam", 8, mordr_follow), #Division 8 to avoid potential conflicts
(set_show_messages, 1),
]),
(ti_on_agent_spawn, 0, 0, [],
[
(store_trigger_param_1, ":agent"),
(agent_get_troop_id, ":troop", ":agent"),
(neq, ":troop", "trp_player"),
(troop_is_hero, ":troop"),
(main_party_has_troop, ":troop"),
(get_player_agent_no, ":player"),
(agent_get_team, ":playerteam", ":player"),
(agent_get_position,pos1,":player"),
(agent_set_team, ":agent", ":playerteam"),
(agent_set_division, ":agent", 8),
(agent_add_relation_with_agent, ":agent", ":player", 1),
(agent_set_is_alarmed, ":agent", 1),
(store_random_in_range, ":shift", 1, 3),
(val_mul, ":shift", 100),
(position_move_y, pos1, ":shift"),
(store_random_in_range, ":shift", 1, 3),
(store_random_in_range, ":shift_2", 0, 2),
(val_mul, ":shift_2", -1),
(try_begin),
(neq, ":shift_2", 0),
(val_mul, ":shift", ":shift_2"),
(try_end),
(position_move_x, pos1, ":shift"),
(agent_set_position, ":agent", pos1),
]),
(ti_on_agent_killed_or_wounded, 0, 0, [],
[
(store_trigger_param_1, ":dead_agent"),
(agent_get_troop_id, ":troop", ":dead_agent"),
(neq, ":troop", "trp_player"),
(troop_is_hero, ":troop"),
(main_party_has_troop, ":troop"),
(party_wound_members, "p_main_party", ":troop", 1),
]),
]
"bandits_at_night", "castle_visit", "village_center", "town_center", "town_default"
by finding the closing
]
),
at the very end of the template, right before the next one begins.
and adding "+ bodyguard_triggers," to the bracket so it looks like:
] + bodyguard_triggers,
),
Also, to avoid odd dialog if the player chooses to talk with their guard/escort, one line is needed in module_dialogs
Find the following chunk of dialog code (around line 2895) and add the marked line
Code:
[anyone, "start", [(is_between, "$g_talk_troop", companions_begin, companions_end),
(this_or_next|eq, "$talk_context", tc_tavern_talk),
(this_or_next|eq, "$talk_context", tc_town_talk), #ADD THIS LINE FOR BODYGUARD CODE
(eq, "$talk_context", tc_court_talk),
(main_party_has_troop, "$g_talk_troop")],
"Let's leave whenever you are ready.", "close_window", []],
The only caveat/problem with coding this as I have here is that sometimes the bodyguards will spawn with errors to their facial appearance (wrong hair/color/beard...maybe even a change to the face). Having your companions wear helmets clearly reduces the visibility of any such errors. (The solution to this problem would be to relocate the code to the game_menus and set the troops as scene visitors, but this presents its own sets of problems and complications.)
Create a common trigger, as follows, near the top of module_mission_templates...with the other common triggers. It must include the first line importing skill definitions (as coded, at least).
Add the trigger in the operations block of the following mission templates:
"bandits_at_night", "castle_visit", "village_center", "town_center", "town_default"
do this by adding the line:
bodyguard_trigger,
Create a common trigger, as follows, near the top of module_mission_templates...with the other common triggers. It must include the first line importing skill definitions (as coded, at least).
Code:
from header_skills import *
bodyguard_trigger = (
ti_after_mission_start, 0, ti_once, [(neq, "$g_mt_mode", tcm_disguised)], #condition for not sneaking in; to exclude prison-breaks, etc change to (eq, "$g_mt_mode", tcm_default")
[
#Get number of bodyguards
(store_skill_level, ":leadership", skl_leadership, "trp_player"),
(troop_get_slot, ":renown", "trp_player", slot_troop_renown),
(val_div, ":leadership", 3),
(val_div, ":renown", 400),
(store_add, ":max_guards", ":renown", ":leadership"),
(val_min, ":max_guards", 4),
(ge, ":max_guards", 1),
#Get player info
(get_player_agent_no, ":player"),
(agent_get_team, ":playerteam", ":player"),
(agent_get_position,pos1,":player"),
(agent_get_horse, ":use_horse", ":player"), #If the player spawns with a horse, the bodyguard will too.
(assign, ":bodyguard_count", 0),
(assign, ":shift", -200),
(party_get_num_companion_stacks, ":num_of_stacks", "p_main_party"),
(try_for_range, ":i", 0, ":num_of_stacks"),
(party_stack_get_troop_id, ":troop_id", "p_main_party", ":i"),
(neq, ":troop_id", "trp_player"),
(troop_is_hero, ":troop_id"),
(neg|troop_is_wounded, ":troop_id"),
(val_add, ":bodyguard_count", 1),
(try_begin),
(le, ":use_horse", 0), #The player didn't spawn with a horse, so prevent the bodyguard
(troop_get_inventory_slot, ":horse", ":troop_id", ek_horse), #by temp. removing their horse
(gt, ":horse", 0),
(troop_get_inventory_slot_modifier, ":horse_mod", ":troop_id", ek_horse),
(troop_remove_item, ":troop_id", ":horse"),
(try_end),
(position_move_x, pos1, ":shift"),
(set_spawn_position, pos1),
(spawn_agent, ":troop_id"),
(assign, ":guard", reg0),
(agent_set_team, ":guard", ":playerteam"),
(agent_add_relation_with_agent, ":guard", ":player", 1),
(agent_set_is_alarmed, ":guard", 1),
(try_begin),
(eq, ":bodyguard_count", 2),
(position_move_y, pos1, 200),
(try_end),
(val_mul, ":shift", -2),
(try_begin),
(le, ":use_horse", 0), #No horses in scene
(gt, ":horse", 0), #But bodyguard had a horse
(troop_add_item, ":troop_id", ":horse", ":horse_mod"), #Give their horse back
(troop_equip_items, ":troop_id"), #make sure they keep the horse
(try_end),
(eq, ":bodyguard_count", ":max_guards"),
(assign, ":num_of_stacks", 0), #Break Loop
(try_end), #Stack Loop
(gt, ":bodyguard_count", 0), #If bodyguards spawned...
(set_show_messages, 0),
(team_give_order, ":playerteam", grc_everyone, mordr_follow),
(set_show_messages, 1),
])
Add the trigger in the operations block of the following mission templates:
"bandits_at_night", "castle_visit", "village_center", "town_center", "town_default"
do this by adding the line:
bodyguard_trigger,