OSP Code QoL Bodyguards/Escorts in Town/Village Scenes (Open Source)

Users who are viewing this thread

No problem. Have you verified prison breaks, etc? Also, I'd put everything from (assign, ":entry_point", 0), to (modify_visitors_at_site, ":cur_scene"), outside the loop.

Here's a simple dialog that should prevent them from clumping up (talk to one if they get too close and the bodyguard should stop moving). Set the appropriate dialog state and you should be good to go.
Code:
  [anyone|plyr, "bodyguard_after_recruited", [(agent_get_simple_behavior, ":bhvr", "$g_talk_agent"),(lt, ":bhvr", 2)],
   "Stay with me.", "close_window", [(agent_clear_scripted_mode, "$g_talk_agent"),
   ]],
  [anyone|plyr, "bodyguard_after_recruited", [(agent_get_simple_behavior, ":bhvr", "$g_talk_agent"),(gt, ":bhvr", 1)],
   "No need to keep following me.", "close_window", [(agent_get_position, pos1, "$g_talk_agent"),
   (agent_set_scripted_destination, "$g_talk_agent", pos1),
   ]],
You could change pos1 to the position of a random entry point or npc or something. Too lazy to make something clever up, so hold position it is. That way, if all of them spawn around the player, at least you'll be able to reach the door (or just press tab).
 
Somebody said:
No problem. Have you verified prison breaks, etc?
I have. I took your lead and added a very simple option to your debug menu:
Code:
      ("summon_prisoner",
      [
       (neg|party_slot_eq, "$current_town", slot_party_type, spt_village),
      ],
      "Imprison Harlaus.",
      [
        (party_add_prisoners, "$current_town","trp_kingdom_1_lord",1),
        (troop_set_slot, "trp_kingdom_1_lord", slot_troop_prisoner_of_party, "$current_town"),
      ]),
Bodyguards work as intended in the context of a prison break. The bodyguards don't follow you into the prison, but are there in the town/castle scene before and after you collect the prisoners to help them escape. The presence of the bodyguard(s) doesn't affect the orders you give to the prisoners, either.

Somebody said:
Also, I'd put everything from (assign, ":entry_point", 0), to (modify_visitors_at_site, ":cur_scene"), outside the loop.
Ah! Of course. Just left it there from when it was spawn agent stuff, I suppose. OP modified to fit.
 
i'll start by saying im a complete modding noob but i wanted to add this bodyguard script to my copy of native(Warband v1.134) but i don't know how to use python or have the tools for it, does anyone have a native(Warband v1.134) mission template and dialog with this bodyguard script added to it that they could put on m&b repository for me?
 
Code:
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),
   ]),
   ]

Aight.  What I do wrong to get this error?

Traceback (most recent call last):
  File "process_init.py", line 2, in <module>
    from process_operations import *
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 21, in
<module>
    from module_mission_templates import *
  File "C:\A Conspiracy of Kings\Conspiracy\module_mission_templates.py", line 1
28, in <module>
    (agent_set_division, ":agent", :cool:,
NameError: name 'agent_set_division' is not defined
Traceback (most recent call last):
  File "process_global_variables.py", line 12, in <module>
    from process_operations import *
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 21, in
<module>
    from module_mission_templates import *
  File "C:\A Conspiracy of Kings\Conspiracy\module_mission_templates.py", line 1
28, in <module>
    (agent_set_division, ":agent", :cool:,
NameError: name 'agent_set_division' is not defined

edit:
New error.
 
Aight.  Fixed that but now I have this...

Initializing...
variables.txt not found. Creating new variables.txt file
Compiling all global variables...
variables.txt not found. Creating new variables.txt file
variable_uses.txt not found. Creating new variable_uses.txt file
Exporting strings...
Exporting skills...
Exporting tracks...
Exporting animations...
Exporting meshes...
Exporting sounds...
Exporting skins...
Exporting map icons...
Creating new tag_uses.txt file...
Creating new quick_strings.txt file...
Exporting faction data...
Exporting item data...
Exporting scene data...
Exporting troops data
Exporting particle data...
Exporting scene props...
Exporting tableau materials data...
Exporting presentations...
Exporting party_template data...
Exporting parties
Exporting quest data...
Exporting info_page data...
Exporting scripts...
Exporting mission_template data...
Traceback (most recent call last):
  File "process_mission_tmps.py", line 64, in <module>
    save_mission_templates(variables,variable_uses,tag_uses,quick_strings)
  File "process_mission_tmps.py", line 48, in save_mission_templates
    save_triggers(file,convert_to_identifier(mission_template[mission_template_n
ame_pos]), mission_template[mission_template_triggers_pos],variables,variable_us
es,tag_uses,quick_strings)
  File "process_mission_tmps.py", line 23, in save_triggers
    save_statement_block(file, 0, 1, trigger[trigger_consequences_pos], variable
_list,variable_uses,tag_uses,quick_strings)
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 449, in
save_statement_block
    save_statement(ofile,opcode,no_variables,statement,variable_list,variable_us
es,local_vars, local_var_uses,tag_uses,quick_strings)
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 401, in
save_statement
    ofile.write("%d "%operand)
TypeError: int argument required

Exporting game menus data...
Error: Unable to find object:skl_persausion
ERROR: Illegal Identifier:skl_persausion
Error: Unable to find object:skl_persausion
ERROR: Illegal Identifier:skl_persausion
Error: Unable to find object:skl_persausion
ERROR: Illegal Identifier:skl_persausion
Error: Unable to find object:skl_persausion
ERROR: Illegal Identifier:skl_persausion
WARNING: Usage of unassigned global variable: $g_presentation_marshall_selection
_max_renown_3
WARNING: Usage of unassigned global variable: $g_presentation_marshall_selection
_max_renown_3_troop
WARNING: Usage of unassigned global variable: $g_presentation_marshall_selection
_max_renown_3
WARNING: Usage of unassigned global variable: $g_presentation_marshall_selection
_max_renown_3_troop
WARNING: Local variable never used: town_merchant, at: 0
exporting simple triggers...
exporting triggers...
exporting dialogs...
Checking global variable usages...
WARNING: Global variable never used: g_number_of_targets_destroyed
WARNING: Global variable never used: g_tutorial_training_ground_archer_trainer_i
tem_1
WARNING: Global variable never used: g_tutorial_training_ground_archer_trainer_i
tem_2
WARNING: Global variable never used: g_tutorial_training_ground_horseman_trainer
_item_1
WARNING: Global variable never used: g_tutorial_training_ground_horseman_trainer
_item_2
WARNING: Global variable never used: drunks_dont_pick_fights
WARNING: Global variable never used: training_fight_won
WARNING: Global variable never used: dialog_with_merchant_ended
WARNING: Global variable never used: g_village_raid_evil
WARNING: Global variable never used: g_siege_sallied_out_once
WARNING: Global variable never used: g_attacker_drawn_weapon
WARNING: Global variable never used: g_latest_order_1
WARNING: Global variable never used: g_latest_order_2
WARNING: Global variable never used: g_latest_order_3
WARNING: Global variable never used: g_latest_order_4
WARNING: Global variable never used: belfry_positioned
WARNING: Global variable never used: g_arena_training_max_opponents
WARNING: Global variable never used: g_position_to_use_for_replacing_scene_items

WARNING: Global variable never used: server_mission_timer_while_player_joined
WARNING: Global variable never used: g_destructible_target_2
WARNING: Global variable never used: g_multiplayer_mission_end_screen
WARNING: Global variable never used: g_election_date
WARNING: Global variable never used: g_battle_waiting_seconds
WARNING: Global variable never used: g_death_mode_part_1_start_time
WARNING: Global variable never used: g_multiplayer_poll_ended
WARNING: Global variable never used: g_multiplayer_poll_end_time
WARNING: Global variable never used: g_training_ground_training_num_gourds_to_de
stroy
WARNING: Global variable never used: g_training_ground_ranged_distance
WARNING: Global variable never used: g_presentation_lines_to_display_begin
WARNING: Global variable never used: g_presentation_lines_to_display_end
WARNING: Global variable never used: $g_presentation_marshall_selection_max_reno
wn_3
WARNING: Global variable never used: $g_presentation_marshall_selection_max_reno
wn_3_troop
WARNING: Global variable never used: $g_presentation_marshall_selection_max_reno
wn_3
WARNING: Global variable never used: $g_presentation_marshall_selection_max_reno
wn_3_troop
Exporting postfx_params...

______________________________

Script processing has ended.
Press any key to exit. . .
 
Aight.  I switched it all over to 1.134 because I was due to anyways.

Still have this error:

Traceback (most recent call last):
  File "process_mission_tmps.py", line 64, in <module>
    save_mission_templates(variables,variable_uses,tag_uses,quick_strings)
  File "process_mission_tmps.py", line 48, in save_mission_templates
    save_triggers(file,convert_to_identifier(mission_template[mission_template_n
ame_pos]), mission_template[mission_template_triggers_pos],variables,variable_us
es,tag_uses,quick_strings)
  File "process_mission_tmps.py", line 23, in save_triggers
    save_statement_block(file, 0, 1, trigger[trigger_consequences_pos], variable
_list,variable_uses,tag_uses,quick_strings)
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 449, in
save_statement_block
    save_statement(ofile,opcode,no_variables,statement,variable_list,variable_us
es,local_vars, local_var_uses,tag_uses,quick_strings)
  File "C:\A Conspiracy of Kings\Conspiracy\process_operations.py", line 401, in
save_statement
    ofile.write("%d "%operand)
TypeError: int argument required
 
After some dissection it appears to be attached to +bodyguard triggers


edit: Yes.

I am not sure where to put + bodyguard.  Where in an example?
 
Lueii said:
I am not sure where to put + bodyguard.  Where in an example?

The end of "town_center" looks like:
Code:
     (try_end),
   ]),     
  ]),

  (
    "village_center",0,-1,
    "village center",

So you'd change it so it looks like:
Code:
     (try_end),
   ]),     
  ] + bodyguard_triggers,
 ),

  (
    "village_center",0,-1,
    "village center",
as listed in the OP.
 
Is there a way to get one's Kevin Costner dressed in pilgrim (ie no ubber armor and weapon) whean sneaking into towns ? To respect the fact we are supposed to be stealthy peeps and making it harder (God, did I said that ? You must know that Rolf just got KO because AI is so wonderful once surrounded).
 
Loner said:
Is there a way to get one's Kevin Costner dressed in pilgrim (ie no ubber armor and weapon) whean sneaking into towns ? To respect the fact we are supposed to be stealthy peeps and making it harder (God, did I said that ? You must know that Rolf just got KO because AI is so wonderful once surrounded).
Yes, bodyguards (nice reference) could be assigned to the pilgrim outfit if you want to OK them for sneaking in, replace the first trigger with the following alternative version:
Code:
(ti_after_mission_start, 0, ti_once, [], #condition: to exclude sneaking in put (neq, "$g_mt_mode", tcm_disguised) within the [], to exclude prison-breaks, too use (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),       
        (eq, "$g_mt_mode", tcm_disguised),
        (eq, "$sneaked_into_town", 0), #fail, caught
        (assign, ":mission_tpl", "mt_sneak_caught_fight"),
        
        #Find nearest visitor_source entry point near the player, depending on player's entry point
        (try_begin),
          (this_or_next|eq, "$talk_context", tc_escape),
          (eq, "$talk_context", tc_prison_break),
          (entry_point_get_position, pos0, 7), 
        (else_try),          
          (party_slot_eq, "$current_town", slot_party_type, spt_town),
          (entry_point_get_position, pos0, 0), 
        (else_try),  
          (entry_point_get_position, pos0, 1), 
        (try_end),        
        (assign, ":smallest_dist", 100000),
        (try_for_range, ":i", 2, 64),
            (entry_point_get_position, pos1, ":i"), 
            (get_distance_between_positions, ":dist", pos0, pos1),
            (lt, ":dist", ":smallest_dist"),
            (assign, ":smallest_dist", ":dist"),
            (assign, ":entry_point", ":i"),
        (try_end),
    (else_try_),    
        (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),
        (eq, "$g_mt_mode", tcm_disguised),
        (mission_tpl_entry_set_override_flags, ":mission_tpl", ":entry_point", af_override_all),
        (mission_entry_add_override_item, ":mission_tpl", ":entry_point",  pilgrim_disguise),
    (else_try),
        (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
    (try_begin),
        (eq, "$g_mt_mode", tcm_disguised),
        (mission_entry_clear_override_items, ":mission_tpl", ":entry_point"),
    (try_end),
    (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),   
   ]), 

I've not tested this...but it should work.
 
Back
Top Bottom