# Consuming food at every 14 hours
(14, So I can just put a number here and it means "do this every 14 hours?"
[
(eq, "$g_player_is_captive", 0), Player must be active; makes sense.
(party_get_num_companion_stacks, ":num_stacks","p_main_party"),
(assign, ":num_men", 0),
(try_for_range, ":i_stack", 0, ":num_stacks"),
(party_stack_get_size, ":stack_size","p_main_party",":i_stack"),
(val_add, ":num_men", ":stack_size"),
(try_end),
So this section... adds the number of companions to the number of regular troops to get the total party size?
(call_script, "script_party_count_members_with_full_health", "p_main_party"), #returns number of troops at full health in reg0
(store_sub, ":num_wounded", ":num_men", reg0), #gets actual number of wounded
(val_max, ":num_wounded", 0), #do some scaling before this If the num_wounded is higher than x it will just set it to x instead of letting the number get too big?
(val_div, ":num_men", 3), This one can be changed if the herbs get consumed too quickly or slowly?
(try_begin),
(eq, ":num_men", 0),
(val_add, ":num_men", 1), Ensuring that num_men is at least 1.
(try_end),
... Not sure what this is about. Am I supposed to enter something here?
(try_begin),
(gt ":num_wounded", 0), If there is at least one wounded, it will run the consume_herbs script
(call_script, "script_consume_herbs", ":num_wounded"),
(try_end),
Notice how the parameter is now changed to a quantity and the item checks are made simpler.
("consume_herbs",
[(store_script_param, ":num_wounded", 1), The number determined in the previous simple_triggers_code
(troop_get_inventory_capacity, ":capacity", "trp_player"),
(try_for_range, ":cur_slot", 0, ":capacity"), Not fully understood
(gt, ":num_wounded", 0),
(troop_get_inventory_slot, ":cur_item", "trp_player", ":cur_slot"),
(eq, ":cur_item", "itm_herbs"),
(troop_get_inventory_slot_modifier, ":item_modifier", "trp_player", ":cur_slot"),
(neq, ":item_modifier", imod_rotten), #you can also add different effects for different imod so this currently doesn't do anything since the herbs can't go rotten, but I could add a function that would do so after a certain number of days if I wanted to...
(troop_inventory_slot_get_item_amount, ":cur_amount", "trp_player", ":cur_slot"), #get cur amount of medicine on stack
(try_begin), #last bit of herbs before script ends
(gt, ":cur_amount", ":num_wounded"),
(val_sub, ":cur_amount", ":num_wounded"),
(troop_inventory_slot_set_item_amount, "trp_player", ":cur_slot", ":cur_amount"),
(assign, ":capacity", -1),
(else_try), #use up entire stack of herbs
(val_sub, ":num_wounded", ":cur_amount"),
(troop_set_inventory_slot, "trp_player", ":cur_slot", -1),
(try_end),
(try_end),
]),