I'm posting a script here for other more serious scripters. The purpose of this script is to get a list of every troop stack in a given party along with of course the number of troop stacks. It currently only counts the non-prisoner troops (I think), but could be adapted to count all troops or only prisoners if needed.
If you don't know why this would be helpful, the script is probably not for you.
Included with the main script is an example script using it, which will print a list of troop stacks in the player's party on-screen. This isn't a particularly useful thing to do, but serves as a good example and base for whatever you need the script to do for you.
Special thanks to fisheye for a bit of scripting help on a more elegant way to store and incrementally reference variables using the slots of a dummy troop.
Add these lines to the end of the troop list in module_troops.py. They should be after the last troop but before the ending bracket:
#do not place a troop past this point, it marks the end of the troops
["end_troops","end_troops","end_troops",tf_hero,no_scene,reserved,fac_commoners,[],def_attrib,0,knows_common,0],
Add these string into module_strings.py, they're just used by the script example:
("party_contains","The party '{s3}' contains {reg9} troop stacks:"),
("string3","{s3}"),
Add these scripts into module_scripts.py:
("list_party_troops", [ #this script will check the target party (stored in "$party_to_check") and return a list of the troop types in the party
(try_begin),[assign,"$party_stack_count",0],
(try_for_range,reg(6), "trp_player", "trp_end_troops"),
[party_count_companions_of_type, reg(7), "$party_to_check", reg(6)], [gt, reg(7), 0],
[troop_set_slot,"trp_end_troops","$party_stack_count",reg(6)],
[val_add, "$party_stack_count", 1],
(end_try),
#at this point, "$party_stack_count" contains the number of troop stacks in the "$party_to_check" party; "$party_stack_count" is also to be used as the end value for
#a try_for_range loop (1 higher than the last reg with troop data), then the troop slots for the "trp_end_troops" dummy entry contain the troop id of each stack in the party.
(end_try),
]),
("player_has_troops", [ #this script is an example of how to use the list_party_troops script; it will determine and print out the player's troop list on screen
(try_begin), [assign, "$party_to_check", "p_main_party"], #set "$party_to_check" to the player's party, used for input in the list_party_troops script
(call_script, "script_list_party_troops"), #run the script to get a list of troops in the player's party
[str_store_party_name, 3, "$party_to_check"],(display_message, "str_party_contains"), #print out the string indicating the party name and number of troop slots
(try_for_range, reg(6), 0, "$party_stack_count"), #loop through each troop. "$party_stack_count" contains the total number of troop references, thus where to end the loop
[troop_get_slot,reg(7), "trp_end_troops", reg(6)], [str_store_troop_name, 3, reg(7)], (display_message, "str_string3"),
#the list of troop references were stored in the dummy troop "trp_end_troops", starting with slot 0. Reg(7) is set to the current troop reference,
#then the name of the troop is obtained and stored in the temporary string s(3). The troop name is then printed to the screen.
(end_try),
(end_try),
]),
Finally, add this into an operation block (in a dialog, a menu, a trigger, or wherever you want) to run the script example:
(call_script,"script_player_has_troops")
EDIT: updated the script to not rely on reg(5) and reg(9) but instead use its own variables, "$party_to_check" and "$party_stack_count".