Script with Destroy Object won't work [SOLVED]

I’ve been at this for hours now and I no longer know what to do so I’ll see if you can maybe help me.

I have a lever puzzle that works splendidly in an area apart from one detail. There is a fence consisting of 4 fence placeables that are supposed to be destroyed when the puzzle is finished, but the fence refuses to be destroyed. My guess is that there’s some mistake in my script. My script is quite convoluted (sorry about that), but I’ve written it like this so that I myself can follow what’s going on. Maybe some of you more experienced people out there can help me figure out what’s wrong.

#include "ginc_object"	
		
void PrepForDestruction(object oTarget)
{
	SetPlotFlag(oTarget,FALSE);
    SetImmortal(oTarget,FALSE);
    AssignCommand(oTarget,SetIsDestroyable(TRUE,FALSE,FALSE));
	
}
   
void main()
{

	  object oPC = GetFirstPC();
	  object oArea = (GetArea(oPC));

      object oBarrier = GetObjectByTag ("force_field_l1");
	  object oBarrier2 = GetObjectByTag ("force_field_l2");
     
      object oLever1 = GetObjectByTag ("l_lever1");
      object oLever2 = GetObjectByTag ("l_lever2");
      object oLever3 = GetObjectByTag ("l_lever3");
      object oLever4 = GetObjectByTag ("l_lever4");
	  object oLever5 = GetObjectByTag ("l_lever5");
	  
	  object oLight1 = GetObjectByTag ("1ge");
	  object oLight2 = GetObjectByTag ("2ge");
	  object oLight3 = GetObjectByTag ("3ge");
	  object oLight4 = GetObjectByTag ("4ge");
	  object oLight5 = GetObjectByTag ("5ge");
	  
	  object oGreenlight5 = GetObjectByTag ("1ge5");
	  object oGreenlight4 = GetObjectByTag ("1ge4");
	  object oGreenlight3 = GetObjectByTag ("1ge3");
	  object oGreenlight2 = GetObjectByTag ("1ge2");
	  object oGreenlight1 = GetObjectByTag ("1ge1");
	  
	  
	  
      
      int Lever1;
      int Lever2;
      int Lever3;
      int Lever4;
	  int Lever5;
     
      if ( GetLocalInt( OBJECT_SELF, "m_bActivated" ) != TRUE )
      {
        //Activate the Lever and Mark the Lever as Activated.
        SetLocalInt( OBJECT_SELF, "m_bActivated", TRUE );
        PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE );
      }
      else
      {
       //Deactivate the Lever and Mark the Lever as Deactivated.
        SetLocalInt( OBJECT_SELF, "m_bActivated", FALSE );
        PlayAnimation( ANIMATION_PLACEABLE_DEACTIVATE );
      }
    // Get the status of the other levers.
      Lever1 = GetLocalInt (oLever1,"m_bActivated");
      Lever2 = GetLocalInt (oLever2,"m_bActivated");
      Lever3 = GetLocalInt (oLever3,"m_bActivated");
      Lever4 = GetLocalInt (oLever4,"m_bActivated");
	  Lever5 = GetLocalInt (oLever5,"m_bActivated");
     
	  int OpenBarrier = GetLocalInt(oBarrier,"opendoor");
      
	  
      if (Lever1 == TRUE && Lever2 == FALSE && Lever3 == FALSE && Lever4 == FALSE && Lever5 == FALSE )
      {
       SetLocalInt(oBarrier, "opendoor", 1);
	   PrepForDestruction(oLight1);
	   DestroyObject(oLight1);
	   object oGreenlight1 = SpawnObjectAtWP(1024,"1ge1", "1g");
	   return;
      }
	 
	  
	  else if (OpenBarrier == 1)
	  {
		  if (Lever1 == TRUE && Lever2 == FALSE && Lever3 == FALSE && Lever4 == FALSE && Lever5 == TRUE )
			  {
				SetLocalInt(oBarrier, "opendoor", 2);
				PrepForDestruction(oLight5);
				DestroyObject(oLight5);
				object oGreenlight5 = SpawnObjectAtWP(1024,"1ge5", "5g");
			  }
		  else
			  {
				SetLocalInt(oBarrier, "opendoor", 0);
				PrepForDestruction(oGreenlight1);
	   			DestroyObject(oGreenlight1);
				object oLight1 = SpawnObjectAtWP(1024,"1ge", "1g");
			  }
	  }	
			  
	  else if (OpenBarrier == 2)
	  {
		  if (Lever1 == TRUE && Lever2 == FALSE && Lever3 == FALSE && Lever4 == TRUE && Lever5 == TRUE)
			  {
				SetLocalInt(oBarrier, "opendoor", 3);
				PrepForDestruction(oLight4);
				DestroyObject(oLight4);
				object oGreenlight4 = SpawnObjectAtWP(1024,"1ge4", "4g");
			  }
		  else
			  {
			  	
				SetLocalInt(oBarrier, "opendoor", 0);
				PrepForDestruction(oGreenlight1);
	   			DestroyObject(oGreenlight1);
				object oLight1 = SpawnObjectAtWP(1024,"1ge", "1g");
				PrepForDestruction(oGreenlight5);
				
				DestroyObject(oGreenlight5);
				
				object oLight5 = SpawnObjectAtWP(1024,"5ge", "5g");
			  }	  
			  
	  }		  
	  
	  else if (OpenBarrier == 3)
	  {
		  if (Lever1 == TRUE && Lever2 == TRUE && Lever3 == FALSE && Lever4 == TRUE && Lever5 == TRUE)
			  {
				
		 		SetLocalInt(oBarrier, "opendoor", 4);
				PrepForDestruction(oLight2);
				DestroyObject(oLight2);
				object oGreenlight2 = SpawnObjectAtWP(1024,"1ge2", "2g");
				
			  }
		  else
			  {
				SetLocalInt(oBarrier, "opendoor", 0);
				PrepForDestruction(oGreenlight1);
	   			DestroyObject(oGreenlight1);
				object oLight1 = SpawnObjectAtWP(1024,"1ge", "1g");
				PrepForDestruction(oGreenlight5);
				PrepForDestruction(oGreenlight4);
				DestroyObject(oGreenlight5);
				DestroyObject(oGreenlight4);
				object oLight5 = SpawnObjectAtWP(1024,"5ge", "5g");
				object oLight4 = SpawnObjectAtWP(1024,"4ge", "4g");
				
			  }	 
	  } 
	  
	  else if (OpenBarrier == 4)
	  {
		  if (Lever1 == TRUE && Lever2 == TRUE && Lever3 == TRUE && Lever4 == TRUE && Lever5 == TRUE)
			  {
				
		 		SetLocalInt(oBarrier, "opendoor", 5);
				
				
				PrepForDestruction(oLight3);
				DestroyObject(oLight3);
				object oGreenlight3 = SpawnObjectAtWP(1024,"1ge3", "3g");
				PrepForDestruction(oBarrier);
				DestroyObject(oBarrier);
				PrepForDestruction(oBarrier2);
				DestroyObject(oBarrier2);
				
				
				object oFence1 = GetObjectByTag ("l_fence1");
	  			AssignCommand(oFence1,SetIsDestroyable(TRUE,FALSE,FALSE));
	  			object oFence2 = GetObjectByTag ("l_fence2");
	  			AssignCommand(oFence2,SetIsDestroyable(TRUE,FALSE,FALSE));
	  			object oFence3 = GetObjectByTag ("l3fence");
	  			AssignCommand(oFence3,SetIsDestroyable(TRUE,FALSE,FALSE));
	  			object oFence4 = GetObjectByTag ("l4fence");
	  			AssignCommand(oFence4,SetIsDestroyable(TRUE,FALSE,FALSE));
				
				DestroyObject(oFence1);
				DestroyObject(oFence2);
				DestroyObject(oFence3);
				DestroyObject(oFence4);
				
				
				MusicBackgroundChangeDay(oArea,169);
				MusicBackgroundChangeNight(oArea,169);
				
			  }
		  else
			  {
				SetLocalInt(oBarrier, "opendoor", 0);
				PrepForDestruction(oGreenlight1);
	   			DestroyObject(oGreenlight1);
				object oLight1 = SpawnObjectAtWP(1024,"1ge", "1g");
				PrepForDestruction(oGreenlight5);
				PrepForDestruction(oGreenlight4);
				PrepForDestruction(oGreenlight2);
				DestroyObject(oGreenlight5);
				DestroyObject(oGreenlight4);
				DestroyObject(oGreenlight2);
				
				object oLight5 = SpawnObjectAtWP(1024,"5ge", "5g");
				object oLight4 = SpawnObjectAtWP(1024,"4ge", "4g");
				object oLight2 = SpawnObjectAtWP(1024,"2ge", "2g");
				
			  }	 
	  } 
			  
	  	  
} 

(And what is f*%#%g annoying is that these forums refuse to display the script exactly like it is in the toolset when I copy it here, with lines not going parallell to each other, ok, I’m sorry, but I’m so pissed off right now. It’s late and I need to go to sleep…)

1 Like

copy your script to a text editor and do “Tabs to spaces (4)” – then paste it as code to the forum (it helps to avoid tabs imo)

to the point … are your fences environmental objects …? static …?

1 Like

The fences are placeables. They are copied from the blueprints from where they are called Fence {Wood} with appearance RuralWFence. Static is set to True and Interuptable to True.

Ok, what I am actually trying to do in this script (maybe there’s another way to do it) is that I have a barrier that the PC needs to go through by pulling levers. Then the barrier disappear when the PC solves the puzzle and the PC can move on through. The problem is that I’m using two placed effects with the Special Effect fx_energy_field_1, and the PC can move through that. So I put up these fences that I moved down into the floor, so that they are practically invisible (did this in my last module and it worked like a charm there), thus making the PC not being able to move through the placed effect. But then I have to destroy the fence for the PC to be able to move on. At first I thought it was some kind of walkmesh problem, but then when I tested with moving the fences up so I could see them, and I saw that they were never destroyed in the first place when they were supposed to be. The placed effects (and everything else that is supposed to) get destroyed. So I don’t know what’s wrong.

1 Like

try false …

2 Likes

Think I tried that but…ok, gonna check again.

Now that was weird. When setting static to True, now two of the fences disappeard. And then when looking at the script I see that the first two had the wrong tag all along. How did that happen? I mean, I went over this script a dosen times yesterday checking everything.

Ok, changed the tag of the two first fences, and now they all disappeared. Will try and sink them into the ground and see if it still works. But this really baffles me…I mean, I genuinely believe I tried with setting Static to False yesterday… :crazy_face: :confounded: :tired_face:

Ok, now this is interesting. Turns out that when setting Static to False the fences gets destroyed but when having that you can also move through the fences, so that doesn’t work. Tried changing back to True and then you can’t walk trough but they won’t get destroyed either.

I think I actually solved it! I set Dynamic Collisions to True and then it seemed to work. Will test again.

Is the fence set to Usable?
I have a script that destroys the “Axe resting on a log” object, in order to recover the axe. I had the same problem. But when set to useable everything was ok for me afterwards. Exact tag is sensible info, but you already know this.

Have a nice. I know the ToolSet can be overwhelming at times. :neutral_face:

1 Like

Thanks for all the help! Yes, the ToolSet can be extremely annoying at times. The fences aren’t usable. If they were that then the PC could click on them and that would destroy the whole illusion that there’s nothing there. It’s weird that Static set to True prevents the Destroy Object function. Thankfully the Dynamic Collisions solved this for me.

2 Likes

Good to hear. :slightly_smiling_face: