Jump to content

Home

Script help needed: spawning npcs


Darth333

Recommended Posts

  • Replies 56
  • Created
  • Last Reply
Originally posted by Darth333

I sent you an identical script the other day to spawn a door that uses the Execute Script function with detailed instructions. Have a look at it ;)

Dear Darth333

 

You are too kind and friendly, but...Have pit on me.:D Right now my head is so fuelled with scripts, area, dialog, skins, models... I don't think my brain can handle much more :D. Here is the script you sent me:

[size=1] void main()
{
   //again we get the variable we want to check
   int nResult = GetGlobalNumber("RECRUIT_ABC");

   // and now we check for plot advancement and make sure XYZ spawns only once:
  if ((nResult == 2) && (!GetIsObjectValid(GetObjectByTag("XYZ"))))

   {
// the coordinates where you want XYZ to spawn:
     float x=248.54f;  
     float y=191.10f;
     float z=0.27f;
     float r=0.0f;
     vector vecNPC=Vector(x,y,z);
     location locNPC=Location(vecNPC, r);

//spawn XYZ
     object oNPC=CreateObject(OBJECT_TYPE_CREATURE,"XYZ",locNPC);
[/size] 

I got the picture, kind of, but my real doubt is where to attach the script. The area where i want to spawn him is a NEW_AREA, so there isn't, at least there i know of, a default OnEnter script (like k_ptat17ab_enter.nss for Tattoine docking bay).

 

I understand how the script will spawn the npc. I understand the plot advancement detection. What i do not understand is where should i attach it. So the npc gets spawned when the NEW_AREA loads.

Link to comment
Share on other sites

Originally posted by Xavier2

What i do not understand is where should i attach it. So the npc gets spawned when the NEW_AREA loads.

Originally posted by Xavier2

hmmm...The OnEnter already has the Default script from the AREA which NEW_AREA is based on. Would it corrupt something?:confused:

Try your script in the OnEnter field instead of the default script and see if it works, worse comes to worse, you can add an execute script function line on your script to fire the default script after yours.

 

I don't see how it could corrupt anything...

 

:D

Link to comment
Share on other sites

Take the OnEnter script of your area, rename it to blabla.ncs. Then paste this in notepad (change the tags as appropriate) and save it with the name of your old OnEnter script and compile:

 

void main()
{
    int nPlot = GetGlobalNumber("MY_PLOT");
    object oEnter = GetEnteringObject();

    if (GetIsPC(oEnter))
 {
       if (nPlot == 4) 
   {
//  this line checks if your custom npcs are already there:
     if(!GetIsObjectValid(GetObjectByTag("my_npc")))
// do a whereami cheat to get the coordinates where you want to spawn
// the npcs and replace the 0.00 by those coordinates:
        CreateObject(OBJECT_TYPE_CREATURE, "my_npc_tag", Location(Vector(00.00, 00.00, 0.00), 0.0));    
   }
 }
// This fires the original OnEnter script that we renamed
    ExecuteScript("blabla", GetModule());
}

Link to comment
Share on other sites

Originally posted by Darth333

Take the OnEnter script of your area, rename it to blabla.ncs. Then paste this in notepad (change the tags as appropriate) and save it with the name of your old OnEnter script and compile:

Sometimes the answer is just in front of you...And i used this sort of solution before...:p Thanks;)

Link to comment
Share on other sites

Archived

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


×
×
  • Create New...