WB NW Droping/removeing swords when equiping bayonet

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
Hey, friend. Not entirely sure what you mean here. If you're saying the bayonet is a knife in the inventory you'll want to amend this by doing something like

Changes marked in Red, my comments in Orange
#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, ":bayonet", "itm_bayonet"), # or whatever the bayonet item_id is, if you want a different one per rifle, make a new slot called slot_item_unique_bayonet and assign them there. Then move this down to the commented out section below
(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),

# (item_get_slot,":bayonet",":curRifle", slot_item_unique_bayonet), # this is a variant needed if you want a different bayonet per rifle
(neq,":bayonetItem",0),
(try_for_range,":curSlot",0,3),
(neq,":itemFound",1),
(agent_get_item_slot,":curItem",":playerAgent",":curSlot"),
(try_begin),
(eq,":curItem",":curRifle"),
(assign,":itemFound",1), #break loop
(assign,":itemSlot",":curSlot"),

(else_try),
(eq,":curItem",":bayonet"),
(assign, ":bayonet_in_inventory", 1),
(assign, ":bayonet_itemSlot", ":curSlot"),
(try_end),

(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),

(eq,":bayonet_in_inventory",1),
(agent_set_animation,":playerAgent","anim_fix_bayonet"),
(agent_unequip_item, ":playerAgent", ":bayonet", ":bayonet_itemSlot"), # using the item slot will ensure that an agent can carry multiple bayonet items without being forced to unequip them all.
(else_try),
(agent_set_animation,":playerAgent","anim_unfix_bayonet"),

(agent_equip_item, ":playerAgent", ":bayonet"), # This assumes there is an empty slot. That ~should~ be true since we had to unequip an item to make this true, but if the agent picked something in the meantime this would fail.
(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

Sorry about the tabs, being inside a spoiler ruins that

Of course, this is entirely untested and I am only guessing at what you are asking.

The way this works is pretty straight forward. It adds a check that there is a bayonet weapon in the inventory of the agent, and if there is, and the current rifle is a variant without a bayonet, it unequips the last bayonet weapon in the equip slots, and changes the variant just like the base version. Then, if the player is swapping from a bayoneted variant, it assumes there should be an open inventory slot, equips the bayonet weapon, and changes the rifle's variant just as the base did.
 

Waffss

Recruit
Best answers
0
Hey, friend. Not entirely sure what you mean here. If you're saying the bayonet is a knife in the inventory you'll want to amend this by doing something like

Changes marked in Red, my comments in Orange
#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, ":bayonet", "itm_bayonet"), # or whatever the bayonet item_id is, if you want a different one per rifle, make a new slot called slot_item_unique_bayonet and assign them there. Then move this down to the commented out section below
(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),

# (item_get_slot,":bayonet",":curRifle", slot_item_unique_bayonet), # this is a variant needed if you want a different bayonet per rifle
(neq,":bayonetItem",0),
(try_for_range,":curSlot",0,3),
(neq,":itemFound",1),
(agent_get_item_slot,":curItem",":playerAgent",":curSlot"),
(try_begin),
(eq,":curItem",":curRifle"),
(assign,":itemFound",1), #break loop
(assign,":itemSlot",":curSlot"),

(else_try),
(eq,":curItem",":bayonet"),
(assign, ":bayonet_in_inventory", 1),
(assign, ":bayonet_itemSlot", ":curSlot"),
(try_end),

(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),

(eq,":bayonet_in_inventory",1),
(agent_set_animation,":playerAgent","anim_fix_bayonet"),
(agent_unequip_item, ":playerAgent", ":bayonet", ":bayonet_itemSlot"), # using the item slot will ensure that an agent can carry multiple bayonet items without being forced to unequip them all.
(else_try),
(agent_set_animation,":playerAgent","anim_unfix_bayonet"),

(agent_equip_item, ":playerAgent", ":bayonet"), # This assumes there is an empty slot. That ~should~ be true since we had to unequip an item to make this true, but if the agent picked something in the meantime this would fail.
(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

Sorry about the tabs, being inside a spoiler ruins that

Of course, this is entirely untested and I am only guessing at what you are asking.

The way this works is pretty straight forward. It adds a check that there is a bayonet weapon in the inventory of the agent, and if there is, and the current rifle is a variant without a bayonet, it unequips the last bayonet weapon in the equip slots, and changes the variant just like the base version. Then, if the player is swapping from a bayoneted variant, it assumes there should be an open inventory slot, equips the bayonet weapon, and changes the rifle's variant just as the base did.
Hi thanks for replying ill try your updated code later today although im haveing problems with the animation it only plays the fix bayonet animation and not the unfix one would you know the cause of this by any chance and again thanks for replying
 

Waffss

Recruit
Best answers
0
Hi thanks for replying ill try your updated code later today although im haveing problems with the animation it only plays the fix bayonet animation and not the unfix one would you know the cause of this by any chance and again thanks for replying
Ive narrowed it down and im 90 percent sure the issue is with the script which is exactly as in the tutorial i linked
 

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
That could be a number of things, but you might try raising the animation priority first. Right now it's set to amf_priority_mount which is to say 60, so if another animation is playing with a higher priority, it won't take effect. I personally use 71 in a lot of my stuff which pretty much will take priority over all other animations outside of being hit.

Outside of that, make sure the animations are declared properly and that they are inside the *.brf and the brf is named inside module.ini
 

Waffss

Recruit
Best answers
0
That could be a number of things, but you might try raising the animation priority first. Right now it's set to amf_priority_mount which is to say 60, so if another animation is playing with a higher priority, it won't take effect. I personally use 71 in a lot of my stuff which pretty much will take priority over all other animations outside of being hit.

Outside of that, make sure the animations are declared properly and that they are inside the *.brf and the brf is named inside module.ini
That didn't work, Here is my script so far without your update, If possible could you take a look at it thanks
Python:
#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
      (else_try),
From my testing ive figured out that when i change the number in (eq,":isFixed",0), it will play the other animation both (for example if set to 0 it plays fix bayonet animation when fixing and unfixing oppisite if set to 1)

and for your new code you sent ill try it once I figure this out. Thanks again
 

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
To help you think like a WB scripter, I'm going to walk through my thought process in bugfixing.

First: Identify the bug.
The try_*** loop is always claiming ":isFixed" = 0, so we'll start with that.

Second: Think about what could cause the bug.
One of two things might be happening, the slot is either being overwritten, or it's not being updated.
So we'll look though the script for an agent_set_slot operation pointing at slot_item_isFixed.
There is none, so that means the slot is never updated to reflect the bayonet's state, meaning it's always 0.
So we need to add a agent_set_slot to the consequence block.

Update this section to include slot setting:
Python:
                (try_begin),
                    (eq,":isFixed",0),
                    (agent_set_animation,":playerAgent","anim_fix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 1), # 1 marks the bayonet as fixed
                            (else_try),
                    (agent_set_animation,":playerAgent","anim_unfix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 0), # 0 marks the bayonet as unfixed
                (try_end),
Keep in mind that I didn't check the other mission_template scripts, so maybe the other lines do it. But it should be handled here, to be honest.

Join us in the Modding Discord for faster responses, by some guys much more skilled than me.
 
Last edited:

Waffss

Recruit
Best answers
0
To help you think like a WB scripter, I'm going to walk through my thought process in bugfixing.

First: Identify the bug.
The try_*** loop is always claiming ":isFixed" = 0, so we'll start with that.

Second: Think about what could cause the bug.
One of two things might be happening, the slot is either being overwritten, or it's not being updated.
So we'll look though the script for an agent_set_slot operation pointing at slot_item_isFixed.
There is none, so that means the slot is never updated to reflect the bayonet's state, meaning it's always 0.
So we need to add a agent_set_slot to the consequence block.

Update this section to include slot setting:
Python:
                (try_begin),
                    (eq,":isFixed",0),
                    (agent_set_animation,":playerAgent","anim_fix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 1), # 1 marks the bayonet as fixed
                            (else_try),
                    (agent_set_animation,":playerAgent","anim_unfix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 0), # 0 marks the bayonet as unfixed
                (try_end),
Keep in mind that I didn't check the other mission_template scripts, so maybe the other lines do it. But it should be handled here, to be honest.

Join us in the Modding Discord for faster responses, by some guys much more skilled than me.
Thanks this worked I've also tried your first script with the unequipping the bayonet sabre but it causes the same problem as before with it playing the only one animation and it also doesn't unequip the saber bayonet here is the combined script for them both.
Python:
#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, ":bayonet", "itm_british_baker_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"),
                    (try_begin),
                    (eq,":curItem",":curRifle"),
                    (assign,":itemFound",1), #break loop
                    (assign,":itemSlot",":curSlot"),
                    (else_try),
                    (eq,":curItem",":bayonet"),
                    (assign, ":bayonet_in_inventory", 1),
                    (assign, ":bayonet_itemSlot", ":curSlot"),
                    (try_end),
                (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),
                    (eq,":bayonet_in_inventory",1),
                    (agent_set_animation,":playerAgent","anim_fix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 1), # 1 marks the bayonet as fixed
                    (agent_unequip_item, ":playerAgent", ":bayonet", ":bayonet_itemSlot"),
                            (else_try),
                    (agent_set_animation,":playerAgent","anim_unfix_bayonet"),
                    (agent_set_slot,":playerAgent",slot_item_isFixed, 0), # 0 marks the bayonet as unfixed
                    (agent_equip_item, ":playerAgent", ":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
 

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
I can tell you, but you should think read through the try_for_range item slot loop line by line and see why this could be.

Python:
(try_for_range,":curSlot",0,3),
                    (neq,":itemFound",1),
                    (agent_get_item_slot,":curItem",":playerAgent",":curSlot"),
                    (try_begin),
                    (eq,":curItem",":curRifle"),
                    (assign,":itemFound",1), #break loop
                    (assign,":itemSlot",":curSlot"),
                    (else_try),
                    (eq,":curItem",":bayonet"),
                    (assign, ":bayonet_in_inventory", 1),
                    (assign, ":bayonet_itemSlot", ":curSlot"),
                    (try_end),
                (try_end),
Line 1: The loop will run through slots 0, 1, and 2. This is the top, and two middle, inventory slots. First bump that 3 to a 4, since there are four weapon slots and try for range loops do not include the last int of the range.
Line 2: This will prevent any lines below this to be read if ":itemFound" is equal to 1. It's a loop breaker. We'll come back to this.
Line 4: If the ":curItem" is equal to the previously assigned ":curRifle" continue inside this try_*** block.
Line 5: If this line is read, the ":itemFound" is set to 1, and the loop breaks. This is why the bayonet isn't being checked. If the bayonet comes after the rifle, the loop is already broken and it doesn't have a chance to be read and set.

So, we the easiest fix would be to split this to two try_for_ranges, one for bayonets and one for rifles.

Python:
(try_for_range,":curSlot",0,4), # Remember, always desired range +1
                    (agent_get_item_slot,":curItem",":playerAgent",":curSlot"),
                    (eq,":curItem",":bayonet"),
                    (assign, ":bayonet_in_inventory", 1),
                    (assign, ":bayonet_itemSlot", ":curSlot"),
                (try_end),
Just pop that in underneath the Rifles loop, but before the (eq,":itemFound",1), flow control. And, of course, remove the additions made to the rifle try_for_range loop.
 
Last edited:

Waffss

Recruit
Best answers
0
Thank you so much it works perfectly and I can't thank you enough. Your replies were always great descriptive and easy to follow. I truly thank you one more question for mount and blade scripting would I need to learn mount and blade specific code or just standard python and do you know any good guides on it?. Again thank you and ill make sure that if i ever get anything done that you will be credited.
 

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
I appreciate that, but no credit is necessary. I was doing it for that best answer diamond.

I suggest getting intimately familiar with the latest version of Lav's header_operations and just reading through interesting snippets in the forums and through open source module systems until you feel confident in your understanding on what everything means.

Knowing Python could help, but I can't write a single line of Python so I don't know if those skills are exactly transferrable.
 

Waffss

Recruit
Best answers
0
Hi me again forgot to ask you last time if you could expand on the ''(assign, ":bayonet", "itm_bayonet"), # or whatever the bayonet item_id is, if you want a different one per rifle, make a new slot called slot_item_unique_bayonet and assign them there. Then move this down to the commented out section below'' I'm not really sure what you meant by assigning them there? thanks
 

SupaNinjaMan

Baron
M&BWBWF&SNWVC
Best answers
9
So the version I had posted, with comments intact, assumes all rifles use the same sabre. But, if you wanted a different sabre per rifle, you could create a slot like slot_item_unique_bayonet in module_constants, and uncomment
Python:
# (item_get_slot,":bayonet",":curRifle", slot_item_unique_bayonet), # this is a variant needed if you want a different bayonet per rifle
in order to change the check from a single sabre item, to the sabre item stored in that slot.

Of course you'd need to update the Fixbayoneta code to include the bayonets on both the bayoneted and non-bayoneted versions of the rifles.

You could also do it without slots, but by using slots this script stays modular and you can just keep adding rifles and assigning the appropriate slots without any changes.