You could modify the script to iterate over the isPlayer database. Companions that are inside your party are also added to that database.

Good job, otherwise!