Improved looting system! Especially for the amount of war booties is over 96

Users who are viewing this thread

rubik

Squire
As is known to all, the max inventory slots of a troop(with 10 inventory Management) is 96, so do the amount of war booties.

Related code is here in module_scripts.py. It makes trp_temp_troop to loot all the defeated enemies one by one. Maybe when trp_temp_troop had looted some low-level troops preceding, its inventory is full with 96 poor items, then it can't loot the high-level troops left with good items. It's a big loss.
      (party_get_num_companion_stacks, ":num_stacks",":enemy_party"),
      (try_for_range,
":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,
":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero,
":stack_troop"),
        (party_stack_get_size,
":stack_size",":enemy_party",":i_stack"),
        (try_for_range,
":unused", 0, ":stack_size"),
          (troop_loot_troop,
"trp_temp_troop", ":stack_troop", ":loot_probability"),
        (try_end),
      (try_end),
     
We can enlarge the max inventory slots to 288 by connecting 3 troops which with 10 inventory Management, then let them to loot the defeated enemies one by one. They can loot 288 war booties at most. At last, we can choose the 96 most valuable items and add them to the inventory of trp_temp_troop to let the player to choose.

The following is the improved code to overwrite the code mentioned above:
## CC
     
(store_add, ":temp_array_c_plus_one", "trp_temp_array_c", 1),
      (try_for_range,
":cur_troop", "trp_temp_array_a", ":temp_array_c_plus_one"),
        (troop_clear_inventory,
":cur_troop"), # clear_inventory
        # raise skl_inventory_management level to 10
       
(store_skill_level, ":cur_level", skl_inventory_management, ":cur_troop"),
        (store_sub,
":dest_level", 10, ":cur_level"),
        (troop_raise_skill,
":cur_troop", skl_inventory_management, ":dest_level"),
      (try_end),
     
      (call_script,
"script_copy_inventory", "trp_temp_troop", "trp_temp_array_a"),
     
      (party_get_num_companion_stacks,
":num_stacks", ":enemy_party"),
      (try_for_range,
":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id,
":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero,
":stack_troop"),
        (party_stack_get_size,
":stack_size",":enemy_party",":i_stack"),
        (try_for_range,
":unused", 0, ":stack_size"),
          (try_begin),
            (store_free_inventory_capacity,
":inv_cap_a", "trp_temp_array_a"),
            (gt,
":inv_cap_a", 0),
            (troop_loot_troop,
"trp_temp_array_a", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity,
":inv_cap_b", "trp_temp_array_b"),
            (gt,
":inv_cap_b", 0),
            (troop_loot_troop,
"trp_temp_array_b", ":stack_troop", ":loot_probability"),
          (else_try),
            (troop_loot_troop,
"trp_temp_array_c", ":stack_troop", ":loot_probability"),
          (try_end),
        (try_end),
      (try_end),
     
      (troop_clear_inventory,
"trp_temp_troop"),
      (try_for_range,
":unused", 0, 96), # for 96 times
        # find the best item
       
(assign, ":best_score", 0),
        (assign,
":best_troop", -1),
        (assign,
":best_slot", -1),
        (try_for_range,
":cur_troop", "trp_temp_array_a", ":temp_array_c_plus_one"),
          (troop_get_inventory_capacity,
":inv_cap", ":cur_troop"),
          (try_for_range,
":i_slot", 10, ":inv_cap"),
            (troop_get_inventory_slot,
":item", ":cur_troop", ":i_slot"),
            (troop_get_inventory_slot_modifier,
":imod", ":cur_troop", ":i_slot"),
            (gt,
":item", -1),
            (call_script,
"script_get_item_value_with_imod", ":item", ":imod"),
            (assign,
":score", reg0),
            (val_div,
":score", 100),
            (val_max,
":score",1),
            (gt,
":score", ":best_score"),
            (assign,
":best_score", ":score"),
            (assign,
":best_troop", ":cur_troop"),
            (assign,
":best_slot", ":i_slot"),
          (try_end),
        (try_end),
        (gt,
":best_score", 0),
       
# already found
       
(troop_get_inventory_slot, ":item", ":best_troop", ":best_slot"),
        (troop_get_inventory_slot_modifier,
":imod", ":best_troop", ":best_slot"),
        (troop_add_item,
"trp_temp_troop", ":item", ":imod"), # add to trp_temp_troop
       
(troop_set_inventory_slot, ":best_troop", ":best_slot", -1), # remove it
     
(try_end),
## CC

The following are two scripts used in the code above, add these to the end of module_scripts.py if your MOD has not them.

script_copy_inventory:
  ("copy_inventory",
    [
      (store_script_param_1,
":source"),
      (store_script_param_2,
":target"),
 
      (troop_clear_inventory,
":target"),
      (troop_get_inventory_capacity,
":inv_cap", ":source"),
      (try_for_range,
":i_slot", 0, ":inv_cap"),
        (troop_get_inventory_slot,
":item", ":source", ":i_slot"),
        (troop_set_inventory_slot,
":target", ":i_slot", ":item"),
        (troop_get_inventory_slot_modifier,
":imod", ":source", ":i_slot"),
        (troop_set_inventory_slot_modifier,
":target", ":i_slot", ":imod"),
        (troop_inventory_slot_get_item_amount,
":amount", ":source", ":i_slot"),
        (gt,
":amount", 0),
        (troop_inventory_slot_set_item_amount,
":target", ":i_slot", ":amount"),
      (try_end),
    ]),

script_get_item_value_with_imod:
("get_item_value_with_imod",
  [
# returns the sell price based on the item's money value and its imod
   
(store_script_param, ":item", 1),
    (store_script_param,
":imod", 2),

    (store_item_value,
":score", ":item"),
    (try_begin),
      (eq,
":imod", imod_plain),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_cracked),
      (assign,
":imod_multiplier", 50),
    (else_try),
      (eq,
":imod", imod_rusty),
      (assign,
":imod_multiplier", 55),
    (else_try),
      (eq,
":imod", imod_bent),
      (assign,
":imod_multiplier", 65),
    (else_try),
      (eq,
":imod", imod_chipped),
      (assign,
":imod_multiplier", 72),
    (else_try),
      (eq,
":imod", imod_battered),
      (assign,
":imod_multiplier", 75),
    (else_try),
      (eq,
":imod", imod_poor),
      (assign,
":imod_multiplier", 80),
    (else_try),
      (eq,
":imod", imod_crude),
      (assign,
":imod_multiplier", 83),
    (else_try),
      (eq,
":imod", imod_old),
      (assign,
":imod_multiplier", 86),
    (else_try),
      (eq,
":imod", imod_cheap),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_fine),
      (assign,
":imod_multiplier", 190),
    (else_try),
      (eq,
":imod", imod_well_made),
      (assign,
":imod_multiplier", 250),
    (else_try),
      (eq,
":imod", imod_sharp),
      (assign,
":imod_multiplier", 160),
    (else_try),
      (eq,
":imod", imod_balanced),
      (assign,
":imod_multiplier", 350),
    (else_try),
      (eq,
":imod", imod_tempered),
      (assign,
":imod_multiplier", 670),
    (else_try),
      (eq,
":imod", imod_deadly),
      (assign,
":imod_multiplier", 850),
    (else_try),
      (eq,
":imod", imod_exquisite),
      (assign,
":imod_multiplier", 1450),
    (else_try),
      (eq,
":imod", imod_masterwork),
      (assign,
":imod_multiplier", 1750),
    (else_try),
      (eq,
":imod", imod_heavy),
      (assign,
":imod_multiplier", 190),
    (else_try),
      (eq,
":imod", imod_strong),
      (assign,
":imod_multiplier", 490),
    (else_try),
      (eq,
":imod", imod_powerful),
      (assign,
":imod_multiplier", 320),
    (else_try),
      (eq,
":imod", imod_tattered),
      (assign,
":imod_multiplier", 50),
    (else_try),
      (eq,
":imod", imod_ragged),
      (assign,
":imod_multiplier", 70),
    (else_try),
      (eq,
":imod", imod_rough),
      (assign,
":imod_multiplier", 60),
    (else_try),
      (eq,
":imod", imod_sturdy),
      (assign,
":imod_multiplier", 170),
    (else_try),
      (eq,
":imod", imod_thick),
      (assign,
":imod_multiplier", 260),
    (else_try),
      (eq,
":imod", imod_hardened),
      (assign,
":imod_multiplier", 390),
    (else_try),
      (eq,
":imod", imod_reinforced),
      (assign,
":imod_multiplier", 650),
    (else_try),
      (eq,
":imod", imod_superb),
      (assign,
":imod_multiplier", 250),
    (else_try),
      (eq,
":imod", imod_lordly),
      (assign,
":imod_multiplier", 1150),
    (else_try),
      (eq,
":imod", imod_lame),
      (assign,
":imod_multiplier", 40),
    (else_try),
      (eq,
":imod", imod_swaybacked),
      (assign,
":imod_multiplier", 60),
    (else_try),
      (eq,
":imod", imod_stubborn),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_timid),
      (assign,
":imod_multiplier", 180),
    (else_try),
      (eq,
":imod", imod_meek),
      (assign,
":imod_multiplier", 180),
    (else_try),
      (eq,
":imod", imod_spirited),
      (assign,
":imod_multiplier", 650),
    (else_try),
      (eq,
":imod", imod_champion),
      (assign,
":imod_multiplier", 1450),
    (else_try),
      (eq,
":imod", imod_fresh),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_day_old),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_two_day_old),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_smelling),
      (assign,
":imod_multiplier", 40),
    (else_try),
      (eq,
":imod", imod_rotten),
      (assign,
":imod_multiplier", 5),
    (else_try),
      (eq,
":imod", imod_large_bag),
      (assign,
":imod_multiplier", 190),
    (try_end),
    (val_mul,
":score", ":imod_multiplier"),
    (assign, reg0,
":score"),
  ]),

 
you released too much good stuff for people to keep up with :smile:

Just for discussion's sake, here are some related issues I was toying with (some more posted in another earlier post on "Army Logistics").

Basically, it's about using simulated arrays to store virtual inventories in 2 forms:
1) 1-1, where each "entry" in array equals 1 item exactly.  easiest to convert to and from real troop inventory.
2) collated, each item type (+modifier) stored exactly once.  An extra value for each item type keeps track of the number of this item (this is so that something like 1000 leather armor can be represented by 1 entry instead of 1000 entry).  Can convert to and from the first type.

And instead of just choosing the best, perhaps it could be paged? i.e. Optionally sort all items by value (and possibly by type) (e.g. using array type 2 from above), then convert to array type 1 from above, and split up the new array into pages of say 90 items per page, where each page can be moved to/from real inventory using temp troop. (when moved to troop inventory, the items will be removed from virtual inventory, and when page changes, the remaining inventory in troop will be moved back to the old page in virtual inventory, before items in a new page is moved in).

Player can then browse through pages if they want, and no single loot item will be missed. (so if for some reason the player is collecting cheap broken daggers, maybe for some quest, they can still do it in massive loots)

The virtual inventory could also be a basis for army-wide equipment tracked down to item level, and could provide possibilities like armament stockpiling and new mechanics to troop recruiting (generated troops from "environment" comes with equipment, but promoted troops may have to be armed by the party leader.  So no more magical upgrading of peasants in clothing to knights in plate armor out in the wilds with nothing but grass :wink: )

I am planning to do a utility level script library to manipulate items via virtual inventories.  If you have any ideas/suggestions, it will be most welcome.
 
rubik said:
script_get_item_value_with_imod:
("get_item_value_with_imod",
  [
# returns the sell price based on the item's money value and its imod
   
(store_script_param, ":item", 1),
    (store_script_param,
":imod", 2),

    (store_item_value,
":score", ":item"),
    (try_begin),
      (eq,
":imod", imod_plain),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_cracked),
      (assign,
":imod_multiplier", 50),
    (else_try),
      (eq,
":imod", imod_rusty),
      (assign,
":imod_multiplier", 55),
    (else_try),
      (eq,
":imod", imod_bent),
      (assign,
":imod_multiplier", 65),
    (else_try),
      (eq,
":imod", imod_chipped),
      (assign,
":imod_multiplier", 72),
    (else_try),
      (eq,
":imod", imod_battered),
      (assign,
":imod_multiplier", 75),
    (else_try),
      (eq,
":imod", imod_poor),
      (assign,
":imod_multiplier", 80),
    (else_try),
      (eq,
":imod", imod_crude),
      (assign,
":imod_multiplier", 83),
    (else_try),
      (eq,
":imod", imod_old),
      (assign,
":imod_multiplier", 86),
    (else_try),
      (eq,
":imod", imod_cheap),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_fine),
      (assign,
":imod_multiplier", 190),
    (else_try),
      (eq,
":imod", imod_well_made),
      (assign,
":imod_multiplier", 250),
    (else_try),
      (eq,
":imod", imod_sharp),
      (assign,
":imod_multiplier", 160),
    (else_try),
      (eq,
":imod", imod_balanced),
      (assign,
":imod_multiplier", 350),
    (else_try),
      (eq,
":imod", imod_tempered),
      (assign,
":imod_multiplier", 670),
    (else_try),
      (eq,
":imod", imod_deadly),
      (assign,
":imod_multiplier", 850),
    (else_try),
      (eq,
":imod", imod_exquisite),
      (assign,
":imod_multiplier", 1450),
    (else_try),
      (eq,
":imod", imod_masterwork),
      (assign,
":imod_multiplier", 1750),
    (else_try),
      (eq,
":imod", imod_heavy),
      (assign,
":imod_multiplier", 190),
    (else_try),
      (eq,
":imod", imod_strong),
      (assign,
":imod_multiplier", 490),
    (else_try),
      (eq,
":imod", imod_powerful),
      (assign,
":imod_multiplier", 320),
    (else_try),
      (eq,
":imod", imod_tattered),
      (assign,
":imod_multiplier", 50),
    (else_try),
      (eq,
":imod", imod_ragged),
      (assign,
":imod_multiplier", 70),
    (else_try),
      (eq,
":imod", imod_rough),
      (assign,
":imod_multiplier", 60),
    (else_try),
      (eq,
":imod", imod_sturdy),
      (assign,
":imod_multiplier", 170),
    (else_try),
      (eq,
":imod", imod_thick),
      (assign,
":imod_multiplier", 260),
    (else_try),
      (eq,
":imod", imod_hardened),
      (assign,
":imod_multiplier", 390),
    (else_try),
      (eq,
":imod", imod_reinforced),
      (assign,
":imod_multiplier", 650),
    (else_try),
      (eq,
":imod", imod_superb),
      (assign,
":imod_multiplier", 250),
    (else_try),
      (eq,
":imod", imod_lordly),
      (assign,
":imod_multiplier", 1150),
    (else_try),
      (eq,
":imod", imod_lame),
      (assign,
":imod_multiplier", 40),
    (else_try),
      (eq,
":imod", imod_swaybacked),
      (assign,
":imod_multiplier", 60),
    (else_try),
      (eq,
":imod", imod_stubborn),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_timid),
      (assign,
":imod_multiplier", 180),
    (else_try),
      (eq,
":imod", imod_meek),
      (assign,
":imod_multiplier", 180),
    (else_try),
      (eq,
":imod", imod_spirited),
      (assign,
":imod_multiplier", 650),
    (else_try),
      (eq,
":imod", imod_champion),
      (assign,
":imod_multiplier", 1450),
    (else_try),
      (eq,
":imod", imod_fresh),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_day_old),
      (assign,
":imod_multiplier", 100),
    (else_try),
      (eq,
":imod", imod_two_day_old),
      (assign,
":imod_multiplier", 90),
    (else_try),
      (eq,
":imod", imod_smelling),
      (assign,
":imod_multiplier", 40),
    (else_try),
      (eq,
":imod", imod_rotten),
      (assign,
":imod_multiplier", 5),
    (else_try),
      (eq,
":imod", imod_large_bag),
      (assign,
":imod_multiplier", 190),
    (try_end),
    (val_mul,
":score", ":imod_multiplier"),
    (assign, reg0,
":score"),
  ]),

You could have just made a function. :X
 
Those are the same values used by the game in item_modifiers.txt. I fail to see how a function can output those arbitrary values. Anyways, rubik did make a function using python.
modifiers = [
  (imod_plain, 100, 0),
  (imod_cracked, 50, -1),
  (imod_rusty, 55, -1),
  (imod_bent, 65, -1),
  (imod_chipped, 72, -1),
  (imod_battered, 75, -1),
  (imod_poor, 80, -1),
  (imod_crude, 83, -1),
  (imod_old, 86, -1),
  (imod_cheap, 90, -1),
  (imod_fine, 190, 1),
  (imod_well_made, 250, 1),
  (imod_sharp, 160, 1),
  (imod_balanced, 350, 1),
  (imod_tempered, 670, 1),
  (imod_deadly, 850, 1),
  (imod_exquisite, 1450, 1),
  (imod_masterwork, 1750, 1),
  (imod_heavy, 190, 1),
  (imod_strong, 490, 1),
  (imod_powerful, 320, 1),
  (imod_tattered, 50, -1),
  (imod_ragged, 70, -1),
  (imod_rough, 60, -1),
  (imod_sturdy, 170, 1),
  (imod_thick, 260, 1),
  (imod_hardened, 390, 1),
  (imod_reinforced, 650, 1),
  (imod_superb, 250, 1),
  (imod_lordly, 1150, 1),
  (imod_lame, 40, -1),
  (imod_swaybacked, 60, -1),
  (imod_stubborn, 90, 1),
  (imod_timid, 180, 1),
  (imod_meek, 180, -1),
  (imod_spirited, 650, 1),
  (imod_champion, 1450, 1),
  (imod_fresh, 100, 1),
  (imod_day_old, 100, -1),
  (imod_two_day_old, 90, -1),
  (imod_smelling, 40, -1),
  (imod_rotten, 5, -1),
  (imod_large_bag, 190, 1)
]

Code:
def set_item_score():
  item_score = []
  for i_modifier in xrange(len(modifiers)):
    item_score.append((item_set_slot, i_modifier, slot_item_modifier_multiplier, modifiers[i_modifier][1]))
    item_score.append((item_set_slot, i_modifier, slot_item_modifier_quality, modifiers[i_modifier][2]))
  return item_score[:]

Code:
("init_item_score", set_item_score()),
("get_item_value_with_imod",
  [# returns the sell price based on the item's money value and its imod
    (store_script_param, ":item", 1),
    (store_script_param, ":imod", 2),

    (store_item_value, ":score", ":item"),
    (item_get_slot, ":imod_multiplier", ":imod", slot_item_modifier_multiplier),
    (val_mul, ":score", ":imod_multiplier"),
    (assign, reg0, ":score"),
  ]),

Call init_item_score at somepoint in script_game_start, and those values will be set to slots. You'll have to define slot_item_modifier_multiplier. All this extra work for a function is the reason using a bunch of else_tries is easier.
 
Somebody said:
Those are the same values used by the game in item_modifiers.txt. I fail to see how a function can output those arbitrary values. Anyways, rubik did make a function using python.
modifiers = [
  (imod_plain, 100, 0),
  (imod_cracked, 50, -1),
  (imod_rusty, 55, -1),
  (imod_bent, 65, -1),
  (imod_chipped, 72, -1),
  (imod_battered, 75, -1),
  (imod_poor, 80, -1),
  (imod_crude, 83, -1),
  (imod_old, 86, -1),
  (imod_cheap, 90, -1),
  (imod_fine, 190, 1),
  (imod_well_made, 250, 1),
  (imod_sharp, 160, 1),
  (imod_balanced, 350, 1),
  (imod_tempered, 670, 1),
  (imod_deadly, 850, 1),
  (imod_exquisite, 1450, 1),
  (imod_masterwork, 1750, 1),
  (imod_heavy, 190, 1),
  (imod_strong, 490, 1),
  (imod_powerful, 320, 1),
  (imod_tattered, 50, -1),
  (imod_ragged, 70, -1),
  (imod_rough, 60, -1),
  (imod_sturdy, 170, 1),
  (imod_thick, 260, 1),
  (imod_hardened, 390, 1),
  (imod_reinforced, 650, 1),
  (imod_superb, 250, 1),
  (imod_lordly, 1150, 1),
  (imod_lame, 40, -1),
  (imod_swaybacked, 60, -1),
  (imod_stubborn, 90, 1),
  (imod_timid, 180, 1),
  (imod_meek, 180, -1),
  (imod_spirited, 650, 1),
  (imod_champion, 1450, 1),
  (imod_fresh, 100, 1),
  (imod_day_old, 100, -1),
  (imod_two_day_old, 90, -1),
  (imod_smelling, 40, -1),
  (imod_rotten, 5, -1),
  (imod_large_bag, 190, 1)
]

Code:
def set_item_score():
  item_score = []
  for i_modifier in xrange(len(modifiers)):
    item_score.append((item_set_slot, i_modifier, slot_item_modifier_multiplier, modifiers[i_modifier][1]))
    item_score.append((item_set_slot, i_modifier, slot_item_modifier_quality, modifiers[i_modifier][2]))
  return item_score[:]

Code:
("init_item_score", set_item_score()),
("get_item_value_with_imod",
  [# returns the sell price based on the item's money value and its imod
    (store_script_param, ":item", 1),
    (store_script_param, ":imod", 2),

    (store_item_value, ":score", ":item"),
    (item_get_slot, ":imod_multiplier", ":imod", slot_item_modifier_multiplier),
    (val_mul, ":score", ":imod_multiplier"),
    (assign, reg0, ":score"),
  ]),

Call init_item_score at somepoint in script_game_start, and those values will be set to slots. You'll have to define slot_item_modifier_multiplier. All this extra work for a function is the reason using a bunch of else_tries is easier.

Of cause I know it, because the code you showed is written by me. I just want to decrease the difficult to learn the code I wrote here.
 
i am using the code... but it is too small...
i tried to expand it to larger loot, as i am now working with a mod with 1k+battles
I also brought this http://forums.taleworlds.com/index.php/topic,69904.0.html
so now it is
        #Now loot the defeated party
        (store_mul, ":loot_probability", player_loot_share, 3),
        (val_mul, ":loot_probability", 100),
        (party_get_skill_level, ":player_party_looting", "p_main_party", "skl_looting"),
        (val_mul, ":player_party_looting", 3),
        (val_add, ":loot_probability", ":player_party_looting"),
       
        (store_add, ":temp_array_c_plus_one", "trp_temp_array_c", 1),
      (try_for_range, ":cur_troop", "trp_temp_array_a", ":temp_array_c_plus_one"),
        (troop_clear_inventory, ":cur_troop"), # clear_inventory
        # raise skl_inventory_management level to 10
        (store_skill_level, ":cur_level", skl_inventory_management, ":cur_troop"),
        (store_sub, ":dest_level", 10, ":cur_level"),
        (troop_raise_skill, ":cur_troop", skl_inventory_management, ":dest_level"),
      (try_end),
     
      (call_script, "script_copy_inventory", "trp_temp_troop", "trp_temp_array_a"),
#improved loot?     
      (party_get_num_companion_stacks, ":num_stacks", ":enemy_party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
        (try_for_range, ":unused", 0, ":stack_size"),
#loot of the dead
      (try_for_range, ":i_slot", 0, 9),
        (troop_get_inventory_slot, ":item_id", ":stack_troop", ":i_slot"),
            (troop_add_item, "trp_temp_array_a", ":item_id", ),
          (try_end),
#back to improved loot     
          (try_begin),
            (store_free_inventory_capacity, ":inv_cap_a", "trp_temp_array_a"),
            (gt, ":inv_cap_a", 0),
            (troop_loot_troop, "trp_temp_array_a", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_b", "trp_temp_array_b"),
            (gt, ":inv_cap_b", 0),
            (troop_loot_troop, "trp_temp_array_b", ":stack_troop", ":loot_probability"),
          (else_try),
            (troop_loot_troop, "trp_temp_array_c", ":stack_troop", ":loot_probability"),
          (try_end),
        (try_end),
      (try_end),
     
      (troop_clear_inventory, "trp_temp_troop"),
      (try_for_range, ":unused", 0, 96), # for 96 times
        # find the best item
        (assign, ":best_score", 0),
        (assign, ":best_troop", -1),
        (assign, ":best_slot", -1),
        (try_for_range, ":cur_troop", "trp_temp_array_a", ":temp_array_c_plus_one"),
          (troop_get_inventory_capacity, ":inv_cap", ":cur_troop"),
          (try_for_range, ":i_slot", 10, ":inv_cap"),
            (troop_get_inventory_slot, ":item", ":cur_troop", ":i_slot"),
            (troop_get_inventory_slot_modifier, ":imod", ":cur_troop", ":i_slot"),
            (gt, ":item", -1),
            (call_script, "script_get_item_value_with_imod", ":item", ":imod"),
            (assign, ":score", reg0),
            (val_div, ":score", 100),
            (val_max, ":score",1),
            (gt, ":score", ":best_score"),
            (assign, ":best_score", ":score"),
            (assign, ":best_troop", ":cur_troop"),
            (assign, ":best_slot", ":i_slot"),
          (try_end),
        (try_end),
        (gt, ":best_score", 0),
        # already found
        (troop_get_inventory_slot, ":item", ":best_troop", ":best_slot"),
        (troop_get_inventory_slot_modifier, ":imod", ":best_troop", ":best_slot"),
        (troop_add_item, "trp_temp_troop", ":item", ":imod"), # add to trp_temp_troop
        (troop_set_inventory_slot, ":best_troop", ":best_slot", -1), # remove it
      (try_end),
    #up to here   
          (troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
          (try_for_range, ":i_slot", 0, ":inv_cap"),
            (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
            (ge, ":item_id", 0),
            (val_add, ":num_looted_items", 1),
          (try_end),
         
          (assign, reg0, ":num_looted_items"),
      ]),

If you can help me expand it to handle like 10k items and return only the top 96 would be much apreciated
I think in theory u can make a script to loot and discard in order to keep only the best 96 items, instead of looting 284 items and chosing the best 96 of those...
especially with the add-on that makes u loot the equipment of the defeated.
worse case scenario you could make a modification that would loot in order of troop level (best troops first) so loot would be resonabile
 
@cadaverescu

Tried your script in addition with the first and I get rich, fast. Though I miss the variation a bit, as after last battle I got some 42-odd pair of boots amongst other things :grin: Although, a strange thing I noticed is that Chipped and Rusty Nordic Swords were priced higher than the stock one. Never noticed that before, perhaps because there was always a big mix before.
 
it is not my script ... it is a mix of HokieBT and rubi
my problem is that during the last 10 years i did no programing whatsoever (since i finished high-scool), so i only use other ppl`s codes..
i am having issues with it producing normal items and never a balanced/chipped
 
i made some progress... but the wrong way...
        #Now loot the defeated party
        (store_mul, ":loot_probability", player_loot_share, 3),
        (val_mul, ":loot_probability", 100),
        (party_get_skill_level, ":player_party_looting", "p_main_party", "skl_looting"),
        (val_mul, ":player_party_looting", 3),
        (val_add, ":loot_probability", ":player_party_looting"),
       
        (store_add, ":temp_array_z_plus_one", "trp_temp_array_z", 1),
      (try_for_range, ":cur_troop", "trp_temp_array_a", ":temp_array_z_plus_one"),
        (troop_clear_inventory, ":cur_troop"), # clear_inventory
        # raise skl_inventory_management level to 10
        (store_skill_level, ":cur_level", skl_inventory_management, ":cur_troop"),
        (store_sub, ":dest_level", 10, ":cur_level"),
        (troop_raise_skill, ":cur_troop", skl_inventory_management, ":dest_level"),
      (try_end),
     
      (call_script, "script_copy_inventory", "trp_temp_troop", "trp_temp_array_a"),
#improved loot?     
      (party_get_num_companion_stacks, ":num_stacks", ":enemy_party"),
      (try_for_range, ":i_stack", 0, ":num_stacks"),
        (party_stack_get_troop_id, ":stack_troop",":enemy_party",":i_stack"),
        (neg|troop_is_hero, ":stack_troop"),
        (party_stack_get_size, ":stack_size",":enemy_party",":i_stack"),
        (try_for_range, ":unused", 0, ":stack_size"),
#loot of the dead
      (try_for_range, ":i_slot", 0, 9),
        (troop_get_inventory_slot, ":item_id", ":stack_troop", ":i_slot"),
        (try_begin),
            (store_free_inventory_capacity, ":inv_cap_a", "trp_temp_array_a"),
            (gt, ":inv_cap_a", 0),
            (troop_add_item, "trp_temp_array_a", ":item_id", ),
        (else_try),
            (store_free_inventory_capacity, ":inv_cap_b", "trp_temp_array_b"),
            (gt, ":inv_cap_b", 0),
            (troop_add_item, "trp_temp_array_c", ":item_id", ),
        (else_try),
              (troop_add_item, "trp_temp_array_c", ":item_id", ),
          (try_end),
       
#back to improved loot     
          (try_begin),
            (store_free_inventory_capacity, ":inv_cap_d", "trp_temp_array_d"),
            (gt, ":inv_cap_d", 0),
            (troop_loot_troop, "trp_temp_array_d", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_e", "trp_temp_array_e"),
            (gt, ":inv_cap_e", 0),
            (troop_loot_troop, "trp_temp_array_e", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_f", "trp_temp_array_f"),
            (gt, ":inv_cap_f", 0),
            (troop_loot_troop, "trp_temp_array_f", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_g", "trp_temp_array_g"),
            (gt, ":inv_cap_g", 0),
            (troop_loot_troop, "trp_temp_array_g", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_h", "trp_temp_array_h"),
            (gt, ":inv_cap_h", 0),
            (troop_loot_troop, "trp_temp_array_h", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_i", "trp_temp_array_i"),
            (gt, ":inv_cap_i", 0),
            (troop_loot_troop, "trp_temp_array_i", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_j", "trp_temp_array_j"),
            (gt, ":inv_cap_j", 0),
            (troop_loot_troop, "trp_temp_array_j", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_k", "trp_temp_array_k"),
            (gt, ":inv_cap_k", 0),
            (troop_loot_troop, "trp_temp_array_k", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_l", "trp_temp_array_l"),
            (gt, ":inv_cap_l", 0),
            (troop_loot_troop, "trp_temp_array_l", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_m", "trp_temp_array_m"),
            (gt, ":inv_cap_m", 0),
            (troop_loot_troop, "trp_temp_array_m", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_n", "trp_temp_array_n"),
            (gt, ":inv_cap_n", 0),
            (troop_loot_troop, "trp_temp_array_n", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_o", "trp_temp_array_o"),
            (gt, ":inv_cap_o", 0),
            (troop_loot_troop, "trp_temp_array_o", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_p", "trp_temp_array_p"),
            (gt, ":inv_cap_p", 0),
            (troop_loot_troop, "trp_temp_array_p", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_r", "trp_temp_array_r"),
            (gt, ":inv_cap_r", 0),
            (troop_loot_troop, "trp_temp_array_r", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_s", "trp_temp_array_s"),
            (gt, ":inv_cap_s", 0),
            (troop_loot_troop, "trp_temp_array_s", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_t", "trp_temp_array_t"),
            (gt, ":inv_cap_t", 0),
            (troop_loot_troop, "trp_temp_array_t", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_q", "trp_temp_array_q"),
            (gt, ":inv_cap_q", 0),
            (troop_loot_troop, "trp_temp_array_q", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_v", "trp_temp_array_v"),
            (gt, ":inv_cap_v", 0),
            (troop_loot_troop, "trp_temp_array_v", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_v", "trp_temp_array_v"),
            (gt, ":inv_cap_v", 0),
            (troop_loot_troop, "trp_temp_array_v", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_x", "trp_temp_array_x"),
            (gt, ":inv_cap_x", 0),
            (troop_loot_troop, "trp_temp_array_x", ":stack_troop", ":loot_probability"),
          (else_try),
            (store_free_inventory_capacity, ":inv_cap_y", "trp_temp_array_e"),
            (gt, ":inv_cap_y", 0),
            (troop_loot_troop, "trp_temp_array_y", ":stack_troop", ":loot_probability"),
   
          (else_try),
            (troop_loot_troop, "trp_temp_array_z", ":stack_troop", ":loot_probability"),
          (try_end),
        (try_end),
      (try_end),
     
      (troop_clear_inventory, "trp_temp_troop"),
      (try_for_range, ":unused", 0, 96), # for 96 times
        # find the best item
        (assign, ":best_score", 0),
        (assign, ":best_troop", -1),
        (assign, ":best_slot", -1),
        (try_for_range, ":cur_troop", "trp_temp_array_a", ":temp_array_z_plus_one"),
          (troop_get_inventory_capacity, ":inv_cap", ":cur_troop"),
          (try_for_range, ":i_slot", 10, ":inv_cap"),
            (troop_get_inventory_slot, ":item", ":cur_troop", ":i_slot"),
            (troop_get_inventory_slot_modifier, ":imod", ":cur_troop", ":i_slot"),
            (gt, ":item", -1),
            (call_script, "script_get_item_value_with_imod", ":item", ":imod"),
            (assign, ":score", reg0),
            (val_div, ":score", 100),
            (val_max, ":score",1),
            (gt, ":score", ":best_score"),
            (assign, ":best_score", ":score"),
            (assign, ":best_troop", ":cur_troop"),
            (assign, ":best_slot", ":i_slot"),
          (try_end),
        (try_end),
        (gt, ":best_score", 0),
        # already found
        (troop_get_inventory_slot, ":item", ":best_troop", ":best_slot"),
        (troop_get_inventory_slot_modifier, ":imod", ":best_troop", ":best_slot"),
        (troop_add_item, "trp_temp_troop", ":item", ":imod"), # add to trp_temp_troop
        (troop_set_inventory_slot, ":best_troop", ":best_slot", -1), # remove it
      (try_end),
    #up to here   
          (troop_get_inventory_capacity, ":inv_cap", "trp_temp_troop"),
          (try_for_range, ":i_slot", 0, ":inv_cap"),
            (troop_get_inventory_slot, ":item_id", "trp_temp_troop", ":i_slot"),
            (ge, ":item_id", 0),
            (val_add, ":num_looted_items", 1),
          (try_end),
         
          (assign, reg0, ":num_looted_items"),
      ]),
this goes in the module_scripts

and this goes in the module troops

# These are used as arrays in the scripts.
["temp_array_a","{!}temp_array_a","{!}temp_array_a",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_b","{!}temp_array_b","{!}temp_array_b",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_c","{!}temp_array_c","{!}temp_array_c",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_d","{!}temp_array_d","{!}temp_array_d",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_e","{!}temp_array_e","{!}temp_array_e",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_f","{!}temp_array_f","{!}temp_array_f",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_g","{!}temp_array_g","{!}temp_array_g",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_h","{!}temp_array_h","{!}temp_array_h",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_i","{!}temp_array_i","{!}temp_array_i",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_j","{!}temp_array_j","{!}temp_array_j",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_k","{!}temp_array_k","{!}temp_array_k",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_l","{!}temp_array_l","{!}temp_array_l",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_m","{!}temp_array_m","{!}temp_array_m",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_n","{!}temp_array_n","{!}temp_array_n",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_o","{!}temp_array_o","{!}temp_array_o",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_p","{!}temp_array_p","{!}temp_array_p",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_r","{!}temp_array_r","{!}temp_array_r",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_s","{!}temp_array_s","{!}temp_array_s",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_t","{!}temp_array_t","{!}temp_array_t",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_q","{!}temp_array_q","{!}temp_array_q",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_v","{!}temp_array_v","{!}temp_array_v",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_x","{!}temp_array_x","{!}temp_array_x",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_y","{!}temp_array_y","{!}temp_array_y",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
["temp_array_z","{!}temp_array_z","{!}temp_array_z",tf_mounted|tf_hero|tf_inactive,0,reserved, fac_neutral,[],def_attrib|level(1:cool:,wp(60),knows_common,0],
 
Back
Top Bottom