PDA

View Full Version : Problem wth spawning npc


sekan
06-21-2007, 02:06 PM
Well i am trying to spawn an npc and i asked Mindtwistah if he could spawn the npc with editing the git file ( i am not good a editing the git file) . He did it and he send it to me after he edit it and i maked a mod file of it. Then the npc is spawned but i cant talk to it. Still i have changed the Npc tag and which convertion name it should use when i start a convertion . Then i tried to make a script but then the npc didn't spawn. So plz help me.

Here is the script i made

void main()
{
location lDestination = Location(Vector(95.08, 86.55, 0.0), 0.0);
object oNew = CreateObject(OBJECT_TYPE_CREATURE, "my npc tag", lDestination);
}

This is for k1

Master Zionosis
06-21-2007, 02:19 PM
You can spawn an NPC using this script:

void main()
{

float x=-64.56150f;
float y=-37.58458;
float z=0.00000;
float r=84.72446f;
vector vecNPC=Vector(x,y,z);
location locNPC=Location(vecNPC, r);
object oNPC=GetObjectByTag("TAG_OF_NPC");
object oTarget=CreateObject(OBJECT_TYPE_CREATURE,"NAME_OF_NPC",locNPC);
object oPC=GetFirstPC();
AssignCommand(oNPC,ActionMoveToObject(oPC));
AssignCommand(oNPC,ActionStartConversation(oPC,"CONVERSATION_NAME"));
}


Do a whereami cheat to get the X, Y and Z coordinates for the script and replace NAME_OF_NPC with the file name of the NPC (without the .UTC extension) and replace TAG_OF_NPC with the tag of the NPC you want to spawn and replace CONVERSATION_NAME with the conversation name of the NPC without the .dlg extension.

Hope this helps :)

stoffe
06-21-2007, 02:26 PM
Well i am trying to spawn an npc and i asked Mindtwistah if he could spawn the npc with editing the git file ( i am not good a editing the git file) . He did it and he send it to me after he edit it and i maked a mod file of it. Then the npc is spawned but i cant talk to it. Still i have changed the Npc tag and which convertion name it should use when i start a convertion.

Made sure you've set the name of the DLG file in the Conversation field in the UTC template, and make sure the name of the DLG file is valid (max 16 characters long, alphanumerical characters or underscore only).

Also make make sure you have assigned the proper AI script in the OnDialog event slot in the UTC file (k_def_dialogue01 is the default one).



Then i tried to make a script but then the npc didn't spawn. So plz help me.
void main() {
location lDestination = Location(Vector(95.08, 86.55, 0.0), 0.0);
object oNew = CreateObject(OBJECT_TYPE_CREATURE, "my npc tag", lDestination);
}


There is nothing wrong with this script from what I can see, it should work fine to spawn an NPC if used properly. Make sure where it says "my npc tag" does not contain the tag, but the name of the UTC file you want to spawn the character from (without the UTC extension). The UTC file needs to be properly named (max 16 character, alphanumerical/underscore only) for it to work as well, and present either in the module file or in the override folder.

Also make sure the X and Y coordinates are correct.

sekan
06-25-2007, 02:43 PM
Both script works fine( i had made a mistake). But i have another question. How do i make a script that makes a new npc spawn after you have get a quest etc quest: Kill a guy at Korriban. Then he will spawn on korriban after you have get the quest.

tk102
06-26-2007, 12:24 PM
Since you got the previous spawning scripts to work, you can use them as templates for your Korriban spawning script. I think the question you are asking is "How should I make the script fire?" That's always a question that needs answering in every script-related mod. You say you're getting a quest right? Well typically you get quests through dialogs. If your dialog takes place in the same area, you can fire the spawn script directly from the dialog. If the dialog that grants the quest is in a different module, you'll have to set a flag that you can check later (eg. using a global variable, having a special item in your inventory, etc.) Then, in the area you want the character to spawn, you'll have to find some way of triggering your script (eg. attach to an existing dialog, use script injection in the area's OnEnter event, create a custom trigger, etc) Your script will perform the flag check and then decide whether or not to spawn the creature if the criteria is met.

sekan
06-26-2007, 04:14 PM
Yes it's a quest. Hmm the special item could be a datapad but how do i create a trigger when i enter a module if my item is a datapad?

tk102
06-26-2007, 04:48 PM
Yes it's a quest. Hmm the special item could be a datapad but how do i create a trigger when i enter a module if my item is a datapad?

If you wanted to use the datapad (we'll say its tag is "sekan_datapad") and you were not using Journal entries you could do something like:
void main() {
// First check to see if the entering object is the PC
if (!GetIsPC(GetEnteringObject)) {
return;
}
// Now check if the sekan_datapad exists
if (!GetIsObjectValid( GetObjectByTag("sekan_datapad") ) {
return;
}
// So far so good, now check to make sure we haven't spawned already
// let's assume the NPC to spawn isn't going to get killed, so we can just
// check for his presence
if (!GetIsObjectValid( GetObjectByTag("sekan_npc") ) {
CreateObject( OBJECT_TYPE_CREATURE, "sekan_npc_resref", GetLocation(GetEnteringObject) );
}
}


The cleaner way would be to use Journal entries because you can keep track of when its time to spawn more easily. If your quest was 'sekan_quest', you could do something like

// First check to see if the entering object is the PC
if (!GetIsPC(GetEnteringObject)) {
return;
}
// Now see our quest is at the point where we want to spawn
int nQuest = GetJournalEntry("sekan_quest");
// let's pretend that in your quest, step 20 is when you to spawn
if (nQuest == 20) {
CreateObject( OBJECT_TYPE_CREATURE, "sekan_npc_resref", GetLocation(GetEnteringObject) );
//now that we've spawned him, we'll change our quest number
AddJournalQuestEntry("sekan_quest", 25);
}
}With this second code snippet, you don't even check for the presence of the datapad. That way if the PC decided he wanted to stash the datapad in one of the Ebon Hawk's plastisteel containers, he would still get the guy to spawn, whereas in the first script, he would not. The only thing is that you'll have to make sure when the datapad is first acquired, you set the Journal entry correctly (to 20 in this example).

See also Darth333's Quest tutorial (Journal Entries) here (http://www.lucasforums.com/showthread.php?t=143372).

sekan
06-26-2007, 05:46 PM
What do i do if there are multiple npcs that needs to be spawned?

sekan
06-27-2007, 01:18 PM
Anyway i have tried some times to get the script work but i just get errors.

void main() {
if (!GetIsPC(GetEnteringObject)) {
return;
}
(!GetIsObjectValid( GetObjectByTag("hk47_bounties") ) {
return;
}
if (!GetIsObjectValid( GetObjectByTag("Groska") ) {
CreateObject( OBJECT_TYPE_CREATURE, "Groska", GetLocation(GetEnteringObject) );
}
}


What is wrong? I get errors in the seceond return and i dont know why.
Please help.

tk102
06-27-2007, 01:55 PM
Fixed.
void main() {
if (!GetIsPC(GetEnteringObject())) {
return;
}
if (!GetIsObjectValid( GetObjectByTag("hk47_bounties") )) {
return;
}
if (!GetIsObjectValid( GetObjectByTag("Groska") )) {
CreateObject( OBJECT_TYPE_CREATURE, "Groska", GetLocation(GetEnteringObject()) );
}
}

sekan
06-27-2007, 03:38 PM
Fixed.
void main() {
if (!GetIsPC(GetEnteringObject())) {
return;
}
if (!GetIsObjectValid( GetObjectByTag("hk47_bounties") )) {
return;
}
if (!GetIsObjectValid( GetObjectByTag("Groska") )) {
CreateObject( OBJECT_TYPE_CREATURE, "Groska", GetLocation(GetEnteringObject()) );
}
}

Yeah it works but how do i set the cordinates in this script or must i make two diffrent scripts?

tk102
06-27-2007, 04:52 PM
Yeah it works but how do i set the cordinates in this script or must i make two diffrent scripts?
Just like you did in your first post with lDestination.

1. Add a line at the beginning:location lDestination = Location(Vector(95.08, 86.55, 0.0), 0.0);
2. Replace the GetLocation(GetEnteringObject()) in the CreateObject function with lDestination.

sekan
06-28-2007, 05:31 PM
Thanks tk102.

sekan
06-29-2007, 11:05 AM
I have a little problem. I have killed the npc i spawned but he when i enter the sith academy again he's alive. How can i fix that?

Mindtwistah
06-30-2007, 01:32 PM
TK:s post in this thread: http://lucasforums.com/showthread.php?t=143536