Awesome job, I hope you don't mind me posting my own personal modification, this makes the weapons breakable for the AI too, however only if they have 2 or more melee weapons (same goes for player btw, but that can easily be removed I think). That way it doesn't end up with a bunch of AI fistfighting.
I bet that there is a more effective way to do than the way I did, but I'm new to the mission_template world.
common_weapon_break = (
0.4, 0, 0,
[], [
#(player_get_agent_id, ":player_agent", ":player_no"),
# (get_player_agent_no, ":player_agent"),
(try_for_agents, ":player_agent"),
(agent_get_attack_action, ":playeraction", ":player_agent"), #returned values: free = 0, readying_attack = 1, releasing_attack = 2, completing_attack_after_hit = 3, attack_parried = 4, reloading = 5, after_release = 6, cancelling_attack = 7
(try_begin),
(eq,":playeraction",3),
(agent_get_wielded_item,":breakweapon",":player_agent",0),
(gt,":breakweapon",2),
(item_get_type, ":weapontype", ":breakweapon"),
(agent_get_horse,":playermounted",":player_agent"),
(store_random_in_range,":weaponbreakchance",1,100),
(try_begin),
(ge,":playermounted",0),
# (display_message, "@Mounted."),
(val_mul,":weaponbreakchance",104),
(val_div,":weaponbreakchance",100),
(eq,itp_type_polearm,":weapontype"),
(val_mul,":weaponbreakchance",110),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_polearm,":weapontype"),
# (display_message, "@Polearm"),
(val_mul,":weaponbreakchance",102),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_two_handed_wpn,":weapontype"),
# (display_message, "@2 hander"),
(val_mul,":weaponbreakchance",101),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_one_handed_wpn,":weapontype"),
# (display_message, "@1 hander"),
(val_mul,":weaponbreakchance",1),
(try_end),
(try_begin),
(assign, reg8, ":weaponbreakchance"),
# (display_message, "@{reg8}"),
(ge,":weaponbreakchance",98),
(assign, ":num_agent_items", 0),
(try_for_range, ":item", "itm_no_item", "itm_items_end"),
(item_get_type, ":weapontype2", ":item"),
(this_or_next|eq,itp_type_one_handed_wpn,":weapontype2"),
(this_or_next|eq,itp_type_two_handed_wpn,":weapontype2"),
(eq,itp_type_polearm,":weapontype2"),
(try_begin),
(agent_has_item_equipped,":player_agent",":item"),
(val_add, ":num_agent_items", 1),
(try_end),
(try_end),
(ge, ":num_agent_items", 2),
(agent_unequip_item,":player_agent",":breakweapon"),
(agent_get_troop_id,":troop", ":player_agent"),
# (troop_remove_item, "trp_player", ":breakweapon"),
(try_begin),
(get_player_agent_no,":player"),
(eq, ":player_agent", ":player"),
(play_sound,"snd_shield_broken",),
(troop_remove_item, ":troop", ":breakweapon"),
(display_message, "@Hah! Your weapon broke."),
(try_end),
(lt,":playermounted",0),
(agent_set_animation, ":player_agent", "anim_strike_chest_front"),
(try_end),
(try_end),
(try_end),])
common_weapon_break = (
0.4, 0, 0,
[], [
#(player_get_agent_id, ":player_agent", ":player_no"),
#MY MODIFICATION BEGIN---------------------------------------------------------------------------
# (get_player_agent_no, ":player_agent"),
(try_for_agents, ":player_agent"),
#MY MODIFICATION END-----------------------------------------------------------------------------
(agent_get_attack_action, ":playeraction", ":player_agent"), #returned values: free = 0, readying_attack = 1, releasing_attack = 2, completing_attack_after_hit = 3, attack_parried = 4, reloading = 5, after_release = 6, cancelling_attack = 7
(try_begin),
(eq,":playeraction",3),
(agent_get_wielded_item,":breakweapon",":player_agent",0),
(gt,":breakweapon",2),
(item_get_type, ":weapontype", ":breakweapon"),
(agent_get_horse,":playermounted",":player_agent"),
(store_random_in_range,":weaponbreakchance",1,100),
(try_begin),
(ge,":playermounted",0),
# (display_message, "@Mounted."),
(val_mul,":weaponbreakchance",104),
(val_div,":weaponbreakchance",100),
(eq,itp_type_polearm,":weapontype"),
(val_mul,":weaponbreakchance",110),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_polearm,":weapontype"),
# (display_message, "@Polearm"),
(val_mul,":weaponbreakchance",102),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_two_handed_wpn,":weapontype"),
# (display_message, "@2 hander"),
(val_mul,":weaponbreakchance",101),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq,itp_type_one_handed_wpn,":weapontype"),
# (display_message, "@1 hander"),
(val_mul,":weaponbreakchance",1),
(try_end),
(try_begin),
(assign, reg8, ":weaponbreakchance"),
# (display_message, "@{reg8}"),
(ge,":weaponbreakchance",98),
#MY MODIFICATION BEGIN----------------------------------------------------------------------------
(assign, ":num_agent_items", 0),
(try_for_range, ":item", "itm_no_item", "itm_items_end"),
(item_get_type, ":weapontype2", ":item"),
(this_or_next|eq,itp_type_one_handed_wpn,":weapontype2"),
(this_or_next|eq,itp_type_two_handed_wpn,":weapontype2"),
(eq,itp_type_polearm,":weapontype2"),
(try_begin),
(agent_has_item_equipped,":player_agent",":item"),
(val_add, ":num_agent_items", 1),
(try_end),
(try_end),
(ge, ":num_agent_items", 2),
#MY MODIFICATION END------------------------------------------------------------------------------
(agent_unequip_item,":player_agent",":breakweapon"),
#MY MODIFICATION BEGIN----------------------------------------------------------------------------
(agent_get_troop_id,":troop", ":player_agent"),
# (troop_remove_item, "trp_player", ":breakweapon"),
(try_begin),
(get_player_agent_no,":player"),
(eq, ":player_agent", ":player"),
(play_sound,"snd_shield_broken",),
(troop_remove_item, ":troop", ":breakweapon"),
(display_message, "@Hah! Your weapon broke."),
(try_end),
#MY MODIFICATION END------------------------------------------------------------------------------
(lt,":playermounted",0),
(agent_set_animation, ":player_agent", "anim_strike_chest_front"),
(try_end),
(try_end),
(try_end),])
I don't trigger the sound every time a weapon is broke because the sound is just as loud no matter how far away the weapon that break is, and that is quite annoying. So you can only hear it when it happens to the player.
I have tested it, and it works.