Aller au contenu

Photo

Destroy Multiple Objects


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
Bubba McThudd

Bubba McThudd
  • Members
  • 147 messages
 Greetings all,

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

#2
420

420
  • Members
  • 190 messages
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

#3
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.


#4
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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);
    }
}

#5
Bubba McThudd

Bubba McThudd
  • Members
  • 147 messages
I should have mentioned I'm trying to destroy placeables, not items.

#6
Bubba McThudd

Bubba McThudd
  • Members
  • 147 messages
Thanks, that looks like what I need!

#7
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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);
    }
}


 

#8
GhostOfGod

GhostOfGod
  • Members
  • 863 messages
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.

#9
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
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.




#10
the.gray.fox

the.gray.fox
  • Members
  • 127 messages
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 .