_Sebastian_ said:Pure randomness.MitchellD said:Has anybody ever figured out the game engine's algorithm for giving agents items from the troop inventory, or come up with a good estimation based on observation?
Script is weighted by the item value. It will distribute items of the medium value (price $), and reserve a % for the cheapest and the most expensive one. I don't have the exact numbers here, but its something like:
1 - cheapest: 10%
2 - random: 80 %
3 - most expensive: 10%
If you look at VC code you will notice that the DLC uses a trigger to replace the armor (body piece) of agents to create a different distribution. Its under "common_gear_check".
This is a logger/trigger I used to test the feature and that you can adapt to check how your items are being used by agents:
Code:
logger_armor_selection = (
10, 0 , ti_once ,
[#(ge, "$cheat_mode", 1),
(mission_tpl_are_all_agents_spawned),
],
[
(set_show_messages, 0),
(display_message, "@^-----------------------------------^"),
(try_for_range, ":i", 0, 1000),
(troop_set_slot, "trp_temp_array_a", ":i", -1),
(troop_set_slot, "trp_temp_array_b", ":i", 0),
(troop_set_slot, "trp_temp_array_c", ":i", -1),
(try_end),
(assign, ":troop_index_add", 25),
(assign, ":troop_index", 0),
#setup
(try_for_agents, ":agent"),
(agent_is_human, ":agent"),
(agent_is_alive, ":agent"),
(agent_is_ally, ":agent"),
(assign, ":is_know_troop", 0),
(assign, ":array_limit", 1000),
(val_div, ":array_limit", ":troop_index_add"),
(assign, ":slot", 0),
(agent_get_troop_id, ":troop_id", ":agent"),
(try_for_range, ":i", 0, ":array_limit"),
(troop_get_slot, ":saved_troop", "trp_temp_array_a", ":slot"),
(assign, reg20, ":saved_troop"),
(assign, reg21, ":troop_id"),
(try_begin),
(eq, ":saved_troop", ":troop_id"),
(assign, ":is_know_troop", 1),
(assign, ":array_limit", 0),
(else_try),
(eq, ":saved_troop", -1),
(assign, ":is_know_troop", 0),
(assign, ":array_limit", 0),
(else_try),
(val_add, ":slot", ":troop_index_add"),
(try_end),
(try_end),
(eq, ":is_know_troop", 0),
(assign, reg1, ":troop_index"),
(val_add, ":troop_index", ":troop_index_add"),
(try_for_range, ":slot2", 0, 65),
(troop_get_inventory_slot, ":item", ":troop_id", ":slot2"),
(neq, ":item", -1),
(item_get_type, ":type", ":item"),
(eq, ":type", itp_type_body_armor),
(troop_set_slot, "trp_temp_array_a", reg1, ":troop_id"),
(troop_set_slot, "trp_temp_array_b", reg1, ":item"),
(troop_set_slot, "trp_temp_array_c", reg1, 0),
(val_add, reg1, 1),
(try_end),
(try_end),
# count gear used
(try_for_agents, ":agent"),
(str_clear, s1),
(str_clear, s2),
(str_clear, s3),
(agent_is_human, ":agent"),
(agent_is_alive, ":agent"),
(agent_is_ally, ":agent"),
(assign, reg1, ":agent"),
(agent_get_troop_id, ":troop_id", ":agent"),
(assign, reg2, ":troop_id"),
(str_store_troop_name, s4, ":troop_id"),
# current chest armor
(agent_get_item_slot, ":wielded_item", ":agent", ek_body),
(try_begin),
(assign, ":array_limit", 1000),
(val_div, ":array_limit", ":troop_index_add"),
(assign, ":slot", 0),
(try_for_range, ":i", 0, ":array_limit"),
(troop_get_slot, ":saved_troop", "trp_temp_array_a", ":slot"),
(try_begin),
(eq, ":saved_troop", ":troop_id"),
(assign, ":array_limit", 0),
(store_add, ":limit", ":slot", 25),
(try_for_range, ":ii", ":slot", ":limit"),
(troop_get_slot, ":saved_armor", "trp_temp_array_b", ":ii"),
(neq, ":saved_armor", 0),
(eq, ":saved_armor", ":wielded_item"),
(troop_get_slot, ":count", "trp_temp_array_c", ":ii"),
(val_add, ":count", 1),
(troop_set_slot, "trp_temp_array_c", ":ii", ":count"),
(assign, ":limit", 0),
(try_end),
(else_try),
(val_add, ":slot", ":troop_index_add"),
(try_end),
(try_end),
(try_end),
(try_end),
# print report
(try_for_range, ":i", 0, 1000),
(troop_get_slot, ":saved_troop", "trp_temp_array_a", ":i"),
(gt, ":saved_troop", 0),
(troop_get_slot, ":piece", "trp_temp_array_b", ":i"),
(gt, ":piece", 0),
(troop_get_slot, ":count", "trp_temp_array_c", ":i"),
(assign, reg1, ":saved_troop"),
(assign, reg2, ":piece"),
(assign, reg3, ":count"),
(str_store_troop_name, s1, ":saved_troop"),
(str_store_item_name, s2, ":piece"),
(display_message, "@Trp: {reg1} | Using: {reg2} | Times: {reg3} | {s1} | {s2}"),
(try_end),
(display_message, "@^-------------------------------------^"),
(set_show_messages, 1),
])