Hi all. Quick question, as I suppose this is quite easy to achieve and I’m either too stupid or brain***ed to do it at the moment. As the title says :). Get a random party member and do stuff to him.
Thanks.
Hi all. Quick question, as I suppose this is quite easy to achieve and I’m either too stupid or brain***ed to do it at the moment. As the title says :). Get a random party member and do stuff to him.
Thanks.
Is a random party member supposed to include the owned characters?
If not, here is a function to get a random roster member from the PC party.
#include "ginc_companion"
object GetRandomRosterMemberFromParty(object oPartyMember)
{
if (!GetIsObjectValid(GetFactionLeader(oPartyMember)))
return OBJECT_INVALID;
int nMax = GetNumRosterMembersInParty(oPartyMember);
if (nMax == 0) return OBJECT_INVALID;
int nNum = Random(nMax) + 1;
int nCount = 0;
string sTarget = GetFirstRosterMember();
while (sTarget != "")
{
if (GetIsRosterNameInParty(oPartyMember, sTarget) && ++nCount == nNum)
return GetObjectFromRosterName(sTarget);
sTarget = GetNextRosterMember();
}
}
If yes, use this function:
object GetRandomPartyMember(object oPartyMember)
{
if (!GetIsObjectValid(GetFactionLeader(oPartyMember)))
return OBJECT_INVALID;
int nMax = 0;
int nCount = 0;
// Count Party Members
object oPCF = GetFirstFactionMember(oPartyMember, TRUE);
while (GetIsObjectValid(oPCF))
{
nMax++;
oPCF = GetNextFactionMember(oPartyMember, TRUE);
}
int nNum = Random(nMax) + 1;
oPCF = GetFirstFactionMember(oPartyMember, TRUE);
while (GetIsObjectValid(oPCF))
{
if (++nCount == nNum) return oPCF;
oPCF = GetNextFactionMember(oPartyMember, TRUE);
}
}
Try this:
#include "ginc_combat"
void main()
{
object oFM = GetRandomFactionMember(GetFirstPC());
// add code here to do stuff to oFM
}
Nvm, just misread the script. It’s too late here where I am
Good alternative if you also want to get associates (familiars, animal companions, etc.).
untested
// Gets a random party member from a given character's faction.
// - oPc must be a player faction (else return is OBJECT_INVALID)
// - bOwned TRUE to include OwnedCharacters
// - bRostr TRUE to include RosterMembers
// - bHench TRUE to include Associate Henchmen
// - bAnico TRUE to include Associate AnimalCompanions
// - bFamil TRUE to include Associate Familiars
// - bSumon TRUE to include Associate Summons
// - bDomin TRUE to include Associate Dominated
object GetRandParty(object oPc,
int bOwned = TRUE,
int bRostr = TRUE,
int bHench = FALSE,
int bAnico = FALSE,
int bFamil = FALSE,
int bSumon = FALSE,
int bDomin = FALSE)
{
object oParty = OBJECT_INVALID;
if (GetIsObjectValid(GetFactionLeader(oPc)))
{
int iAssoc = ASSOCIATE_TYPE_NONE;
int i = 0;
object oTest = GetFirstFactionMember(oPc, FALSE);
while (GetIsObjectValid(oTest))
{
iAssoc = GetAssociateType(oTest);
if ( (GetIsOwnedByPlayer(oTest) && bOwned)
|| (GetIsRosterMember(oTest) && bRostr)
|| (iAssoc == ASSOCIATE_TYPE_HENCHMAN && bHench)
|| (iAssoc == ASSOCIATE_TYPE_ANIMALCOMPANION && bAnico)
|| (iAssoc == ASSOCIATE_TYPE_FAMILIAR && bFamil)
|| (iAssoc == ASSOCIATE_TYPE_SUMMONED && bSumon)
|| (iAssoc == ASSOCIATE_TYPE_DOMINATED && bDomin))
{
if (!Random(++i))
oParty = oTest;
}
oTest = GetNextFactionMember(oPc, FALSE);
}
}
return oParty;
}
Thank you all. I am certain on of these will do the job.