Author Topic: An Object to Summon Henchmen to the PC's Side?  (Read 533 times)

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« on: November 16, 2012, 05:48:59 pm »


               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. At the moment, the script looks like this:

void main(){object oPC = GetItemActivator();
object oHenchman = GetHenchman (oPC);;location lPC;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.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #1 on: November 16, 2012, 08:50:00 pm »


                An important part of the GetHenchman function is that you can specify the index of the henchman you are getting. Default use of the function gets the first in the list of henchmen. But you can change this by adjusting the second variable - nInt - in the function call:

object GetHenchman(
    object oMaster = OBJECT_SELF,
    int nInt = 1
);

My recommendation is to loop through all henchment as follows

int nInt   = 1;
object oHench   = GetHenchman(oMaster, nIt);
while(oHench!=OBJECT_INVALID)
{
   // do what you need to the henchman here

  // then get the next one
  oHench = GetHenchman(oMaster, ++nInt);
}
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #2 on: November 17, 2012, 12:34:22 am »


               That won't compile - "ERROR: PARSING VARIABLE LIST"
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #3 on: November 17, 2012, 06:43:00 am »


               there's a type-o that I see.  The nIt variable after oMaster should be nInt.

object oHench = GetHenchman(oMaster,nInt);
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #4 on: November 17, 2012, 08:17:09 am »


               I didn't type that out in the toolset so there are likely to be typos. For that matter oMaster isn't defined either. The point is to use the second variable in GetHenchman and increment it so that you can step through all the henchman you have.
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #5 on: November 17, 2012, 01:00:50 pm »


               

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 .
                     
                  


            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #6 on: November 17, 2012, 01:18:01 pm »


               Thanks, I got it working perfectly c:
               
               

               
            

Legacy_AndarianTD

  • Hero Member
  • *****
  • Posts: 725
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #7 on: November 17, 2012, 01:23:38 pm »


               

Mr. Versipellis wrote...

Thanks, I got it working perfectly c:


Glad to hear! 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 exactly what I intended. That's easy to fix, though, if you want to do that (just move the sa_GetRandomLoc call to inside the loop in sa_rally).
               
               

               


                     Modifié par AndarianTD, 17 novembre 2012 - 01:23 .
                     
                  


            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
An Object to Summon Henchmen to the PC's Side?
« Reply #8 on: November 18, 2012, 10:56:00 pm »


               "Horn of Rallying"? I went with a little wooden "Friendship Charm"... different strokes for different folks '<img'>
I think I prefer your version of the code - I'll replace my version with yours if that's okay?