I’m trying to create a new module for my grandkids to play and have hit a problem with something I thought would be simple. To give them a rather strong party ( so they won’t get slaughtered !) I want to give them three henchmen. I took the script from the Lexicon which says that the actual number possible is much higher but it doesn’t work anyway. Script there is
void main()
{
// No parameter other then a number needed
SetMaxHenchmen(6);
// Thats it!
}
I changed the number to 6 just in case the ability to summon a familiar counted in the henchmen numbers although I don’t know if it does.
However, it doesn’t work. In a clean module I can hire the first two but then the third replaces the first and I can’t get past two. With a script as simple as that I’m missing something obvious, but what? I’m no scripter but I don’t see an obvious check about number of current henchmen and even if it did I’ve set the number high enough to allow.
The script in the Action taken tab of the conversation is courtesy of Script Generator. It seems to work as the first person is hired without difficulty. I’ve also ensured that the tags are correct in each script.
void main()
{
object oTarget;
// Get the creature who triggered this event.
object oPC = GetEnteringObject();
// Only fire for (real) PCs.
if ( !GetIsPC(oPC) || GetIsDMPossessed(oPC) )
return;
// Only fire once per PC.
if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )
return;
SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
// Give the PC a new henchman.
oTarget = GetNearestObjectByTag("grandma", oPC);
AddHenchman(oPC, oTarget);
}
1 Like
Whenever you call AddHenchman(oMaster, oHench)
, oHench
abandons its current master and joints oMaster
. You are probably doing that. Explore which “grandma” is taken and when. Perhaps the same one?
I suggest to add debug messages anytime you suspect something wonky is going on in the script:
SendMessageToPC(GetFirstPC(), "grandma: " + GetName(oTarget));
Some remarks: SetMaxHenchmen
sets per-creature henchmen count. With 6 everybody (PCs and NPCs) can have 6 henches. Other associate types (summons, etc) are not henchmen (they don’t go through AddHenchman
) and everybody can have only one of these types (i.e. summons replace each other).
Extra advice from NWSH.
I’d also change this:
if ( GetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF)) )
return;
SetLocalInt(oPC, "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);
to this:
if ( GetLocalInt(oPC, "DO_ONCE__" + ObjectToString(OBJECT_SELF)) )
return;
SetLocalInt(oPC, "DO_ONCE__" + ObjectToString(OBJECT_SELF), TRUE);
to avoid race condition with multiple triggers with the same tag (what is the trigger’s tag?).
warning: below code may not work as intended in multiplayer
You can also set the var on the trigger instead and use ID of the PC to avoid cluttering the lvar dictionary of PC:
if (GetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC)))
return;
SetLocalInt(OBJECT_SELF, "DO_ONCE__" + ObjectToString(oPC), TRUE);
Thanks, @NWShacker. I’ll work my way through those suggestions.
Sorry, should have said. No triggers were harmed in the making of these scripts ! All three of these are hired through the Action Taken tab on a line of their conversation.
UPDATE
Tried your suggested change but then I couldn’t hire anybody. It occured to me that maybe nobody wanted to work for me
So, I went back to SG, redid the script with the hiring done by tag rather than owner of the conversation and made a new clean module with same scripts. Except this time the tags of the potential henchmen were “one”, “two” and “three”.
Three different conversations but all of which had the same script ( apart from tag obviously)
void main()
{
object oTarget;
// Get the PC who is in this conversation.
object oPC = GetPCSpeaker();
// Give the PC a new henchman.
oTarget = GetNearestObjectByTag("one", oPC);
AddHenchman(oPC, oTarget);
}
SUCCESS !!!
Thanks for the help. I went through everything in meticulous detail this time so you are right that I probably missed something simple.
If you ever need to perm, say, 3 henchmen from 5, a common practice is to SetMaxHenchmen() on module load, then put a conditional script in the hiring conversation which compares the current number of henchmen with GetMaxHenchmen() before hiring.
As you’ve discovered, you need a custom script, because the Bioware hiring scripts ignore these functions.
Although I see you got it working, your original attempt may have failed because it looks like you missed one of the tutorials in the Lexicon…
Tutorial - Huntsman - Guide To Henchman: Advanced Topics
Controlling the number of henchmen you can have.
If you want to have more than two henchmen per PC you will need to make an alteration to the ‘HireHenchman()’ function in ‘x0_i0_henchman’ as follows (approx line 481):
int nCountHenchmen = X2_GetNumberOfHenchmen(oPC);
int nNumberOfFollowers = X2_GetNumberOfHenchmen(oPC, TRUE);
// * The true number of henchmen are the number of hired
nCountHenchmen = nCountHenchmen ;
int nMaxHenchmen = X2_NUMBER_HENCHMEN;
should be changed to:
int nCountHenchmen = X2_GetNumberOfHenchmen(oPC);
//int nNumberOfFollowers = X2_GetNumberOfHenchmen(oPC, TRUE);
// * The true number of henchmen are the number of hired
//nCountHenchmen = nCountHenchmen ;
int nMaxHenchmen = GetMaxHenchmen();
Then save the altered file.
After that you will need to put the following line of script in the ‘OnModuleLoad’ script slot of the modules property sheet.
SetMaxHenchmen(5);
The number in brackets is where you change it to however many henchmen you want the player to be able to hire. In this case 5. If you just want the two henchmen then you do not need the other script changes, just the ‘SetMaxHenchmen(2);’ line in the ‘OnModuleLoad’ script.
1 Like