Hello NWN Community!
I needeth thy help. These days, I decided to create a henchman system. In order for it to work, a Creature named “Construct” is spawned and Tagged after the PC Player Name. After the PC talks with the said Creature, the Construct copies all the stats, sounds, name, feats, skills and inventory of the PC. An exact copy…
The problem is this. During that small gap between Creating the Construct and speaking with the Construct, the PC is free to do whatever he wants. So, after a bit of thought, I decided to put an ExecuteScript function inside a DelayCommand function , in order to delete the Construct after a given time.
The first Script is simple. oPC is the Player, oSelf is the NPC (Who holds the shop that makes the Construct) and lTarget is used to set where the Creature will be spawned.
SetLocalString is called, in order to make a simple Text Appears check in the conversation with the NPC.
TakeGold… blah blah
And finally… The last piece of code.
Since the creature that is created gets its Tag changed to the PCPlayerName, I found it a must do - to save its Tag as a String as a Local Variable of the Area of Spawn.
object oPC = GetPCSpeaker();
location lTarget = GetLocation(GetWaypointByTag("HENCHMANSPAWN"));
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "henchman", lTarget, TRUE, GetPCPlayerName(oPC));
object oSelf = OBJECT_SELF;
SetLocalString(oSelf, "PCName", GetPCPlayerName(oPC));
TakeGoldFromCreature(500000, oPC, FALSE);
object oConstruct = GetObjectByTag(GetPCPlayerName(oPC));
SetLocalString(GetArea(oSelf), "ConstructTag", GetTag(oConstruct));
DelayCommand(IntToFloat(60), ExecuteScript("silvmn_npc_avin6", oConstruct));
Simple enough right?
So once again, the second script…
lArea and oArea gets the area where the Creatures spawn.
ConstructTag string is used to get the Tag of the Creature.
And finally, oConstruct gets the Creature as an object.
Afterwards, if the name of the object oConstruct is “Construct”, that means that the Player hasn’t talked to the spawned Creature yet and the Construct hasn’t copied the name of the PC.
If the Player had talked with the Construct after it was spawned, the name of the oConstruct == Name Of PC.
So, I set the LocalString for the Text Appear check.
I assign as a command to the oConstruct to flag itself as DestroyAble.
And then I destroy it… but it won’t go away! It stays right there, waiting for the PC…
Why won’t you go away!!!
location lArea = GetLocation(GetWaypointByTag("HENCHMANSPAWN"));
object oArea = GetAreaFromLocation(lArea);
string ConstructTag = GetLocalString(oArea, "ConstructTag");
object oConstruct = GetObjectByTag(ConstructTag);
if (GetName(oConstruct, FALSE) == "Construct"){
SetLocalString(GetObjectByTag("Silvmn_NPC_Avina"), "PCName", "!NULL");
AssignCommand(oConstruct, ActionDoCommand(SetIsDestroyable(TRUE, FALSE, FALSE)));
DestroyObject(oConstruct, 0.0f);
}
But, when I use the exact lines on a RemoveHenchman script, it works just fine…
object oHench = OBJECT_SELF;
SetFormerMaster(GetPCSpeaker(), oHench);
RemoveHenchman(GetPCSpeaker());
SetLocalInt(oHench, "IsTaken", 0);
AssignCommand(oHench, ActionDoCommand(SetIsDestroyable(TRUE, FALSE, FALSE)));
DestroyObject(oHench, IntToFloat(2));
I’ve tried using SendMessageToPC commands, just to check if the
GetName(oConstruct, FALSE) == “Construct” condition is met… Which it DOES!
For some reason, the DestroyObject function just will not work…
Sorry for the long post. Thank you for your time.