Jump to content

Home

Get a soldier/jedi when NPC says [blahblah]


The Betrayer

Recommended Posts

You'd have to do several things. First, you need to make a .utc for the NPC that you want spawned. Use KT to extract an existing .utc and make the changes you need with the GFF editor. Be sure to give it a unique name, and change the reference tags to match your new NPC's name.

 

Then you have to make a script that spawns the NPC and attach it to a dialogue file. Here's a sample script:

 

void main()

{

CreateObject(OBJECT_TYPE_CREATURE, "SPAWNED NPC'S NAME", Location(Vector(X.XXX,Y.YYY,Z.ZZZ), ANGLE));

}

 

Save the script as a .nss file and compile it with the NWN script compiler.

 

You'll have to use the whereami cheat (or the whereami armband for K2) to get the location (replace all the Xs, Ys, and Zs with the correct coordinates), and for the angle, 0.00 is North, 180.00 is South, etc. (I think :p).

 

And finally, extract the dialogue file of the NPC you're going to talk to in order to spawn the other NPC. Edit the dialogue file and attach the script to one of the dialogue nodes.

 

That's everything, I think.

Link to comment
Share on other sites

For that, you need to first add the line:

 

location lDestination = GetLocation(GetFirstPC());

 

And then replace

 

Location(Vector(X.XXX,Y.YYY,Z.ZZZ), ANGLE));

 

with

 

lDestination);

 

So the full script would be:

 

void main()

{

location lDestination = GetLocation(GetFirstPC());

CreateObject(OBJECT_TYPE_CREATURE, "SPAWNED NPC'S NAME", lDestination);

}

 

And on another matter...do you want the NPC to follow you? If so, you'll need another script for that.

Link to comment
Share on other sites

The first one posted by SithRevan should work.

 

As for following you into another module...eh...that's where it gets complicated.

 

You could make an OnEnter script that would spawn them. But you'd also want to make sure that the NPCs aren't spawned unless you orignally talked to that NPC in the other module. You'd have to ask someone else how to do that. :giveup:

Link to comment
Share on other sites

Alright, so I guess here's what you want to do:

 

You want to talk to a person who will give you a soldier. Once he gives it to you, you want that soldier to follow you into another module and then follow you around (and attack for you). Here's what you need to do (largely step by step):

 

1) Use Kotor Tool to extract a .utc of a creature you want to use as the soldier. Use the GFF editor to make changes to its name, etc.

 

2) Write the dialog for your NPC (which will give you the soldier - to attach it edit the NPC's .utc file in Kotor Tool) and on the last dialog entry (the [End Dialog] entry) attach this script (if you want the soldier to spawn right next to the PC):

 

void main()
{
location lDestination = GetLocation(GetFirstPC());
CreateObject(OBJECT_TYPE_CREATURE, "SPAWNED NPC'S NAME", lDestination);
}

 

N.B. Replace "Spawned NPC's Name" with the name you put in its .utc file in step 1.

 

3) Go back to the GFF editor. There should be an option "Heartbeat script" or something similar. It basically means a script that triggers as soon as the creature is spawned. In this case it will be this henchman script:

 

// k_fpm_heartbtxx

#include "k_inc_debug"
#include "k_inc_generic"
#include "k_inc_switch"
#include "k_inc_utility"



void main()
{



           object oEnemy = GetNearestCreature(CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN, OBJECT_SELF, 1, CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY);
           if(!GN_GetSpawnInCondition(SW_FLAG_AI_OFF) && !GetSoloMode())
           {
               if(GetPartyMemberByIndex(0) != OBJECT_SELF)
               {
                   if(//GetCurrentAction(OBJECT_SELF) != ACTION_FOLLOW && 
                      GetCurrentAction(OBJECT_SELF) != ACTION_WAIT  &&
                      !GetIsConversationActive() &&
                      !GN_GetSpawnInCondition(SW_FLAG_SPECTATOR_STATE) &&
                      GetCommandable())
                   {

                         if(!GN_GetIsFighting(OBJECT_SELF) && !GetIsObjectValid(oEnemy))


                           ClearAllActions();
                           if(GetDistanceBetween(OBJECT_SELF, GetPartyMemberByIndex(0)) < 5.0)
                           {
                            ClearAllActions();
                            ActionForceMoveToObject(GetPartyMemberByIndex(0), FALSE, 1.0);
                            //SendMessageToPC(GetFirstPC(), "Debug Message: Henchmen just executed the bWalk routine.");
                           }
                           if(GetDistanceBetween(OBJECT_SELF, GetPartyMemberByIndex(0)) > 5.0)
                           {
                            ClearAllActions();
                            ActionForceMoveToObject(GetPartyMemberByIndex(0), TRUE, 3.5);
                            //SendMessageToPC(GetFirstPC(), "Debug Message: Henchmen just executed the bRun routine.");
                           }

                    }
               }
           }
           else if(GetSoloMode() && GetCurrentAction(OBJECT_SELF) == ACTION_FOLLOWLEADER)
           {
               ClearAllActions();
           }
           if(GN_GetSpawnInCondition(SW_FLAG_EVENT_ON_HEARTBE  AT))
           {
               SignalEvent(OBJECT_SELF, EventUserDefined(1001));
           }



}

 

4) Okay, now that the henchman is done he'll follow you around and I believe he will attack your enemies. But once you go into a different module he'll disappear. To make him respawn you'll need to do a number of things.

 

5) The first is to set a global variable when the creature spawns. To do this, simply attach the script to the same dialog entry as the one that spawned the creature (go back up to step 2):

 

void main() {
   if (!GetGlobalBoolean("YOUR_VARIABLE_NAME") && (GetEnteringObject() == GetFirstPC())) {
       SetGlobalBoolean("YOUR_VARIABLE_NAME", 1);
   }
}

 

You'll need to extract the globalcat.2da (from Kotor Tool) and edit it in the .2da editor (also included in Kotor Tool). Just add an entry with whatever name you want and replace the "MyPlayerCheck" in the code above with that name.

 

6) Now you'll need extract the on_enter script for the module/s that you're going to go into, but only when you've actually got the creature as your henchman. So you'll use a combination of this code:

 

return GetGlobalBoolean("YOUR_VARIABLE_NAME");

 

And this code:

 

void main()
{
location lDestination = GetLocation(GetFirstPC());
CreateObject(OBJECT_TYPE_CREATURE, "SPAWNED NPC'S NAME", lDestination);
}

 

Basically you ONLY want the NPC to spawn after you've got him for the first time. And that should be it.

 

7) Oh except when you want him to go away. I think there's an option in the .utc for a script to fire when the NPC dies (on death script or something). Simply attach this script:

 

void main() {
   SetGlobalBoolean("YOUR_VARIABLE_NAME", 0);

}

 

That way he won't respawn once he's died. If there isn't actually an "on death" script option, slap me and we'll sort something out.

 

And I think that should be it. Someone please correct me if I'm wrong. I actually have no experience with henchman scripting, but this should work. See the above tutorial if the henchman code I gave you doesn't work.

Link to comment
Share on other sites

  • 1 month later...
there is no need for a ondeatch if there is even one lol

 

Where did you get the idea that this was an on death script?

 

How about "dismissing" the henchman? What script should I attach to the dialog? (I want him to fade)

 

That was the thing I posted the script for.

 

BTW use this follow script instead of the old one I posted.

//:: k_def_heartbt01
/*
   Default heartbeat script
*/
//:: Created By: Preston Watamaniuk
//:: Copyright (c) 2002 Bioware Corp.

#include "k_inc_switch"
#include "k_inc_debug"

void main()
{
   ExecuteScript("k_ai_master", OBJECT_SELF, KOTOR_DEFAULT_EVENT_ON_HEARTBEAT);
   /*
   object oEnemy = GetNearestCreature(CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, OBJECT_SELF,1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN);

   if(!GN_GetSpawnInCondition(SW_FLAG_AI_OFF))
   {
       if(GN_GetSpawnInCondition(SW_FLAG_AMBIENT_ANIMATIONS) || GN_GetSpawnInCondition(SW_FLAG_AMBIENT_ANIMATIONS_MOBILE))
       {
           string sWay = "WP_" + GetTag(OBJECT_SELF) + "_01";
           int nSeries = GetLocalNumber(OBJECT_SELF, WALKWAYS_SERIES_NUMBER);
           if(!GetIsObjectValid(GetObjectByTag(sWay)) && nSeries <= 0)
           {
               if(GetCurrentAction(OBJECT_SELF) != ACTION_MOVETOPOINT)
               {
                   if(!GN_GetIsFighting(OBJECT_SELF) && !GetIsObjectValid(oEnemy))
                   {
                       GN_PlayAmbientAnimation();
                   }
               }
           }
       }
   }
   if(GN_GetSpawnInCondition(SW_FLAG_EVENT_ON_HEARTBEAT))
   {
       SignalEvent(OBJECT_SELF, EventUserDefined(1001));
   }
   */

   int nTest = GetGlobalNumber("Tar_Sarna");

   if  (nTest == 32)
 {
location lMe=GetLocation(GetFirstPC());
 ActionForceMoveToLocation(lMe,TRUE);
 }
}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...