Author Topic: Unspawn NPC?  (Read 221 times)

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Unspawn NPC?
« on: October 08, 2010, 09:12:50 pm »


               I found a nice script in old forums axe murderer made to spawn npc's onenter.
I think this will help reduce lag ?
I was wondering ...how do I despawn the npc if noone is in the area ..I dont think the clean up script will sense that is for encounters.'Posted
               
               

               
            

Legacy_Mudeye

  • Full Member
  • ***
  • Posts: 238
  • Karma: +0/-0
Unspawn NPC?
« Reply #1 on: October 08, 2010, 10:26:35 pm »


               If you have kept track of the objects (NPCs) you want to get rid of then you can make a script for the   OnExit event of the area that cleans them up.

When the PC leaves the area the OnExit event fires it would be something like this for an npc tagget "npctag":

void main()
{
   object pc = GetExitingObject();
   if( GetIsPC( pc ) )
   {
      object npc = GetObjectByTag("npctag");
      if( npc != OBJECT_INVALID ) DestroyObject(npc);
   }
}
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Unspawn NPC?
« Reply #2 on: October 08, 2010, 10:35:00 pm »


               You need two while loops to destroy all the npc's if it's a multiplayer campaign.  The above script will only destroy one npc.



The first while loop would check if there are any pc's in the area, using get firstpc and the get next pc, then return the script if there is still a pc in the area.  If no pc's in the area then start the second while loop destroying the npc's one by one as long as there is one remaining.
               
               

               
            

Legacy_Knight_Shield

  • Hero Member
  • *****
  • Posts: 812
  • Karma: +0/-0
Unspawn NPC?
« Reply #3 on: October 08, 2010, 10:50:48 pm »


               'Posted
               
               

               


                     Modifié par Knight_Shield, 08 octobre 2010 - 09:52 .