Author Topic: On Exit Kill All NPC's In Area-Script  (Read 314 times)

Legacy_Guest_NWN Dragon-Blade_*

  • Jr. Member
  • **
  • Posts: 92
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« on: February 27, 2011, 05:57:29 pm »


               I'm not sure how to do this, I've been using lilacs script generator for most scripting but this I could not do with it.
i'm trying to kill all NPC's In the area on exit (to destroy some NPC's from a wild-life script from on enter) Or Maybe could It be done with the Specific spawns from the on enter like the cardinals or whatnot? I'll lsit their tags below...

MEDFOREST_VIPER
ZEP_BIRD_004
ZEP_BIRD_003
ZEP_GAZELLE
ZEP_SKUNK
ZEP_WEASEL
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« Reply #1 on: February 27, 2011, 06:35:57 pm »


               Do you want to "kill" them or simply destroy the objects? Also, I'm guessing that you only want this to happen if there are no other PCs in the area (in the case of a multiplayer game).

-420
               
               

               
            

Legacy_Guest_NWN Dragon-Blade_*

  • Jr. Member
  • **
  • Posts: 92
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« Reply #2 on: February 27, 2011, 06:45:27 pm »


               Yes, No PC's in area, Destroy would probablt be better since wouldnt want corpses or somthing please '<img'>
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« Reply #3 on: February 27, 2011, 06:59:38 pm »


               


//Goes in area's OnExit event

void main()

{

object oPC = GetExitingObject();

object oTarget;

string sTag;



//If the exiting object isn't a PC end script

if(!GetIsPC(oPC)) return;



//Check to make sure no PCs are in the area

oPC = GetFirstObjectInArea(OBJECT_SELF);

if(GetIsPC(oPC)) return;

else if(GetIsObjectValid(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC, oPC))) return;



//Area has no PCs clean up the NPCs

oTarget = GetFirstObjectInArea(OBJECT_SELF);

while(GetIsObjectValid(oTarget))

    {

    sTag = GetTag(oTarget);

    if(sTag == "MEDFOREST_VIPER" ||

       sTag == "ZEP_BIRD_004" ||

       sTag == "ZEP_BIRD_003" ||

       sTag == "ZEP_GAZELLE" ||

       sTag == "ZEP_SKUNK" ||

       sTag == "ZEP_WEASEL")

        {

        DestroyObject(oTarget, 1.0);//Delay destroy while in a loop

        }

    oTarget = GetNextObjectInArea(OBJECT_SELF);

    }

}


               
               

               
            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« Reply #4 on: February 27, 2011, 07:17:17 pm »


               I use this one, as it ignores tags and just destroys creatures.

void main()
{
   object oPC = GetNextObjectInArea();
   if(GetIsPC(oPC)==TRUE)return;
   object oExiting = GetExitingObject();
   if (GetIsPC(oExiting))
   {
   //SendMessageToPC(oExiting, "Area cleanup event fired.");
   object oObjectToClean = GetFirstObjectInArea(OBJECT_SELF);
   while (GetIsObjectValid(oObjectToClean))
       {
           if (
               !GetIsPC(oObjectToClean) &&
               !GetIsDM(oObjectToClean) &&
               !GetPlotFlag(oObjectToClean) &&
               GetObjectType(oObjectToClean) == OBJECT_TYPE_CREATURE
               )
                   {
                   //SendMessageToPC(oExiting, "Destroying " + GetName(oObjectToClean));
                   DestroyObject(oObjectToClean, 0.1);
                   }
           oObjectToClean = GetNextObjectInArea(OBJECT_SELF);
       }
    }
}


               
               

               


                     Modifié par Xovian, 27 février 2011 - 07:20 .
                     
                  


            

Legacy_Guest_NWN Dragon-Blade_*

  • Jr. Member
  • **
  • Posts: 92
  • Karma: +0/-0
On Exit Kill All NPC's In Area-Script
« Reply #5 on: February 27, 2011, 07:51:54 pm »


               Thankyou, To both of you '<img'>