Mr. Versipellis wrote...
My module sometimes teleports the PC between areas as part of the plot, so I've included a "special power" object that will summon their henchmen to the PC's side. The object is set up and working, but the trouble is that I can only get the first henchman added to appear at the PC's side.
This is exactly what the
Horn of Rallying in my
Sanctum of the Archmage modules does, except that it also works on all summons, familiars, and animal companions in the party.
At the moment, the script looks like this:
void main() {
object oPC = GetItemActivator();
object oHenchman = GetHenchman (oPC);
location lPC = GetLocation(oPC);
if (GetAreaFromLocation(lPC) == OBJECT_INVALID) return;
AssignCommand (oHenchman, ClearAllActions());
DelayCommand (3.0, AssignCommand (oHenchman, ActionJumpToLocation (lPC)));
}
Is there some way of getting the game to assign this command to more than one henchman? The "GetHenchman" function only seems to "get" the first henchman on the list.
As Henesua said, you want to use the "nth" parameter to make this work. I would use "GetAssociate" instead of GetHenchman, though. Here's a stripped-out version of the code from Sanctum; feel free to re-use it if you want.
EDIT: After reading this I actually noticed that there's a minor bug in the code that I need to fix. It tries to rally multiple associates of the same kind to the same location. That still works; they just "land on top of each other," which isn't what I intended. It's easy to fix, though, and the code should still answer the question originally posed.
#include "x2_inc_switches"
#include "x0_i0_anims"
location sa_GetRandomLoc(object oPC, float fd1, float fd2)
{
// This generates a random location in a ring around the PC no closer than fd1, and no further than fd2.
object oArea = GetArea(oPC);
location rloc = GetLocation(oPC);
int count = 0;
while (GetDistanceBetweenLocations(GetLocation(oPC),rloc) < fd1)
{
rloc = GetRandomLocation(oArea,oPC,fd2);
count++;
if (count > 100) break;
}
return(rloc);
}
void sa_rally(object oRally, location lRally, int type)
{
// This "rallies" an individual associate "oRally" of associate type "type"
// to location "lRally".
int nth = 1;
object oAssociate = GetAssociate(type,oRally,nth);
while (oAssociate != OBJECT_INVALID)
{
AssignCommand(oAssociate,ClearAllActions(TRUE));
AssignCommand(oAssociate,ActionJumpToLocation(lRally));
nth = nth + 1;
oAssociate = GetAssociate(type,oRally,nth);
//TD There seems to be a bug with GetAssociate on dominated associates:
//TD the "nth" param is being ignored, and it's just returning the
//TD same object, causing a loop. Terminate early.
if (type == ASSOCIATE_TYPE_DOMINATED) oAssociate = OBJECT_INVALID;
}
}
void sa_rally_party(object oRally)
{
// This "rallies" all associates of "oRally" to into a ring around him, no
// closer than 1.0, meters, and no further than 1.5 meters.
location lRally = GetLocation(oRally);
object oArea = GetArea(oRally);
sa_rally(oRally,sa_GetRandomLoc(oRally,1.0,1.5),ASSOCIATE_TYPE_HENCHMAN);
sa_rally(oRally,sa_GetRandomLoc(oRally,1.0,1.5),ASSOCIATE_TYPE_FAMILIAR);
sa_rally(oRally,sa_GetRandomLoc(oRally,1.0,1.5),ASSOCIATE_TYPE_ANIMALCOMPANION);
sa_rally(oRally,sa_GetRandomLoc(oRally,1.0,1.5),ASSOCIATE_TYPE_SUMMONED);
sa_rally(oRally,sa_GetRandomLoc(oRally,1.0,1.5),ASSOCIATE_TYPE_DOMINATED);
}
void main()
{
int nEvent = GetUserDefinedItemEventNumber();
object oPC;
if (nEvent == X2_ITEM_EVENT_ACTIVATE)
{
oPC = GetItemActivator();
AssignCommand(oPC,PlaySound("as_cv_eulpipe1"));
sa_rally_party(oPC);
}
}
Modifié par AndarianTD, 17 novembre 2012 - 01:21 .