count party size script issues
#1
Posté 01 mars 2012 - 04:41
The script should only count MP PCs, SoZ party creation PCs, and OC type companions. I don't want to count animal companions, summons, henchmen, or familiars.
Here is my script which seems to be working fine if the currently controlled player is your first created character. It only counts one if the currently controlled character is one of your SoZ party creation GUI PCs.
int GetNumberOfCompanions()
{
// We alway use the SAME object for the GetFirst/Next faction
// member calls - always define it first. Here it is the first PC.
int nComp = 0;
object oPC = GetFirstPC(FALSE);
while(GetIsObjectValid(oPC) == TRUE)
{
if (GetIsOwnedByPlayer(oPC))
{
// Get the first PC party member
object oPartyMember = GetFirstFactionMember(oPC, FALSE);
// We stop when there are no more valid PC's in the party.
while(GetIsObjectValid(oPartyMember) == TRUE)
{
if ((GetIsPC(oPartyMember)) || (GetIsRosterMember(oPartyMember)))
{
// Do something to party member
nComp++;
SendMessageToPC(oPC, "Found a PC");
}
else
SendMessageToPC(oPC, "Found a non-PC");
// Get the next PC member of oPC's faction.
// If we put anything but oPC into this, it may be a totally
// unreliable loop!
oPartyMember = GetNextFactionMember(oPC, FALSE);
}
}
oPC = GetNextPC(FALSE);
}
string sComp = IntToString(nComp);
SendMessageToPC(oPC, "Number of Companions = " + sComp);
return nComp;
}
Any ideas? It seems easy until the SoZ party creation PCs get involved.
#2
Posté 01 mars 2012 - 05:41
CSLGetNumberPartyMembers
Add in GetAssociateType to make it work as you intend ( and make the loop actually go thru all companions by changing it from TRUE to FALSE )
int ASSOCIATE_TYPE_NONE = 0; int ASSOCIATE_TYPE_HENCHMAN = 1; int ASSOCIATE_TYPE_ANIMALCOMPANION = 2; int ASSOCIATE_TYPE_FAMILIAR = 3; int ASSOCIATE_TYPE_SUMMONED = 4; int ASSOCIATE_TYPE_DOMINATED = 5; /** * Returns the associate type of the specified creature. * @param oAssociate object to get the associate type of * @return an ASSOCIATE_TYPE_* constant. * @onerror Returns ASSOCIATE_TYPE_NONE if the creature is not the associate of anyone. */ int GetAssociateType( object oAssociate );
Changing the loop from TRUE ( True PC's only ), to FALSE, and then filtering by GetAssociateType() being less than 2, would do the trick i think...
/**
* Return the number of other players in the PC's party
* Does NOT include companions, familiars, summons or dominated.
*/
int CSLGetNumberPartyPCAndHenchmen(object oPC )
{
int nNumber = 1;
object oPartyMem = GetFirstFactionMember(oPC, FALSE);
while (GetIsObjectValid(oPartyMem))
{
/*
int ASSOCIATE_TYPE_NONE = 0;
int ASSOCIATE_TYPE_HENCHMAN = 1;
int ASSOCIATE_TYPE_ANIMALCOMPANION = 2;
int ASSOCIATE_TYPE_FAMILIAR = 3;
int ASSOCIATE_TYPE_SUMMONED = 4;
int ASSOCIATE_TYPE_DOMINATED = 5;
*/
if ( GetAssociateType(oPartyMem) < 2 )
{
nNumber++;
}
oPartyMem = GetNextFactionMember(oPC, FALSE);
}
return nNumber;
}
Seems like something which should be in the CSL library, so if you could test that, I'll put it in so others can use it as well.
Modifié par painofdungeoneternal, 01 mars 2012 - 05:42 .
#3
Posté 01 mars 2012 - 06:29
#4
Posté 01 mars 2012 - 06:50
Yes you'd have to make sure the oPC fed into that is in the party faction, but there are functions which can help with that. Can there be more than one party in MP? You don't have to use the currently controlled character, and can instead use functions to get the owner of whatever creature you are dealing with ( or even getfirstPC but you really have to think it thru as there generally are better options )
Modifié par painofdungeoneternal, 01 mars 2012 - 06:58 .
#5
Posté 01 mars 2012 - 07:07
#6
Posté 01 mars 2012 - 07:42
int GetFactChars()
{
int i = 0;
object oPC = GetFirstPC(); // -> or grab a PC in the party
object oFM = GetFirstFactionMember(oPC, FALSE);
while (GetIsObjectValid(oFM))
{
if (!GetAssociateType(oFM)) i++;
oFM = GetNextFactionMember(oPC, FALSE);
}
return i;
}
void main()
{
int i = GetFactChars();
SendMessageToPC(GetFirstPC(FALSE), "Test = " + IntToString(i));
}i = 6
( get back ta bug fixin, sir, if this works for ya )
#7
Posté 01 mars 2012 - 08:29
#8
Posté 01 mars 2012 - 09:24
i was going over his script and when you posted constants i thought that's brilliant! so I started playing with it ...
#9
Posté 01 mars 2012 - 09:37
hmm need a generic function where you just pass in parameters to decide which are included.
#10
Posté 01 mars 2012 - 09:43
int GetFacts(object oFM, int iAssocType1 = FALSE, int iAssocType2 = FALSE, int iAssocType3 = FALSE, ...)
?
edit, + int iPConly, gets complicated i'm sure
Modifié par kevL, 01 mars 2012 - 09:47 .
#11
Posté 01 mars 2012 - 10:02
It would have to be simple on top, and branch out inside to optimize the code. PC only would just switch the faction loop to true. Something like the following.
CSLCountFactionMembersOfType(
object oMainFactionMember = OBJECT_INVALID
int bIncludePlayers
int bIncludeHenchmen
int bIncludeAnimalCompanions
int bIncludeFamiliars
int bIncludeSummons
int bIncludeDominated
int bOnlyUndeadSummons = FALSE
int bOnlyMagicalSummons = FALSE ( the non undead ones like animals and celestial tigers, etc )
int bOnlyInfernalSummons = FALSE
int bOnlyAngelicSummons = FALSE
if OBJECT_INVALID can just get the "main" pc using getfirstpc or nearest pc depending on if they are in multiplayer. Regardless have it do a GetMaster( oPC ) to get the main actor in charge, even though that might not be needed at all.
Not sure how to get if a creature is a SOZ companion ( which is now associate type none. ) but that would be nice as well.
Modifié par painofdungeoneternal, 01 mars 2012 - 10:04 .
#12
Posté 01 mars 2012 - 10:53
// Characters created through the party creation mechanics // are stored in the Roster system but are flagged as // PlayerCreated to distinguish them from normal Roster // contained NPCs. Note that if the character is not // in the roster /at all/, this function returns false. // This script function can query that flag. // oCreature - object id of a creature to check int GetIsPlayerCreated( object oCreature );
not sure how SoZ adds them to the Roster, or if it's automagic.
btw, you prob. remember that henchmen are basically NwN henchmen - they just tag along and can't access their inventory etc (pretty much a nuisance that need constant protecting)
It would have to be simple on top, and branch out inside to optimize the code. PC only would just switch the faction loop to true.
Modifié par kevL, 01 mars 2012 - 10:57 .
#13
Posté 01 mars 2012 - 10:59
- was getting the same thing SD got : count 1, then quit
#14
Posté 01 mars 2012 - 11:34
Ok that makes sense, i'd like to rewrite the description on that function to make more sense as i never understood how it related to the SOZ party until now. Does it return true if it's the actual human being, or just one of the SOZ party members. ( think there is getisowned there as well if it returns true on both )
Modifié par painofdungeoneternal, 01 mars 2012 - 11:40 .
#16
Posté 02 mars 2012 - 12:41
At the time I wrote my scripts for this sort of thing I wasn't aware of GetIsPlayerCreated(). So I wrote my own function for that. Basically I found that player created characters do not have tags so that differentiates them from companions, associates, and henchmen. To differentiate between PC's and non-PC's you can check the roster - PCs will not be in the roster. Not sure about what happens in MP though.
Regards
#17
Posté 02 mars 2012 - 12:47
painofdungeoneternal wrote...
You need to be in multiplayer for it to ever not be 1,
right, Sry. Ever since GetIsPC( ) changed to mean getiscontrolled, I've been ambiguous about anything that says "PC" or "PConly" ( heck, my familiar is a PC at times ) - re. counting would be nice to have a quick routine that does PC + SoZ_char + companion/cohort .. <- what i meant by PC above.
no, it returns true only for an SoZ-style character that's in the Roster. getisowned is still needed for the true PC. they're exclusive, pretty sureOk that makes sense, i'd like to rewrite the description on that function to make more sense as i never understood how it related to the SOZ party until now. Does it return true if it's the actual human being, or just one of the SOZ party members. ( think there is getisowned there as well if it returns true on both )
SD: tks, Saved .Pdf
#18
Posté 02 mars 2012 - 02:22
Modifié par slowdive.fan, 02 mars 2012 - 02:33 .
#19
Posté 02 mars 2012 - 02:49
Kaldor Silverwand wrote...
Similar post about this from a year ago. May shed some light.
At the time I wrote my scripts for this sort of thing I wasn't aware of GetIsPlayerCreated(). So I wrote my own function for that. Basically I found that player created characters do not have tags so that differentiates them from companions, associates, and henchmen. To differentiate between PC's and non-PC's you can check the roster - PCs will not be in the roster. Not sure about what happens in MP though.
Regards
I set tags on our players to store information, as do quite a few other PWs. ( Grinning fool recommended this store store the players id in the database, and i know many PW's which have taken this advice, good spot to hide information actually as it can store any string you want there. ) By default there is no tag, but i'd avoid this unless you have complete control of everything that is installed. Probably not a problem to use this, especially if it's your module, but it likely something some creative content person is eventually going to take advantage of.
Modifié par painofdungeoneternal, 02 mars 2012 - 02:50 .
#20
Posté 02 mars 2012 - 09:58
(sure is perty tho)





Retour en haut







