I don't think you can use an object's position in the party pool in that way as it won't relate to your CCC_TABLE_CAPTURED M2DA. I would expect objects to appear in the PartyPool in the order (or the reverse order) they join your party whereas your M2DA is probably in a specific order. So while this may work for you it may not be reliable for others. As I recall BioWare have a look up functions to map the companion to an ID and back again.
I think what you want to do is tackle the problem the other way round. Assuming your CCC_TABLE_CAPTURED M2DA has all the relevant companions in it (even if spread over multiple fragments) then you should be able to do something like this:
int nAvailable, nFollowerId, nRow;
int[] nAvailableFollowerIds;
object oFollower;
object[] oAvailableFollowers;
string sFollowerTag;
// get the size of the "captured" array
int nRows = GetM2DARows(CCC_TABLE_CAPTURED);
// loop through each entry in the "captured" array and build a list of available captives
// NOTE: depending what the table contains the IsHero, IsSummond and IsFollowerVanilla checks
// are probably not required so have been omited in this example. They should be added back as
// necessary.
for(nRow = 0; nRow < nRows; nRow++)
{
// convert the row number into an ID
nFollowerId = GetM2DARowIdFromRowIndex(CCC_TABLE_CAPTURED, nRow);
// get the companion's tag
sFollowerTag = GetM2DAString(CCC_TABLE_CAPTURED, CCC_COL_FOLLOWER_TAG, nFollowerId);
// companions, once joined, should be in the party or the char_stage so we can Get it by
// its tag
oFollower = GetObjectByTag(sFollowerTag);
// determine if the follower is a suitable candidate and, if so add them and their ID to
// arrays: note we only need the ID but storing the object saves us retrieving it again
if(GetFollowerState(oFollower) == FOLLOWER_STATE_AVAILABLE)
{
nAvailableFollowerIds[nAvailable] = nFollowerId;
oAvailableFollowers[nAvailable] = oFollower;
nAvailable++;
}
}
// select a companion at random
// NOTE: by incrementing nAvailable after adding elements to both arrays it is equivalent to the
// size of the array so we can just use it as the basis for our random index
int nRandom = Random(nAvailable);
// retrieve the information stored in the "available" arrays
oFollower = oAvailableFollowers[nRandom];
nFollowerId = nAvailableFollowerIds[nRandom];
// retireve the "in party" plot flag information from the M2DA
string sPlot = GetM2DAString(CCC_TABLE_CAPTURED, CCC_COL_PARTY_PLOT, nFollowerId);
int nFlag = GetM2DAInt(CCC_TABLE_CAPTURED, CCC_COL_IN_PARTY_FLAG, nFollowerId);
// activate the companion and add them to the party
WR_SetFollowerState(oFollower, FOLLOWER_STATE_ACTIVE);
WR_SetPlotFlag(sPlot, nFlag, TRUE);