ConstantA - thanks very much, I still need to test your bottom code, but the original use_healthpack worked great. This will definetely be added to the next release of the star wars mod and I'll add you to the credits.
In case anybody is interested, I modified the code a bit so it now uses an injector and capsules.
common_use_healthpack = (0, 0, 0, [
(key_clicked, key_h)
],
[
(get_player_agent_no, ":player_agent"),
(agent_is_alive, ":player_agent"),
(store_agent_hit_points, ":player_hp", ":player_agent"),
(try_begin),
(lt, ":player_hp", 100),
#(troop_get_inventory_capacity, ":inv_cap", "trp_player"),
(troop_get_inventory_capacity, ":inv_cap", "$g_player_troop"), #since custom commander is integrated
(assign, ":healing_item_injector_slot", -1),
(assign, ":healing_item_capsule_slot", -1),
(assign, reg1, 0),
(try_for_range, ":slot_no", 0, ":inv_cap"),
#(troop_get_inventory_slot,":item_id","trp_player",":slot_no"),
(troop_get_inventory_slot,":item_id","$g_player_troop",":slot_no"), #since custom commander is integrated
(try_begin),
(eq, ":item_id", "itm_bacta_injector"),
(assign, ":healing_item_injector_slot", ":slot_no"),
(else_try),
(eq, ":item_id", "itm_bacta_capsule"),
(assign, ":healing_item_capsule_slot", ":slot_no"),
(val_add, reg1, 1),
(try_end),
(try_end),
(try_begin),
(eq, ":healing_item_injector_slot", -1),
(display_message, "@You don't have a Bacta Injector in inventory!"),
(else_try),
(le, reg1, 0),
(display_message, "@You don't have any Bacta Capsules in inventory!"),
(else_try),
(store_agent_hit_points, ":player_hp", ":player_agent", 1),
(val_add, ":player_hp", 20), #hp to add
(agent_set_hit_points, ":player_agent", ":player_hp", 1),
#(troop_set_inventory_slot,"trp_player",":healing_item_capsule_slot", -1),
(troop_set_inventory_slot,"$g_player_troop",":healing_item_capsule_slot", -1), #since custom commander is integrated
(val_sub, reg1,1),
(display_message, "@You were healed for 20 hp and have {reg1} bacta capsules left."),
(try_end),
(else_try),
(display_message, "@You are not hurt."),
(try_end),
])