Author Topic: How to destroy an object?  (Read 343 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
How to destroy an object?
« on: September 17, 2012, 02:07:36 am »


               Easy title, more difficult than I thought!

An NPC is spawned in using the below script:

void main()
{
SetIsDestroyable(FALSE, FALSE, FALSE);
ActionDoCommand(ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDeath(),OBJECT_SELF));
}


Works and is quite straight forward.

I'm unable to destroy the NPC in question using the following OnExit script:

void main()
{

object oPC = GetExitingObject();

object oNPC1=GetObjectByTag("AR510B2A_NPC1");

if (!GetIsPC(oPC)) return;

DestroyObject(oNPC1);

}


The TAG is correct.

I'd like to make sure that the script that kills the NPC keeps the NPC from fading BUT, I want to be able to remove the NPC from the area once the player has exited that area.

If I make it:

SetIsDestroyable(TRUE, FALSE, FALSE);


the NPC fades as a corpse normally would and doesn't stick around.

If I leave it:

SetIsDestroyable(FALSE, FALSE, FALSE);


the NPC remains but if the player exits and returns to the same area, there are now TWO NPCs that are in the area, one above the other. Rinse repeat for each time one returns to the area. NPCs are destroyed OnExit and respawned OnEnter.

Thoughts?

FP!
               
               

               


                     Modifié par Fester Pot, 17 septembre 2012 - 01:10 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to destroy an object?
« Reply #1 on: September 17, 2012, 02:44:34 am »


               You have to set the NPC as destroyable.

Try.

void main()
{

object oPC = GetExitingObject();

object oNPC1=GetObjectByTag("AR510B2A_NPC1");

if (!GetIsPC(oPC)) return;

SetIsDestroyable(TRUE);
DestroyObject(oNPC1);

}


EDIT: oops Will have to assign it.   So. 

void KillKillKill()
{    
  SetIsDestroyable(TRUE);
  DestroyObject(oOBJECT_SELF);
}

void main()
{

object oPC = GetExitingObject();

object oNPC1=GetObjectByTag("AR510B2A_NPC1");

if (!GetIsPC(oPC)) return;

AssignCommand (oNPC1, KillKillKill());  

               
               

               


                     Modifié par Lightfoot8, 17 septembre 2012 - 01:50 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
How to destroy an object?
« Reply #2 on: September 17, 2012, 02:49:37 am »


               Hrm, alright. But SetIsDestroyable will destroy the status of the caller, which is the OnExit script. Must I use an AssignCommand(oNPC1, SetIsDestroyable(TRUE));?

I'll give it a shot and report.

EDIT: Had to use the AssignCommand.

Thanks for the helping hand!

FP!
               
               

               


                     Modifié par Fester Pot, 17 septembre 2012 - 01:52 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
How to destroy an object?
« Reply #3 on: September 17, 2012, 02:51:38 am »


               Yea,  I caught my mistake and edited the above post.