Author Topic: is it possible....  (Read 368 times)

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
is it possible....
« on: December 15, 2010, 06:24:00 am »


               ... to make a group of NPCs spawn at random locations? i know it can be done with one NPC, but can a whole group be spawned together, in the same area, and do so at random locations (different maps)

i would like to have 12 NPCs spawn in random locations in my server as a group. i have about 6 locations i'd like this group to spawn at. can it be done? if so, how?

thanks in advance 
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
is it possible....
« Reply #1 on: December 15, 2010, 01:43:58 pm »


               Yes it is possible. I did a random spawner on the vault which could be modified to do what you want.

http://nwvault.ign.c....Detail&id=3318

Although this spawner has a lot of things you don't need such as spawning randome creatures from a list.
I made a variation of this spawner which might more likely suit your needs.  What it does is spawn to a random newly created waypoint, so it's always random, at a certain distance from the PC.  I use the method of creating a new waypoint while destroying the old one to which the creatures last spawned and usually I spawn 3 groups 2 of them hostile to the 3rd.  So 3 groups of 3-4 creatures each which could be used to reach your 12. 
I use a for loop to spawn more than one creature.

Here is one that does not use a for loop and just spawns creatures to that waypoint with the tag:   Spawn.  The resref of my (Waypoint) Spawn is waypoint006 so I just create another one of them within the script after the spawn occurs.

    #include "NW_I0_GENERIC"
    void main()
    {
        object oPC = GetEnteringObject();
        object oArea = GetArea (oPC);
        object oWaypoint = GetFirstObjectInArea(oArea);
        float fDistance = GetDistanceBetweenLocations(GetLocation(oWaypoint), GetLocation(oPC));
        location lWP1 = GetRandomLocation(oArea,oPC,fDistance/2);
        if (!GetIsPC(oPC))
         return;
          if(GetLocalInt(oArea,"Done") == 1)
          return;
        //so it does not spawn continously
         while (GetIsObjectValid(oWaypoint) && GetLocalInt(oArea, "Ran") < 5)
            {
            if (GetTag(oWaypoint)!="Spawn")
               oWaypoint = GetNextObjectInArea(oArea);
            else if (GetTag(oWaypoint)=="Spawn")
               {
                CreateObject(OBJECT_TYPE_CREATURE,"npcresref",GetLocation(oWaypoint));
                CreateObject(OBJECT_TYPE_CREATURE,"npcresref",GetLocation(oWaypoint));
                CreateObject(OBJECT_TYPE_CREATURE,"npcresref",GetLocation(oWaypoint));
                CreateObject(OBJECT_TYPE_CREATURE,"npcreref,GetLocation(oWaypoint));
               //should create 12 npc's in groups of 3 at a time.
                DestroyObject(oWaypoint, 2.0);
                SetLocalInt(oArea,"Ran", GetLocalInt(oArea,"Ran")+1);
                oWaypoint = GetNextObjectInArea(oArea);
               }
              object oWaypoint1 =  CreateObject(OBJECT_TYPE_WAYPOINT, "waypoint006", lWP1);
              //create a new random waypoint resref of the Spawn waypoint
             }

            SetLocalInt(oArea,"Done",1);
            DelayCommand (200.0, SetLocalInt(oArea, "Done", 0));
            DelayCommand (202.0, SetLocalInt(oArea, "Ran", 0));
           //resets the Ran and Done locals so the spawning mechanism will work again.
}
 Oh nd you have to set at least one Waypoint with the Tag Spawn down in the area.
This may not be the best or cleanest way to do this but it works so there you have it.
You cold also put down a bunch of waypoints with the tag Spawn and get rid of the creation of a new Spawn waypoint.  So each time the script is triggered the creatures would spawn to a new waypoint while destroying the old one.
               
               

               


                     Modifié par ffbj, 15 décembre 2010 - 02:35 .
                     
                  


            

Legacy_zero-feeling

  • Sr. Member
  • ****
  • Posts: 287
  • Karma: +0/-0
is it possible....
« Reply #2 on: December 15, 2010, 06:14:36 pm »


               well this script will come in really handy for another project i have, but not quite for the current one. i should probably explained a bit more what i need, something i tend to forget to do.

i'm basicly looking to teleport "Santa, 8 deer, and 3 elves" from location to location, different locations every time. this ramdom movement should happen after a player(s) leave the area the group is in. if this script will still work, i'm sure it would need a bit of modification, right?

my current layout has 6 WPs marked as "santa_group" dropped in 6 areas, and "santa", "elf", "deer_dasher", "deer_prancer", ect...  for the resrefs / tags of all the NPC's/animals.

would my current layout still work with this script, with a bit of modification? or would i need a whole new monster to deal with this?

thanks
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
is it possible....
« Reply #3 on: December 15, 2010, 11:12:10 pm »


               I think I get what you are trying to do and understand why the script I provided will not do that.

One thing is trying to teleport them, Santa and the Reindeer, to a new area would be difficult to do, since there is no function GetNextArea.  So not sure how to do that, though maybe someone else can help you with that.