Author Topic: Destroy Multiple Objects  (Read 388 times)

Legacy_Bubba McThudd

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +0/-0
Destroy Multiple Objects
« on: November 09, 2010, 06:37:59 pm »


                Greetings all,

I forget; how do you script the destruction of multiple objects bearing the same tag?
               
               

               
            

Legacy_420

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #1 on: November 09, 2010, 07:34:45 pm »


               From this thread:

Lightfoot8 wrote...



Uf you include nw_io_plot  you can use. GetNumItems

also in nw_io_plot is TakeNumItems for when you want to remove the items from the PC.




-420
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #2 on: November 09, 2010, 07:48:40 pm »


               I think a good question here is:



Where are the objects?



Are they items on a PC Or  NPC?  

Are they Objects in a container?

Are they objects in an area?  If so are they all in the same area?



I guess you could search the entire module and destroy them all. There are just better way to do it, If we have better information avout where they objects are at.  

               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #3 on: November 09, 2010, 07:51:04 pm »


               if you are talking about placeable objects then there are a couples ways to do this.

If you have these objects spead all over the module then you could use something like this(though it's not very efficient):

void main()
{
    object oObject = GetObjectByTag("Tag of object");
    while (GetIsObjectValid(oObject))
    {
        DestroyObject(oObject);
        oObject = GetObjectByTag("Tag of object");
    }
}


If all the placeable objects are in the same area you could do something like this(and it is more efficient):


void main()
{
    object oArea = GetObjectByTag("Tag of AREA");
    object oObject = GetFirstObjectInArea(oArea);
    while (GetIsObjectValid(oObject))
    {
        if (GetTag(oObject) == "Tag of OJBECT")
        DestroyObject(oObject);
        oObject = GetNextObjectInArea(oArea);
    }
}
               
               

               
            

Legacy_Bubba McThudd

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #4 on: November 09, 2010, 07:57:59 pm »


               I should have mentioned I'm trying to destroy placeables, not items.
               
               

               
            

Legacy_Bubba McThudd

  • Sr. Member
  • ****
  • Posts: 254
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #5 on: November 09, 2010, 08:47:58 pm »


               Thanks, that looks like what I need!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #6 on: November 09, 2010, 10:51:17 pm »


               Small bug on the first script.  Here is a fix.

void main()
{
    int i;
    object oObject = GetObjectByTag("Tag of object",i);
    while (GetIsObjectValid(oObject))
    {
        DestroyObject(oObject);
        i++;
        oObject = GetObjectByTag("Tag of object",i);
    }
}


 
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #7 on: November 09, 2010, 10:55:37 pm »


               Oooh. Didn't think you'd have to advance the nth parameter. Just figured it'd automatically grab the next object since the first was gone. Or would it still find the same destroyed object?

Thanks for the correction Lightfoot.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #8 on: November 09, 2010, 11:08:08 pm »


               Welcome



Objects are not destroyed untill after the script finishes running.  So the object is still there and valid untill the script ends and the delay expires.  Even with the defualt delay of  0.0 the script still needs to finish first.  



               
               

               
            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Destroy Multiple Objects
« Reply #9 on: November 12, 2010, 02:53:34 am »


               An addendum to what said by Lightfoot8.

Delayed calls with a delay _inferior_ to 0.1 will carry out in the exact order they are "met" in the script.
But as the delay increases, say to 0.1 and after, the order of execution shall be _inverted_. Watch out for it.
This applies to DestroyObject() as well.

DelayCommand (0.0f, SendMessageToPC (GetFirstPC (), "DBG: 1"));
DelayCommand (0.0f, SendMessageToPC (GetFirstPC (), "DBG: 2"));
DelayCommand (0.0f, SendMessageToPC (GetFirstPC (), "DBG: 3"));
DelayCommand (0.0f, SendMessageToPC (GetFirstPC (), "DBG: 4"));
DelayCommand (0.1f, SendMessageToPC (GetFirstPC (), "DBG: 11"));
DelayCommand (0.1f, SendMessageToPC (GetFirstPC (), "DBG: 22"));
DelayCommand (0.1f, SendMessageToPC (GetFirstPC (), "DBG: 33"));
DelayCommand (0.1f, SendMessageToPC (GetFirstPC (), "DBG: 44"));

The above instructions will produce the following output:
 DBG: 1
 DBG: 2
 DBG: 3
 DBG: 4
 DBG: 44
 DBG: 33
 DBG: 22
 DBG: 11



-fox
               
               

               


                     Modifié par the.gray.fox, 12 novembre 2010 - 02:55 .