Miltiades Posted February 25, 2006 Share Posted February 25, 2006 I want to spawn multiple NPCs in one module. I learned how to spawn a NPC in a module using this tutorial: http://www.lucasforums.com/showthread.php?t=143536 I can't make multiple scripts, because the name of the file will always be the same (for example: k_231area_enter.nss => can't make another script with the same name). So I think I have to add a few things to the script. But I don't know anything about scripting. Can someone help? This is the script: void main() { object oEntering = GetEnteringObject(); object oPC=GetFirstPC(); if (GetIsPC(oEntering)) { //check if the object is already there to avoid multiple objects if (!GetIsObjectValid(GetObjectByTag("o"))) { //Note that the script uses OBJECT_TYPE_CREATURE instead of OBJECT_TYPE_PLACEABLE - that's the only difference with the container: CreateObject(OBJECT_TYPE_CREATURE, "my_npc_templateresref", Location(Vector(43.41,-0.28,9.66), 0.0)); // this portion is optional and will only work if you spawn the npc not too far from where you enter the area - careful if there are scripted cutscenes too. // You can also use the On perception event instead of the on enter script for this. NoClicksFor(0.5); //Make the NPC walk towards you: AssignCommand((GetObjectByTag("my_npc_tag")),ActionMoveToObject(oPC)); //Make the npc initiate the converstation after approcahing you: AssignCommand ((GetObjectByTag("my_npc_tag")), ActionDoCommand(ActionStartConversation(oPC))); } ExecuteScript("old_a_306onenter", OBJECT_SELF); } } Link to comment Share on other sites More sharing options...
Pavlos Posted February 25, 2006 Share Posted February 25, 2006 void main() { object oEntering = GetEnteringObject(); if(GetIsPC(oEntering)) { object oNPC1 = GetObjectByTag("MyNPC"); if (!GetIsObjectValid(oNPC1)) { CreateObject(OBJECT_TYPE_CREATURE, "templateresref", Location(Vector(x, y, z), 0.0)); } object oNPC2 = GetObjectByTag("MyOtherNPC"); if (!GetIsObjectValid(oNPC2)) { CreateObject(OBJECT_TYPE_CREATURE, "templateresref", Location(Vector(x, y, z), 0.0)); } ExecuteScript("old_entry", OBJECT_SELF); } } You can just continue adding your NPCs as you go. That or you can create a chain of these scripts firing. The first one would have: ExecuteScript("script2", OBJECT_SELF); at the end. And you could continue this provided your first script has the original name - though it is highly inefficient. Link to comment Share on other sites More sharing options...
Miltiades Posted February 25, 2006 Author Share Posted February 25, 2006 I tried the first code you gave, but it only works partially. I wanted a third NPC to spawn, so I copied this once: object oNPC2 = GetObjectByTag("MyOtherNPC"); if (!GetIsObjectValid(oNPC2)) { CreateObject(OBJECT_TYPE_CREATURE, "templateresref", Location(Vector(x, y, z), 0.0)); } and changed NPC2 to NPC3 where that was the case. For the second and third NPC I first used two Sith Soldiers. So the tag is: "SithSoldier" and the templateresref is: "n_sithsoldier". I tried it, but only one of the two Sith Soldiers spawned (NPC1 spawned, NPC2, which is a Sith Soldier, spawned, but NPC3, which is also a Sith Soldier, didn't spawn). Then I tried to change the tag and templateresref from the Sith Soldier, so I got two different NPCs (example: "sithsoldier1" and "sithsoldier2"). Now only my NPC1 spawns, and the other two don't. What's wrong? Link to comment Share on other sites More sharing options...
Elven6 Posted February 25, 2006 Share Posted February 25, 2006 So were would you put these scripts? Link to comment Share on other sites More sharing options...
tk102 Posted February 25, 2006 Share Posted February 25, 2006 It's kind of hard of hard to tell from reading this what all your .utc Tag/TemplateResRef are, but maybe another hypothetical script will help? Let's say you want 1 of soldier "A" and 2 of soldier "B" to spawn when you enter area 231TEL where: soldierA.utc : - Tag: soldierAtag - TemplateResRef: soldierAtemp soldierB.utc : - Tag: soldierBtag - TemplateResRef: soldierBtemp And you rename the original k_231_area_enter.nss to old231_enter.nss. Your new k_231area_enter.nss could appear like this: void main() { object oEntering = GetEnteringObject(); object oPC=GetFirstPC(); object oNPCA; object oNPCB1; object oNPCB2; //use whereami armband to get good location coordinates location locSpawn=Location(Vector(43.41,-0.28,9.66), 0.0); if (GetIsPC(oEntering)) { //check if the soldier A is already spawned if (!GetIsObjectValid(GetObjectByTag("soldierAtag"))) { oNPCA=CreateObject(OBJECT_TYPE_CREATURE, "soldierAtemp", locSpawn); // since soldier A should spawn with the soldier B, we can assume // that they have also not yet been spawned. Spawn them now. oNPCB1=CreateObject(OBJECT_TYPE_CREATURE, "soldierBtemp", locSpawn); oNPCB2=CreateObject(OBJECT_TYPE_CREATURE, "soldierBtemp", locSpawn); // here you can script actions for the soldiers using their // object variables: oNPCA, oNPCB1, oNPCB2 // example: // AssignCommand(oNPCA,ActionMoveToObject(oPC)); // AssignCommand(oNPCB1,ActionMoveToObject(oPC)); // AssignCommand(oNPCB2,ActionMoveToObject(oPC)); // AssignCommand(oNPCB1,ActionMoveToObject(oPC)); // AssignCommand(oNPCA, ActionDoCommand(ActionStartConversation(oPC))); } } ExecuteScript("old231_enter", OBJECT_SELF); } Link to comment Share on other sites More sharing options...
Miltiades Posted February 25, 2006 Author Share Posted February 25, 2006 Hey, thanks tk102, it worked! Link to comment Share on other sites More sharing options...
Miltiades Posted February 25, 2006 Author Share Posted February 25, 2006 I don't want to start to many threads, so I'll ask my question here. I want to add a journal entry when I take a datapad of a body. I followed the tutorial on "How to add journal entries", but I can't figure out how to use these scripts. --------- Next, I want a new journal entry when I collect 4 datapads. How do I do that? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.