Jump to content

Home

Destroy object script syntax problem


kdsphantom

Recommended Posts

Hello all and this is for TSL-KOTOR 2

I'm trying to use DestroyObject in a script to destroy a certain type of creature. I checked NWN lexicon, did a search here. I think I just have the wrong syntax and just cant figure out the right syntax. I would be so appreciative of any help

 

the script I have it in and syntax I thought might be ok is

void main() 
{ 
CreateObject( OBJECT_TYPE_CREATURE, "c_drdprot", Location(Vector(9.727780,49.268573,0.00), 0.0));
//DestroyObject( OBJECT_TYPE_CREATURE, "n_forcezomb98")
DestroyObject(GetObjectByTag("n_forcezomb98"), 0.0);
}

as you can see I was trying different syntax's, If i ned a loc im not sure as the creatures are in a fight with you, This script is set to run on the death of the Boss mob. To clear out all his minions.

Thank you

kdsphantom

Link to comment
Share on other sites

The first thing to verify is if n_forcezomb98 is really the tag of your object and not the resref as they are not necessarily the same. When you see GetObjectByTag you have to put the tag :D

 

Also, if I understand correctly, you are trying to destroy more than one npc with the same tag. Right now your script will destroy only one object. If you want it to destroy all the objects with the same tag in an area, you have to use something like this:

  void main ()
{
object oTarget = GetFirstObjectInArea(GetArea(OBJECT_SELF), OBJECT_TYPE_CREATURE);
while(GetIsObjectValid(oTarget))
       {
if(GetTag(oTarget) == "n_forcezomb98")
            {  
       DestroyObject(oTarget);
           }
oTarget = GetNextObjectInArea(GetArea(OBJECT_SELF), OBJECT_TYPE_CREATURE);
       }
CreateObject( OBJECT_TYPE_CREATURE, "c_drdprot", Location(Vector(9.727780,49.268573,0.00), 0.0));
}

 

Edited to correct a few typos.

Link to comment
Share on other sites

Hello Darth333 :)

I totally agree that I get confused still on TAG meaning resref, stoffe said I did that before =/

 

If i want to find the TAG then of a creature I have created would I open( and if I was using KT) open the GFF editor, looking in its basic profile and there is a TAG box there, and I can edit that box, so I use whats in that box as my TAG ? Doing just that, I found the tag to be ForceGhoul so in the script I just replace that for the resref.(?)

 

But that is such a nice script you made, and yes I am trying to destroy many of these creatures with the ResRef n_forcezomb98, I hope Tag ForceGhoul.

thank you for your time and patience :)

kdsphantom

Link to comment
Share on other sites

Hiya )

your a script angel genius :)

I just plugged that in and it worked! I mean it REALLY worked, ohh that is sooo cool ) thatnk you so much, I think well I hope that will make this one end fight well 2 end fights work out soo well, I was really worried I wouldnt be able to script that or make it work out right.

But ohh thank you so much )

kdsphantom

Link to comment
Share on other sites

If you want it to destroy all the objects with the same tag in an area, you have to use something like this:

(snip)

object oTarget = GetFirstObjectInArea(GetArea(OBJECT_SELF), OBJECT_TYPE_CREATURE);

(snip)

 

While the above method works just fine, I think it's a little bit more efficient to use GetObjectByTag() when you are just after objects with one particular tag. Like:

 

void main() {
   int nIdx = 0;
   object oTarget = GetObjectByTag("n_forcezomb98");

   while (GetIsObjectValid(oTarget)) {
       DestroyObject(oTarget);
       oTarget = GetObjectByTag("n_forcezomb98", ++nIdx);
   }
   CreateObject( OBJECT_TYPE_CREATURE, "c_drdprot", Location(Vector(9.727780,49.268573,0.00), 0.0));
}

 

But that's just nitpicking, never mind me. :)

Link to comment
Share on other sites

Hiya Stoffe

I love your nitpicking, so I will always mind you.

and to see if I understand this right, when you did this int nIdx = 0;

you basically made X and and made X equal 0 and then used when we destroyed an object X = X + 1 to move on? am I understanding that right? but even If i dont quite "get it" I do understand at least the script that is, it is destroying my zombies perfectly.

 

While darth333 uses a Getarea command and couples that with the IF and to search for them. Both work but from different pov's ?

 

But thank you again Stoffe and Darth333

and shameless plug coming last night the 20th I finished the mod you all been helping me with, that this script went into, I posted it in the other forum. heh you 2 should check it out since you two have put so much work into it heh. I am sure you will see your scripts at work :)

kdsphantom

Link to comment
Share on other sites

Hiya Stoffe

I love your nitpicking, so I will always mind you.

and to see if I understand this right, when you did this int nIdx = 0;

you basically made X and and made X equal 0 and then used when we destroyed an object X = X + 1 to move on? am I understanding that right? but even If i dont quite "get it" I do understand at least the script that is, it is destroying my zombies perfectly.

 

What the script is doing is incrementing through the total number of zombies in the area. It starts at zombie number "0" and then goes to zombie #1 and so on until all of the zombies are gone.

Link to comment
Share on other sites

hiya Darkkender

and thank you buddy )

this past week working on scripts so much i was trying my hardest to do just this or jsut that, heh shows my age but I started programming in basic heh 20+ some years ago. And the more I can break there script lang down into those terms the more i can understand and make the script do what I want.

 

If i was 13 again Id prolly have this worked out over a weekend, but woudlnt be able to visit the nudie sites =/ so guess ya gotta take the good with the bad heh but thank you and if ya wanna see how that script got used (shameless plug number 8) is to check it out)

kdsphantom

Link to comment
Share on other sites

What the script is doing is incrementing through the total number of zombies in the area. It starts at zombie number "0" and then goes to zombie #1 and so on until all of the zombies are gone.

 

 

It's a well preciced while loop. "For" loops and "while" loops can get very dangerous if not conditioned right. Good job...

Link to comment
Share on other sites

It's a well preciced while loop. "For" loops and "while" loops can get very dangerous if not conditioned right. Good job...

 

Boy don't I know it. There are reasons why I took shortcuts for the v1.0 of NSSEditor. Mostly due to my own hair pulling caused by my loops.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...