Reserved
Today's feature presentation: Fixable Bayonets (OSP) by Azrooh http://forums.taleworlds.com/index.php/topic,272505.0.html
Hey everyone, I've gotten a lot of requests for this code I wrote awhile back, so I figured I'd post it open-source as it seems to be something that quite a few people could use.
This was originally made for NW, but it will work for either module.
This allows you to detach or attach a bayonet. That's all it does. Well, I guess you could use it for switching between two weapons that aren't bayoneted versions if you'd like. You get to pick a fancy animation for it and there's a cooldown to prevent you from spamming it. It should 'remember' your ammo status as long as you can fire from the bayoneted version of the gun, so attaching and detaching the bayonet won't magically give you a round in the chamber or take one away.
Uses:
1 multiplayer event
2 item slots
1 agent slot
Many times people would like this feature but have some things missing from the original post of codes.
I have set a name to each new code as (code) so you know which PY file it goes in.
Quoted lines as (Quote) indicates points of reference in the guide.
header_common.py1st is under line 53 starting at #server events put the following second code below this first line:
multiplayer_event_return_agent_set_item = 122
module_constants.py2nd is under line 15 starting at Item Slots put the following second code below this first line:
slot_item_multiplayer_availability_linked_list_begin = 3 #temporary, can be moved to higher values
slot_item_bayonetItem = 4
slot_item_isFixed = 5
Under line 26 starting at Agent Slots put the following second code below this first line:
slot_agent_walker_occupation = 26
slot_agent_bayonetCooldown = 27
module_mission_templates.py3rd is under line 53 starting at end of multiplayer_server_log_player_leave script
Fixbayoneta = (
ti_before_mission_start, 0, 0, [],
[
(item_set_slot,"itm_british_brown_bessnobayonet",slot_item_bayonetItem,"itm_british_brown_bessb"), #set each non-bayoneted rifle to its bayoneted version
(item_set_slot,"itm_british_brown_bessb",slot_item_bayonetItem,"itm_british_brown_bessnobayonet"), #set each bayoneted rifle to its non-bayoneted version
(item_set_slot, "itm_british_brown_bessb", slot_item_isFixed, 1), #set each bayonet-attached item to isFixed
(item_set_slot,"itm_french_charlevillenobayonet",slot_item_bayonetItem,"itm_french_charlevilleb"), #set each non-bayoneted rifle to its bayoneted version
(item_set_slot,"itm_french_charlevilleb",slot_item_bayonetItem,"itm_french_charlevillenobayonet"), #set each bayoneted rifle to its non-bayoneted version
(item_set_slot, "itm_french_charlevilleb", slot_item_isFixed, 1), #set each bayonet-attached item to isFixed
#(display_message,"@MTA"),
])
Fixbayonetb = (
0, 0, 0, [(key_is_down,key_b),],
[
(multiplayer_get_my_player,":player"),
(player_get_agent_id,":playerAgent",":player"),
(multiplayer_send_2_int_to_server,multiplayer_event_fixBayonet,1,":playerAgent"),
#(display_message,"@MTB"),
])
Fixbayonetc = (
3, 0, 0, [],
[
(multiplayer_is_server),
(try_for_agents,":curAgent"),
(agent_get_slot,":bayonetCooldown",":curAgent",slot_agent_bayonetCooldown),
(val_sub,":bayonetCooldown",3),
(try_begin),
(lt,":bayonetCooldown",0),
(assign,":bayonetCooldown",0),
(try_end),
(agent_set_slot,":curAgent",slot_agent_bayonetCooldown,":bayonetCooldown"),
#(display_message,"@MTC"),
(try_end),
]) #Bajo
Stop at multiplayer_event_kill_stray_horses script start
Under line 3468 starting at mm_multiplayer_common script add the following lines at the end of #MM Multiplayer Commons like so below this first line:
multiplayer_client_surrender,
Fixbayoneta,
Fixbayonetb,
Fixbayonetc,
This ^^^^^^^^^^^^^^^^^^^^^ part is the part forgot to be mentioned on the original thread, thanks to B&I mod I found the missing pieces
module_scripts.py4th is under line 7391 starting at the end of this script:
(multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_confirmation),
(else_try),
(try_begin),
(eq,":spawn_is_ok",0),
(assign,":error_message","str_invalid_prop_place"),
(else_try),
(assign,":error_message","str_invalid_prop_select"),
(try_end),
(multiplayer_send_2_int_to_player, ":player_no", multiplayer_event_show_multiplayer_message, multiplayer_message_type_error, ":error_message"),
(multiplayer_send_message_to_player, ":player_no", multiplayer_event_return_rejection),
(try_end),
(try_end),
# Beaver End
(else_try),
After the last else_try the #Bajo script goes immediately after no empty line as space in-between
#Bajo script
(eq, ":event_type", multiplayer_event_fixBayonet),
(store_script_param,":eventNo",3),
(store_script_param,":var2",4),
(try_begin),
(eq,":eventNo",1), #Event 1 - Fix Bayonet
(assign,":itemFound",0),
(assign,":playerAgent",":var2"),
(agent_is_active, ":playerAgent"),
(agent_is_alive, ":playerAgent"),
(agent_get_slot,":bayonetCooldown",":playerAgent",slot_agent_bayonetCooldown),
(eq,":bayonetCooldown",0),
(agent_get_wielded_item,":curRifle",":playerAgent"),
(item_get_slot,":bayonetItem",":curRifle",slot_item_bayonetItem),
(neq,":bayonetItem",0),
(try_for_range,":curSlot",0,3),
(neq,":itemFound",1),
(agent_get_item_slot,":curItem",":playerAgent",":curSlot"),
(eq,":curItem",":curRifle"),
(assign,":itemFound",1), #break loop
(assign,":itemSlot",":curSlot"),
(try_end),
(eq,":itemFound",1), #the item was found and no witchcraft occurred
(agent_is_active, ":playerAgent"),
(agent_is_alive, ":playerAgent"),
(agent_get_ammo_for_slot,":rifleAmmo",":playerAgent",":itemSlot"),
(agent_get_slot,":isFixed",":playerAgent",slot_item_isFixed),
(try_begin),
(eq,":isFixed",0),
(agent_set_animation,":playerAgent","anim_fix_bayonet"),
(else_try),
(agent_set_animation,":playerAgent","anim_unfix_bayonet"),
(try_end),
(agent_unequip_item,":playerAgent",":curRifle"),
(agent_equip_item,":playerAgent",":bayonetItem"),
(agent_set_wielded_item,":playerAgent",":bayonetItem"),
(try_begin),
(eq,":rifleAmmo",0),
(agent_set_ammo,":playerAgent",":bayonetItem",0),
(try_end),
(agent_is_active, ":playerAgent"),
(agent_is_alive, ":playerAgent"),
(agent_set_slot,":playerAgent",slot_agent_bayonetCooldown,6), #unable to spam bayonet on/off
(try_end), #Bajo script
The script stops at else_try right under Client Events no empty line as space in-between
(else_try),
###############
#CLIENT EVENTS#
###############
(neg|multiplayer_is_dedicated_server),
module_items.py5th and now it is time to add item codes as fix bayonet makes the firearm unique from it's regular counterpart.
The following code is first the item code I put the new codes right under as a test for War of 1812 mod.
#Muskets
# French
["french_charleville", "Infantry Musket", [("french_charleville",0)], itp_cant_use_on_horseback|itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(75),imodbits_none,[]],
# [(ti_on_weapon_attack, [(store_trigger_param_1,":user_agent"),(call_script, "script_server_fire_musket", ":user_agent", firearm_type_musket),])]],
["french_charleville_melee", "Infantry Musket", [("french_charleville",0)], itp_cant_use_on_horseback|itp_has_upper_stab|itp_type_polearm |itp_primary|itp_is_pike|itp_no_blur,itc_spear|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(138)|swing_damage(40 , pierce) | thrust_damage(45 , pierce),imodbits_none ],
# Bayonet fix test
["french_charlevillenobayonet", "Infantry Musket", [("french_charleville2",0)], itp_cant_use_on_horseback|itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(78),imodbits_none,[]],
# [(ti_on_weapon_attack, [(store_trigger_param_1,":user_agent"),(call_script, "script_server_fire_musket", ":user_agent", firearm_type_musket),])]],
["french_charlevillenobayonet_melee", "Infantry Musket", [("french_charleville2",0)], itp_has_upper_stab|itp_type_polearm |itp_primary|itp_no_blur|itp_offset_musket|itp_can_knock_down,itc_musket_melee|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(85)|swing_damage(23 , blunt) | thrust_damage(22 , blunt),imodbits_none ],
["french_charlevilleb", "Infantry Musket with Bayonet", [("french_charleville",0)], itp_cant_use_on_horseback|itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(75),imodbits_none,[]],
["french_charlevilleb_melee", "Infantry Musket with Bayonet", [("french_charleville",0)], itp_cant_use_on_horseback|itp_has_upper_stab|itp_type_polearm |itp_primary|itp_is_pike|itp_no_blur,itc_spear|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(138)|swing_damage(40 , pierce) | thrust_damage(45 , pierce),imodbits_none ],
Same method for the Brown Bess
# British
["british_brown_bess", "Infantry Musket", [("brown_bess_musket",0)], itp_cant_use_on_horseback|itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(75),imodbits_none,[]],
["british_brown_bess_melee", "Infantry Musket", [("brown_bess_musket",0)], itp_cant_use_on_horseback|itp_has_upper_stab|itp_type_polearm |itp_primary|itp_is_pike|itp_no_blur,itc_spear|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(136)|swing_damage(40 , pierce) | thrust_damage(45 , pierce),imodbits_none ],
# Bayonet fix test
["british_brown_bessnobayonet", "Infantry Musket", [("brown_bess_musket2",0)], itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(78),imodbits_none,[]],
# [(ti_on_weapon_attack, [(store_trigger_param_1,":user_agent"),(call_script, "script_server_fire_musket", ":user_agent", firearm_type_rifle)])]],
["british_brown_bessnobayonet_melee", "Infantry Musket", [("brown_bess_musket2",0)], itp_has_upper_stab|itp_type_polearm |itp_primary|itp_no_blur|itp_offset_musket|itp_can_knock_down,itc_musket_melee|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(85)|swing_damage(23 , blunt) | thrust_damage(22 , blunt),imodbits_none ],
["british_brown_bessb", "Infantry Musket with Bayonet", [("brown_bess_musket",0)], itp_cant_use_on_horseback|itp_type_crossbow |itp_merchandise|itp_primary|itp_two_handed|itp_cant_reload_on_horseback|itp_cant_reload_while_moving|itp_next_item_as_melee ,itcf_shoot_musket|itcf_carry_crossbow_back,
683 , weight(3.5)|difficulty(0)|spd_rtng(23) | shoot_speed(250) | thrust_damage(100 ,pierce)|max_ammo(1)|accuracy(75),imodbits_none,[]],
["british_brown_bessb_melee", "Infantry Musket with Bayonet", [("brown_bess_musket",0)], itp_cant_use_on_horseback|itp_has_upper_stab|itp_type_polearm |itp_primary|itp_is_pike|itp_no_blur,itc_spear|itcf_carry_crossbow_back,
180 , weight(0)|difficulty(0)|spd_rtng(85) | weapon_length(136)|swing_damage(40 , pierce) | thrust_damage(45 , pierce),imodbits_none ],
module_animations.py6th if you have an animation here is the code:
Replace these unused animation lines as they will be used now
["unused_human_anim_62", 0, 0, [1.0, "anim_human", 0, 1, 0]],
["unused_human_anim_63", 0, 0, [1.0, "anim_human", 0, 1, 0]],
["unused_human_anim_64", 0, 0, [1.0, "anim_human", 0, 1, 0]],
["unused_human_anim_65", 0, 0, [1.0, "anim_human", 0, 1, 0]],
Replace unused_human_anim_62-65 with the following below.
["fix_bayonet", acf_enforce_all, amf_priority_reload|amf_play, [2, "fix_bayonet", 0, 119, arf_blend_in_8]],
["fix_bayonet_end", 0, amf_priority_mount|amf_play, [0.1, "fix_bayonet", 50, 119, arf_blend_in_1]],
["unfix_bayonet", acf_enforce_all, amf_priority_reload|amf_play, [2, "unfix_bayonet", 0, 119, arf_blend_in_8]],
["unfix_bayonet_end", 0, amf_priority_mount|amf_play, [0.1, "unfix_bayonet", 50, 119, arf_blend_in_1]],
Oddly enough the module_animations.py file already has the fix and unfix bayonet animation lines done for you
["equip_bayonet", 0, amf_priority_equip|amf_play|amf_restart|amf_client_prediction,
[0.3, "equip_musket", 5, 13, arf_blend_in_0],
## [0.8, "equip_arms", 253, 276, arf_blend_in_0]
],
["unequip_bayonet", 0, amf_priority_equip|amf_play|amf_restart|amf_client_prediction,
[0.3, "equip_musket", 5, 13, arf_blend_in_0],
## [0.2, "equip_arms", 254, 250, arf_blend_in_0]
Finally the OSP animation for fix and unfix bayonet, located in modified vanilla mmanimations BRF file for your convenience.
Download this:
https://drive.google.com/file/d/0B_XEt5J8_HVnN3lDVEhtYWFpNk0/edit?usp=sharingAnd replace your mmanimations.brf with it and enjoy the fix/unfix bayonet OSP code & animation.
Let me know how this guide works for you, if you need any help feel free to post your issues. Feedback is appreciated!
The things I do when I can't sleep, ha.
Credits of the animation goes to
caseofinsanityCredits:
•The musket models without bayonet are modified versions of the original fixed muskets.
•The fixing&unfixing animations were made by me, CaseOfInsanity and it's free to use. If your mod ends up using the animations, it would be nice of you to mention my name