Jump to content

Home

Script help needed: spawning npcs


Darth333

Recommended Posts

How could I spawn an npc at a specific location at a specific time and make that npc walk towards my pc and initiate conversation?

 

An example would be the mysterious guy that spawns between the hotel and the Republic Embassy on Manaan after your PC exits the hotel during Sunry's murder inquiry.

 

Another example: the twilek that spawns on Tatoine and asks for your autoprint when you are the swoop champion.

Link to comment
Share on other sites

  • Replies 56
  • Created
  • Last Reply

Let's see, sounds like you want to set a Trigger (a .UTT file) at the location where the party will cause the NPC to spawn. In that UTT file, set the ScriptOnEnter field to point to the script that you will write. In that script, you'll probably want to use functions such as CreateObject (#243) to spawn your NPC, ActionMoveToObject (#22) to get your NPC to walk* and ActionStartConversation (#204) to initiate the dialog. (You can look up their syntax in nwscript.nss).

 

* You'll have to embed this one inside an AssignCommand (#6) function.

 

Is that enough to go on?

Link to comment
Share on other sites

:ball: :ball: :ball: OK I tried but I'm lost! HELP! :ball: :ball: :ball:

 

I thought I would be able to do it with what you gave me TK but not yet. Would it be possible to see an example of such script - not only the syntax that is found in the nwscript.nss - to get started? (I'm not sure about how to fill in the blanks properly) See the problem is that a couple of weeks ago C++ sounded more like a brand of orange Juice to me than anything else (OK, I'm exagerating a little but not that much )

 

I've been playing with some scripts for my Dustil mod and it worked pretty well but I had similar examples in bifs so i was able to make the link with the other elements contained in the game and thus modify the scripts to get what I wanted. However, this this time it seems everything is already compiled (apart that nwscript).

Link to comment
Share on other sites

void main() {

// in your game, do a 'whereami' cheat to
// determine your location then plug in
// three values here
float x=14.19f;  
float y=27.01f;
float z=-1.27f;

//orientation doesn't matter too much
float r=0.0f;

// the following two functions create
// the location for your NPC to spawn at
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);

//spawn! (in this case, a Republic solider from the Endar Spire)
object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"n_repsold001",locNPC);

// now tell the NPC to talk to your PC
object oPC=GetFirstPC();
AssignCommand(oNPC,ActionMoveToObject(oPC));
AssignCommand(oNPC,ActionStartConversation(oPC,"my_dlg"));
}

I tested this at the very first scene on the Endar Spire and it worked alright.

 

 

Edit:

I decided to tweak it a bit and use end_trask01.dlg in the last line. After tweaking that .dlg a bit (removing a bund of Speaker: end_trask fields, the spawned republic soldier came up to me and started speaking Trask's lines with his voice and with lipsync. Screenshot

Link to comment
Share on other sites

I tried the script and it works...well it spawns NPCs for sure. I tested the script with the Deadeye Duncan dlg file on Manaan and i spawned Duncan as you can see...

 

http://mars.walagata.com/w/darth333/deadeye.JPG :laughing:

 

In fact 3 new Deadeye Duncan (one for each party member) appear at every step I make near the location where Duncan spawns. I now have an entire army of Deadeye Duncans (not sure such army would be very effective).

 

The dialog part works fine and I know how to make the script to them walk away. But I'd like to have only one Duncan spawning and only once. How do I do this?

Link to comment
Share on other sites

You'll need to set a flag somewhere. Then in your script, check at the very beginning whether that flag has been set. If not, then execute the rest of the script. Otherwise exit. Then, at the end of your script, set the flag.

 

Now, you have to figure out whether or not you plan on checking that flag elsewhere in the game. You might want to use it to trigger some other event. In that case, you'll need to set a Global variable using either SetGlobalBoolean or SetGlobalNumber functions. The downside to this is that you have to find an existing Global variable or you have to modify the globalcat.2da file to add a new one. Don't worry -- you should be able to reuse ones from the Endar Spire for example without much consequence. (Feel free to use my Global Variable Comparison tool to see how globals change throughout the game.)

 

If you don't want to use the flag again, but you just don't want an army of DeadEye Duncans, you can get away with setting a Local Boolean with the SetLocalBoolean function on the trigger object itself.

 

Here are examples of both ways:

 

 

// This method uses a Global Numeric value
void main() {

if (GetGlobalNumber("End_TraskTalk") == 333) { return; }

// insert thre rest of the script here...
// ...
// and then at the end add:
SetGlobalNumber("End_TraskTalk",333);
}

 

// This method uses a Local Boolean value
void main () {
object oTrigger = GetObjectByTag("your_trigger_objects_tag");

if (GetLocalBoolean(oTrigger,0) == TRUE) { return; }

// insert thre rest of the script here...
// ...
// and then at the end add:
SetLocalBoolean(oTrigger,0,TRUE);
}

Link to comment
Share on other sites

You can use a local boolean that way if you like, T7. In that case, you would probably want to make the object the NPC who is speaking the dialog although the local variable could be any object you like I suppose.

 

To make the NPC say something once and only once, you would first write a script that goes something like:

 

int StartingConditional() {
  if (GetLocalBoolean(OBJECT_SELF,0) == FALSE) { return TRUE; }

  return FALSE;
}

 

Then in the appropriate EntriesList struct, you would reference your script in the Active field. That way, the script is fired in order to check whether or not the NPC says the Entry referenced in the Index field.

 

Then, in the Entry List where your one-time text is mentioned, you would set a reference to another script in the Script field. This script would go something like:

void main() {
  SetLocalBoolean(OBJECT_SELF,0,TRUE);
}

In this way, the local flag is set once the dialog is spoken, so it won't be spoken again. Of course, you have to design your dialog tree so there's no other points of re-entry also.

 

The flag is stored in the NPC (courtesy of the OBJECT_SELF pre-defined variable).

Link to comment
Share on other sites

  • 1 month later...
Originally posted by tk102

void main() {

// in your game, do a 'whereami' cheat to
// determine your location then plug in
// three values here
float x=14.19f;  
float y=27.01f;
float z=-1.27f;

//orientation doesn't matter too much
float r=0.0f;

// the following two functions create
// the location for your NPC to spawn at
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);

//spawn! (in this case, a Republic solider from the Endar Spire)
object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"n_repsold001",locNPC);

// now tell the NPC to talk to your PC
object oPC=GetFirstPC();
AssignCommand(oNPC,ActionMoveToObject(oPC));
AssignCommand(oNPC,ActionStartConversation(oPC,"my_dlg"));
}

 

"vector vecNPC=Vector(x,y,z);

location locNPC=Location(vecNPC, r);"

 

What do i need to write in in those rows?

 

Edit: Or if i don't need to to anything with those rows, where do i need to write the area module?

Link to comment
Share on other sites

"vector vecNPC=Vector(x,y,z);

location locNPC=Location(vecNPC, r);"

 

What do i need to write in in those rows?

 

First go into the module where the spawning will occur. Walk to the position that you'd like to spawn the NPC. Do the cheat 'whereami' and write down the 3 coordinates. Put those into the lines:

float x=...
float y=...
float z=...

 

And you can play with the value of r to make the NPC face the direction you like.

Link to comment
Share on other sites

Originally posted by tk102

First go into the module where the spawning will occur. Walk to the position that you'd like to spawn the NPC. Do the cheat 'whereami' and write down the 3 coordinates. Put those into the lines:

float x=...
float y=...
float z=...

 

And you can play with the value of r to make the NPC face the direction you like.

I did it and it didn't work. In the Lines i wrote, i don't need to write anything?
Link to comment
Share on other sites

Originally posted by Darth_ToMeR

To spawn someone i need to "replace" someone that exist in the game in the place i want to spwan him?

 

No. You can simply add someone if you want. If the .utc of the npc you want to spawn is already in the module (example Deadeye Duncan on Manaan - http://www.pcgamemods.com/5410/ ) you can even attach the script to a dlg to fire the script.

 

If not, you'll need to edit the .git file to make the npc available.

Link to comment
Share on other sites

Originally posted by Darth333

No. You can simply add someone if you want. If the .utc of the npc you want to spawn is already in the module (example Deadeye Duncan on Manaan - http://www.pcgamemods.com/5410/ ) you can even attach the script to a dlg to fire the script.

 

If not, you'll need to edit the .git file to make the npc available.

Sorry about my questions, but this is the first time i try modding. Can you tell me where are the .git files and what i suppose to do with them?
Link to comment
Share on other sites

Originally posted by Darth333

.git files are located in RIMs>modules>.rim>Dynamic Area Info

 

You can create a trigger or edit the creatures list. If you want, we can transfer this discussion via pm and post a summary when it's done.

I think i understand it. I will send you PM if i'll have a problem. Thanks.

Link to comment
Share on other sites

  • 3 weeks later...

OK all, i need some help.

 

Im trying to spawn an npc so that they come and talk to you (im testing it with holowspire). BUT ive come across a problem, the character doesnt talk to me when i use the local boolean code, but i still only want one to spawn.

i.e. When i do not use the localboolean code, there are multiple spawns, the one that just spawns does not speak to me, however when a new one spawns, the previous one that spawned comes and talks to me with the set dialogue (called dd_mono,) and after it is finsihed he reverts back to his orininal dialogue of (dd_doomdealer) when i speak to him

however, as i only want one of the character to spawn, i use a localboolean code, and the one spawn does not come and speak to me.

 

any help would be greatly appreciated :

heres what ive got at the moment (the single spawn one)

 

void main() 
{
object oTrigger = GetObjectByTag("spawn1"); 
if (GetLocalBoolean(oTrigger,0) == TRUE) { return; } 
float x=33.34; 
float y=147.71; 
float z=0.00; 
float r=0.0f; 
vector vecNPC=Vector(x,y,z); 
location locNPC=Location(vecNPC, r); 
object oNPC=GetObjectByTag("DoomDealer"); 
object oTarget=CreateObject(OBJECT_TYPE_CREATURE,"dd_doomdealer",locNPC); 
object oPC=GetFirstPC(); 
AssignCommand(oNPC,ActionMoveToObject(oPC)); 
AssignCommand(oNPC,ActionStartConversation(oPC,"dd_mono")); 
SetLocalBoolean(oTrigger,0,TRUE); 
} 

Link to comment
Share on other sites

Hey guys I would really appreciate some help with this one. All I want to do is be able to spawn custom made NPC's(1-3) to the same area as the main PC and have the NPC attack the PC. This is much like the Dark Jedi's that appear throughout the game from time to time.

 

My idea was to make a nice number of individual NPC's that the user can spawn to fight at anytime any place in the gameat will. It would work as a user called side quest as the NPC's would progess in level of difficulty and challenge for the player.

 

Yes there is KOTOR area and the Matrix mods, but those just don't serve this exact purpose that I wanted. "ANY" help would be welcomed. Thx.

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...