OSP Code Combat [WB] Weapon breaking trigger

Users who are viewing this thread

great work here!

You have forgot a "," en try_end:

                (troop_get_inventory_slot_modifier, ":imod", "trp_player", ":i_slot"),
            (try_end),


I have try join your code with Cruger´s code, and look it work:

#Brytenwalda -Baron Conrad script- armas se rompen
common_weapon_break =  (
        0.4, 0, 0,
      [], [
     
      #(player_get_agent_id, ":player_agent", ":player_no"),
#Cruger MODIFICATION BEGIN---------------------------------------------------------------------------
      # (get_player_agent_no, ":player_agent"),
    (try_for_agents, ":player_agent"),
#Cruger 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
      (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"),
#--Cabadrin imod, get weapon imod
            (try_for_range, ":i_slot", 0, 10),
                (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),  #Find Item Slot with same item ID as Equipped Weapon
                (eq, ":item_id", ":breakweapon"),
                (troop_get_inventory_slot_modifier, ":imod", "trp_player", ":i_slot"),
            (try_end),
#--End Get imod
          (agent_get_horse,":playermounted",":player_agent"),
          (store_random_in_range,":weaponbreakchance",1,100),
          (try_begin),
            (ge,":playermounted",0),
      #      (display_message, "@Mounted."),
              (val_mul,":weaponbreakchance",84), 
            (val_div,":weaponbreakchance",100),
            (eq,itp_type_polearm,":weapontype"),
            (val_mul,":weaponbreakchance",90),
            (val_div,":weaponbreakchance",100),
            (try_end),
        (try_begin),         
            (eq,itp_type_polearm,":weapontype"),
      #      (display_message, "@Polearm"),
            (val_mul,":weaponbreakchance",82),
            (val_div,":weaponbreakchance",100),
          (try_end),
          (try_begin),         
            (eq,itp_type_two_handed_wpn,":weapontype"),
      #      (display_message, "@2 hander"),
            (val_mul,":weaponbreakchance",81),
            (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),
#--Cabadrin imod Quality Modifier
    #Better than Average
        (try_begin),
            (eq, imodbit_masterwork, ":imod"),
            (val_mul,":weaponbreakchance",40),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_tempered, ":imod"),
            (val_mul,":weaponbreakchance",50),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_balanced, ":imod"),
            (val_mul,":weaponbreakchance",60),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_heavy, ":imod"),
            (val_mul,":weaponbreakchance",70),
            (val_div,":weaponbreakchance",100),
        (try_end),
    #Worse than Average
        (try_begin),
            (eq, imodbit_bent, ":imod"),
            (val_mul,":weaponbreakchance",80),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_rusty, ":imod"),
            (val_mul,":weaponbreakchance",90),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_chipped, ":imod"),
            (val_mul,":weaponbreakchance",105),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_cracked, ":imod"),
            (val_mul,":weaponbreakchance",120),
            (val_div,":weaponbreakchance",100),
        (try_end),
#--End imod Quality Modifier
    (try_begin), 
            (assign, reg8, ":weaponbreakchance"),
      #      (display_message, "@{reg8}"),
            (ge,":weaponbreakchance",9:cool:,
#Cruger 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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
            (agent_unequip_item,":player_agent",":breakweapon"),
#Cruger 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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
            (lt,":playermounted",0),
            (agent_set_animation, ":player_agent", "anim_strike_chest_front"),
            (try_end),
   
      (try_end),
      (try_end),])
#brytenwalda armas se rompen acaba

 
Hey, for some reason I'm getting this syntax error:

SyntaxError: invalid syntax
Traceback (most recent call last):
  File "process_global_variables_unused.py", line 3, in <module>
    from process_operations import *
  File "C:\Users\Admin\Desktop\OSPW - Native 1.127c Module_system\process_operat
ions.py", line 21, in <module>
    from module_mission_templates import *
  File "C:\Users\Admin\Desktop\OSPW - Native 1.127c Module_system\module_mission
_templates.py", line 1236
    common_weapon_break =  (
                                            ^

Any idea why or how I can fix it (I'm new to this stuff, sorry for being a Noob)
 
Baron Conrad said:
N0body, did you alter it in any way?


Caba ' drin, I did think about doing that, just never got round to it.

Glad that you guys are taking it even further!

Nope, I did use Idibil's version of the code and I put it right after every common_battle_tab_press,
I'm going to try using the original now, and see if that works.

EDIT:
Managed to get it working, as I was a bit stupid and misread you post (Top of this page) and was putting the entire code after each common_battle_tab_press, :roll:
Sorry about that :???: maybe I should make sure I read everything properly next time  :razz:
It still gets a 'minor' error though: ERROR: Usage of unassigned local variable: :playeraction
EDIT:
Ingame weapons don't seem to break, so I'm guessing that error is actually breaking the script?
 
Idibil said:
N0body, you try now, i had paste code that i am using in Brytenwalda.


Ah, and remmenber add: common_weapon_break, --->lead_charge and mission where you want weapon break.

Thanks!  :grin: Looks like it has worked, no errors. Now to test it.  :smile:

Edit:
Hmmm.... I had 3 weapons on me (Ranging from cracked to tempered) and none of them broke - I was on horseback too.
I didn't notice and NPC's weapons breaking either  :neutral:
Am I doing something wrong? I've put Idibil's version of the code before the very first multiplayer_server_check_belfry_movement and then put common_weapon_break, after every common_battle_tab_press,
 
Ibdil, I think your changes to the numbers may have been a little too drastic, that is why N0body never had his weapons break.

The way the system works right now is this:

First it picks a random number 1-100, the higher it is the more likely a weapon is to break.

Then it does the math things depending on weapon type, mounted, and modifers (what you added)

So in your code for a one handed weapon it multiplies by 81 and divides by 100, in other words, it multiplies by .81

Even if the random chance earlier in the  script is a 100 then the result is 100 * .81 = 81

At the end you notice that the weapon will only break if the result is 98 or higher.

Average one handed weapons would never break.


My numbers may have been to high to start with but when you lower them you need to lower them very slightly because if you lower them too much then they may never break.

 
Yes, i am tested it. Brytenwalda betatester complained that the weapons are very easily broken, even in a first encounter. I am looking for equilibrate break, a sword could for generations, or break a particularly aggressive encounter.

I can change result of 98 to 95  :grin:
 
I'm wondering why the code isn't doing anything - I've had no errors either.  :neutral:
I set the chance for each Imod bits to 135, the weapons still didn't break.
I even set the chance from 98 to 28, still nothing. I'm guessing this code doesn't like me  :sad:
 
Idibil said:
I can change result of 98 to 95  :grin:

It will make more difference to change the multipliers.

Also I don't think having the multiplier smaller than the divider is a good idea unless the requirement is something that would make the weapon stronger, for example, masterwork.

To N0body, how many weapons did you have in your inventory, Crugers additions make it so your weapon only breaks if you have more than one weapon, I personally wouldn't use that.

Also, I hope you added

common_weapon_break,

to the mission templates you wanted it in.
 
Baron Conrad said:
Idibil said:
I can change result of 98 to 95  :grin:

It will make more difference to change the multipliers.

Also I don't think having the multiplier smaller than the divider is a good idea unless the requirement is something that would make the weapon stronger, for example, masterwork.

To N0body, how many weapons did you have in your inventory, Crugers additions make it so your weapon only breaks if you have more than one weapon, I personally wouldn't use that.

Also, I hope you added

common_weapon_break,

to the mission templates you wanted it in.

I had 3 weapons on me.
I added the  common_weapon_break,  after every    common_battle_tab_press,    (As you had said on one of your other posts)
I think I know what the problem may be though - I'm editing a mod for personal use (OSPW) And it may not like this script.
 
@Baron Conrad

It will make more difference to change the multipliers.

Also I don't think having the multiplier smaller than the divider is a good idea unless the requirement is something that would make the weapon stronger, for example, masterwork.

I am trying test better option in this. It should be too easy break.
You had do great work here, if i dont say it to you before  :grin:
 
I don't know what to say, I used his script and set the 98 to 28 it worked fine.

also remove the "#"

from

#      (display_message, "@{reg8}"),

and it should say the result number after each hit in-game, that way you can see if it is just luck or not.
 
I think that he had copy code bad in mision_templates.py

Install:

#  Please note that mission templates is work in progress and can be changed in the future versions.
#
####################################################################################################################

pilgrim_disguise = [itm_pilgrim_hood,itm_pilgrim_disguise,itm_practice_staff, itm_throwing_daggers]
af_castle_lord = af_override_horse | af_override_weapons| af_require_civilian

######CODE BREAK HERE BEGIN
#Brytenwalda -Baron Conrad script- armas se rompen
common_weapon_break =  (
        0.4, 0, 0,
      [], [
   
      #(player_get_agent_id, ":player_agent", ":player_no"),
#Cruger MODIFICATION BEGIN---------------------------------------------------------------------------
      # (get_player_agent_no, ":player_agent"),
    (try_for_agents, ":player_agent"),
#Cruger 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
      (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"),
#--Cabadrin imod, get weapon imod
            (try_for_range, ":i_slot", 0, 10),
                (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),  #Find Item Slot with same item ID as Equipped Weapon
                (eq, ":item_id", ":breakweapon"),
                (troop_get_inventory_slot_modifier, ":imod", "trp_player", ":i_slot"),
            (try_end),
#--End Get imod
          (agent_get_horse,":playermounted",":player_agent"),
          (store_random_in_range,":weaponbreakchance",1,100),
          (try_begin),
            (ge,":playermounted",0),
      #      (display_message, "@Mounted."),
              (val_mul,":weaponbreakchance",84), 
            (val_div,":weaponbreakchance",100),
            (eq,itp_type_polearm,":weapontype"),
            (val_mul,":weaponbreakchance",90),
            (val_div,":weaponbreakchance",100),
            (try_end),
        (try_begin),         
            (eq,itp_type_polearm,":weapontype"),
      #      (display_message, "@Polearm"),
            (val_mul,":weaponbreakchance",82),
            (val_div,":weaponbreakchance",100),
          (try_end),
          (try_begin),         
            (eq,itp_type_two_handed_wpn,":weapontype"),
      #      (display_message, "@2 hander"),
            (val_mul,":weaponbreakchance",81),
            (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),
#--Cabadrin imod Quality Modifier
    #Better than Average
        (try_begin),
            (eq, imodbit_masterwork, ":imod"),
            (val_mul,":weaponbreakchance",40),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_tempered, ":imod"),
            (val_mul,":weaponbreakchance",50),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_balanced, ":imod"),
            (val_mul,":weaponbreakchance",60),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_heavy, ":imod"),
            (val_mul,":weaponbreakchance",70),
            (val_div,":weaponbreakchance",100),
        (try_end),
    #Worse than Average
        (try_begin),
            (eq, imodbit_bent, ":imod"),
            (val_mul,":weaponbreakchance",80),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_rusty, ":imod"),
            (val_mul,":weaponbreakchance",90),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_chipped, ":imod"),
            (val_mul,":weaponbreakchance",105),
            (val_div,":weaponbreakchance",100),
        (try_end),
        (try_begin),
            (eq, imodbit_cracked, ":imod"),
            (val_mul,":weaponbreakchance",120),
            (val_div,":weaponbreakchance",100),
        (try_end),
#--End imod Quality Modifier
    (try_begin), 
            (assign, reg8, ":weaponbreakchance"),
      #      (display_message, "@{reg8}"),
            (ge,":weaponbreakchance",9:cool:,
#Cruger 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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
            (agent_unequip_item,":player_agent",":breakweapon"),
#Cruger 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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
            (lt,":playermounted",0),
            (agent_set_animation, ":player_agent", "anim_strike_chest_front"),
            (try_end),
   
      (try_end),
      (try_end),])
#brytenwalda armas se rompen acaba
###CODE BREAK END HERE


multiplayer_server_check_belfry_movement = (
  0, 0, 0, [],
  [
    (multiplayer_is_server),
    (set_fixed_point_multiplier, 100),

Now, my suggestion (future you add most code) is you writte is:

### CODE BREAK BEGIN HERE
code_battles = [
  common_weapon_break,
  ]
#########CODE BREAK END HERE

multiplayer_server_check_belfry_movement = (
  0, 0, 0, [],
  [
    (multiplayer_is_server),
    (set_fixed_point_multiplier, 100),


Finally, you go to lead_charge and add black  end:

      common_battle_order_panel,
      common_battle_order_panel_tick,

    ]+ code_battles,
  ),

You have can add code to village_attack_bandits, village_raid and quick_battle_battle also.

If you change 98 to 28 like said Baron Conrad, you can see fastly if it run well.


 
Thanks for your help guys - I tried doing a native version of the latest version of the script and it worked, but it seems incompatible with OSPW like the other versions of the script. It works fine on a native module - though I'm not sure why the other versions didn't...
It's a great script and adds a whole new factor of realism, thanks for sharing it, and thanks to those that edited it & improved.  :smile:

When using the OSPW module, no numbers are generated at all, it seems the script is ignored or something like that.
 
Finally back at a machine with Warband installed, I was able to test my additions to the script. I had to make a few minor adjustments, but things are working as they should now. Modifiers affect both chance and damage correctly for all weapons the player begins the battle with.

common_weapon_break =  (
        0.4, 0, 0,
      [

      (get_player_agent_no, ":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"),
#--imod, get weapon imod
            (try_for_range, ":i_slot", 0, 5),
              (troop_get_inventory_slot, ":item_id", "trp_player", ":i_slot"),  #Find Item Slot with same item ID as Equipped Weapon
(eq, ":item_id", ":breakweapon"),
(troop_get_inventory_slot_modifier, ":imod", "trp_player", ":i_slot"),
(assign, ":weaponslot", ":i_slot"),
            (try_end),
#--End Get imod
            (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),
#--imod Quality Modifier
    #Better than Average, Number <100 to decrease chance
(try_begin),
(eq, imod_masterwork, ":imod"),
(val_mul,":weaponbreakchance",50),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_tempered, ":imod"),
(val_mul,":weaponbreakchance",70),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_balanced, ":imod"),
(val_mul,":weaponbreakchance",80),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_heavy, ":imod"),
(val_mul,":weaponbreakchance",90),
(val_div,":weaponbreakchance",100),
(try_end),
    #Worse than Average, Number >100 to increase chance
(try_begin),
(eq, imod_bent, ":imod"),
(val_mul,":weaponbreakchance",110),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_rusty, ":imod"),
(val_mul,":weaponbreakchance",120),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_chipped, ":imod"),
(val_mul,":weaponbreakchance",130),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_cracked, ":imod"),
(val_mul,":weaponbreakchance",150),
(val_div,":weaponbreakchance",100),
(try_end),
#--End imod Quality Modifier
(try_begin),
(ge,":weaponbreakchance",9:cool:,
#--imod Weapon Damage
    #Better than Average
(try_begin),
(eq, imod_masterwork, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", imod_balanced),
(else_try),
(eq, imod_tempered, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", 0),
(else_try),
(eq, imod_balanced, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", 0),
(else_try),
(eq, imod_heavy, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", imod_chipped),
#Normal Weapon gets Chipped
(else_try),
(eq, 0, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", imod_chipped),
    #Worse than Average
(else_try),
(eq, imod_bent, ":imod"),
(troop_set_inventory_slot_modifier, "trp_player", ":weaponslot", imod_cracked),
    #Chipped, Cracked, Rusty weapons break
(else_try),
(this_or_next|eq, imod_rusty, ":imod"),
(this_or_next|eq, imod_chipped, ":imod"),
(eq, imod_cracked, ":imod"),
(agent_unequip_item,":player_agent",":breakweapon"),
(play_sound,"snd_shield_broken",),
(troop_remove_item, "trp_player", ":breakweapon"),
(display_message, "@Hah! Your weapon broke."),
(lt,":playermounted",0),
(agent_set_animation, ":player_agent", "anim_strike_chest_front"),
(try_end),
#--End imod Weapon Damage
      (try_end),

      (try_end),
      ], [])


And now this should work with all agents. The below doesn't work as intended, at all.
common_weapon_break =  (
        0.4, 0, 0,
      [

#Cruger MODIFICATION BEGIN---------------------------------------------------------------------------
    (try_for_agents, ":player_agent"),
  (agent_get_troop_id,":troop", ":player_agent"),
#Cruger 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"),
#--imod, get weapon imod
            (try_for_range, ":i_slot", 0, 5),
              (troop_get_inventory_slot, ":item_id", ":troop", ":i_slot"),  #Find Item Slot with same item ID as Equipped Weapon
(eq, ":item_id", ":breakweapon"),
(troop_get_inventory_slot_modifier, ":imod", ":troop", ":i_slot"),
(assign, ":weaponslot", ":i_slot"),
            (try_end),
#--End Get imod
            (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),
#--imod Quality Modifier
    #Better than Average, Number <100 to decrease chance
(try_begin),
(eq, imod_masterwork, ":imod"),
(val_mul,":weaponbreakchance",50),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_tempered, ":imod"),
(val_mul,":weaponbreakchance",70),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_balanced, ":imod"),
(val_mul,":weaponbreakchance",80),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_heavy, ":imod"),
(val_mul,":weaponbreakchance",90),
(val_div,":weaponbreakchance",100),
(try_end),
    #Worse than Average, Number >100 to increase chance
(try_begin),
(eq, imod_bent, ":imod"),
(val_mul,":weaponbreakchance",110),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_rusty, ":imod"),
(val_mul,":weaponbreakchance",120),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_chipped, ":imod"),
(val_mul,":weaponbreakchance",130),
(val_div,":weaponbreakchance",100),
(try_end),
(try_begin),
(eq, imod_cracked, ":imod"),
(val_mul,":weaponbreakchance",150),
(val_div,":weaponbreakchance",100),
(try_end),
#--End imod Quality Modifier
(try_begin),
(ge,":weaponbreakchance",9:cool:,
#--imod Weapon Damage
    #Better than Average
(try_begin),
(eq, imod_masterwork, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", imod_balanced),
(else_try),
(eq, imod_tempered, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", 0),
(else_try),
(eq, imod_balanced, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", 0),
(else_try),
(eq, imod_heavy, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", imod_chipped),
#Normal Weapon gets Chipped
(else_try),
(eq, 0, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", imod_chipped),
    #Worse than Average
(else_try),
(eq, imod_bent, ":imod"),
(troop_set_inventory_slot_modifier, ":troop", ":weaponslot", imod_cracked),
    #Chipped, Cracked, Rusty weapons break
(else_try),
(this_or_next|eq, imod_rusty, ":imod"),
(this_or_next|eq, imod_chipped, ":imod"),
(eq, imod_cracked, ":imod"),
#Cruger 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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
(agent_unequip_item,":player_agent",":breakweapon"),
#Cruger MODIFICATION BEGIN----------------------------------------------------------------------------
(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),
#Cruger MODIFICATION END------------------------------------------------------------------------------
(lt,":playermounted",0),
(agent_set_animation, ":player_agent", "anim_strike_chest_front"),
(try_end),
#--End imod Weapon Damage
      (try_end), #>98
  (try_end),  #Action=3
      (try_end),  #Loop for all agents
      ], [])

For some reason, if the player picks up a weapon, the script is not identifying its "slot" correctly and thus can't identify its modifier and the weapon becomes invulnerable. Does anyone know what slot a weapon picked up in battle is assigned to? Or why the script wouldn't be able to identify it?


EDIT: All agents doesn't work...and the varied damage doesn't really work as intended either. The changes to the break chance are the only portion that truly work as intended. I haven't found a way to better this though. The coding I have done is left up for posterity's sake.
 
There are lots of problems with that code, especially within the all agent adjustment.
Code:
      (agent_get_wielded_item,":breakweapon",":player_agent",0),
      (gt,":breakweapon", 0),
Not sure why 2 was used - fists are -1, while itm_no_item is 0. In addition, all items for regular troops are imod_none, so there's no need to fetch that in most cases. Furthermore, regular troops do not make use of those slots - they may spawn with anything in their inventory. You must fetch these items at spawn-time, using slots for weapons. After that, you loop through those agent slots instead of ek_item slots.

Otherwise, just adjust the loop - you're only looking for the one item that matches.
Code:
(assign, ":imod", imod_plain),
(assign, ":end", ek_head),#this is 4, not 5
(try_for_range, ":i_slot", ek_item_0, ":end"),
    (troop_get_inventory_slot, ":item_id", ":troop", ":i_slot"),  #Find Item Slot with same item ID as Equipped Weapon
    (eq, ":item_id", ":breakweapon"),    
    (assign, ":weaponslot", ":i_slot"),
    (assign, ":end", 0),#loop breaker
    (troop_is_hero, ":troop"),
    (troop_get_inventory_slot_modifier, ":imod", ":troop", ":i_slot"),
(try_end),

I'm not sure if reducing imod has an effect - try dropping your item after it degrades and see the modifier on the spawned item. Also, make use of this_or_next, like so:
Code:
         (else_try),
            (this_or_next|eq, ":imod", imod_tempered),
            (eq, ":imod", imod_balanced),
            (troop_set_inventory_slot_modifier, ":troop", ":weaponslot", 0),
         (else_try),
            (this_or_next|eq, ":imod", imod_heavy),
            (eq, ":imod", imod_plain),   #Normal Weapon gets Chipped
            (troop_set_inventory_slot_modifier, ":troop", ":weaponslot", imod_chipped),
         (else_try),

Cruger's modification is slow since it loops through all the items - which can number in the thousands. Instead, you'll want to check the items the troop can have in its inventory, like so
Code:
            (troop_get_inventory_capacity, ":cap", ":troop"),
            (try_for_range, ":item_slot", ek_item_0, ":cap"),
               (troop_get_inventory_slot, ":item", ":troop", ":item_slot"),
               (neq,":item", ":breakweapon"),
               (item_get_type, ":weapontype2", ":item"),
               (is_between, ":weapontype2", itp_one_handed_wpn, itp_type_arrows),
               (try_begin),
                   (agent_has_item_equipped,":player_agent",":item"),
                   (val_add, ":num_agent_items", 1),
                (try_end),
                (try_begin),
                   (ge, ":num_agent_items", 2),
                   (assign, ":cap", 0),
                (try_end),
            (try_end),
            (agent_unequip_item,":player_agent",":breakweapon"),
            (try_begin),
               (eq, ":player", "trp_player"), #we already fetched troop_id
               (play_sound,"snd_shield_broken",),
               (troop_remove_item, ":troop", ":breakweapon"),
               (display_message, "@Hah! Your weapon broke."),
            (try_end),

I assume the point of the first snippet is to ensure that the troop has another melee weapon before losing its first. So I broke out of the loop as soon as it found 2, since the item doesn't appear to be used in agent_set_wielded_item or anything. Again, using agent slots would mean you only need to check 4 times for the 4 possible items all agents carry. The second part refetches the player's agent, when we already fetched the troop's id - so we compare it to trp_player instead of comparing agents.
 
I appreciate the adjustments you've suggested to the mash together I attempted--I simply tried the most direct way of putting my player-centered code with Cruger's. I should have thought much more carefully about the repercussions of that. It was definitively sloppy.

Somebody said:
I'm not sure if reducing imod has an effect - try dropping your item after it degrades and see the modifier on the spawned item.

From my testing, reducing the imod as I've coded has the following effects:
-After an imod reduction, the next time the script is called, the lowered imod is used; this leads me to believe it has been correctly stored with the item.
-It takes 2 successful "damages" to destroy a normal weapon; 3 for a tempered/balanced weapon; 4 for a masterwork weapon.
-After the battle, the script-adjusted imod is still applied to the item. If the player enters battle with a normal weapon and it gets chipped, it will be chipped in the inventory after the battle.

However, I'm unsure if reducing the imod immediately impacts the damage/speed of the weapon.
 
Back
Top Bottom