lift door block

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

lift door block

Post by fuhrer »

ive set up a trigger in a lift that if someone blocks the doors the doors open again,

however if u call the lift to another then block the doors the triggers arent triggerable anymore n nothing works, i cant figure out why

ill post the entire script

Code: Select all

level waittill prespawn

exec global/DMprecache.scr
exec global/ambient.scr lift
level.script = "maps/dm/lift.scr" 

	$inner_trigger_1 bind $lift
	$inner_trigger_2 bind $lift
	$inner_trigger_3 bind $lift
	$inner_trigger_4 bind $lift
	$inner_door bind $lift
	$inner_door_open bind $lift
	$inner_door_closed bind $lift
				
	
	$doors_1 time 2
	$doors_2 time 2
	$doors_3 time 2
	$doors_4 time 2
	$inner_door time 2

	
	$lift_up hide
	$lift_down hide
	
	level.doorsmoving = 0
	level.doorblocked = 0
	level.doorpos = 0
	level.pos = 1	

	$lift speed 116	// sets the lifts speed (Units Per Second)
	thread indicator_mover
		

level waittill spawn

end

//------//
// Lift //
//------//

	
call: 
	
//--------------//
// Triggers Off //
//--------------//

	
	if ((level.doorblocked == 0) || (level.doorsmoving == 0))
	{
	$inner_trigger_1 nottriggerable		// turns off the triggers
	$inner_trigger_2 nottriggerable
	$inner_trigger_3 nottriggerable
	$inner_trigger_4 nottriggerable
	$outer_triggers nottriggerable

//---------------//
// Moves Buttons //
//---------------//

	$call_buttons playsound click
	$call_buttons moveNorth 1		// moves buttons
	$call_buttons move
	wait .2
	$call_buttons moveSouth 1
	$call_buttons move

//-------------//
// Close Doors //	
//-------------//

	if (level.doorpos == 1)
	{
	if (level.pos == self.floor)
	{
	}
	else
	{
	$("doors_" + level.pos) doclose
	level.doorsclosing = 1
	if (level.doorsmoving != 1) // SOUND FIX!
	{
	$("doors_" + level.pos) playsound lift_gate 
	}
	level.doorsmoving = 1
	$inner_door moveEast (vector_length ($inner_door.origin - $inner_door_closed.origin))
	$inner_door waitmove
	level.doorpos = 0
	level.doorsmoving = 0
	level.doorsclosing = 0
	}
	}
	}

//---------------------//
// Up and Down display //
//---------------------//
	
	if(self.floor > level.pos)	// if called floor is higher than current lift position
	{
	$lift_up show
	level.posa = 1
	}

	if(self.floor < level.pos)	
	{
	$lift_down show
	level.posa = 0
	}
	
//------------//
// Moves Lift //
//------------//

	if (level.doorpos == 0)
	{
	$lift moveto $("floor_" + self.floor)
	$lift loopsound lift_sound
	$lift waitmove				// moves the lift to that destination
	$lift loopsound lift_sound wait
	level.pos = self.floor

//------------//
// Open Doors //
//------------//

	$("doors_" + self.floor) doopen
	if (level.doorsmoving != 1)
	{
	$("doors_" + self.floor) playsound lift_gate
	}
	level.doorsmoving = 1
	$inner_door moveWest (vector_length ($inner_door.origin - $inner_door_open.origin))
	$inner_door waitmove
	level.doorpos = 1
	level.doorsmoving = 0
	}
	
//--------------------------//
// Up and Down display Hide //	
//--------------------------//

	if(level.posa == 1)		// if up button is showing, hide it
	{
	$lift_up hide
	}

	if(level.posa == 0)
	{
	$lift_down hide
	}
		
//-------------//
// Triggers on //
//-------------//
	
	$inner_trigger_1 triggerable		// turns triggers on
	$inner_trigger_2 triggerable		
	$inner_trigger_3 triggerable		
	$inner_trigger_4 triggerable		
	$outer_triggers triggerable

//--------------------------------//
// Close Doors if lift not in use //
//--------------------------------//

	if ((local.waittime == 0) || (local.waittime == NIL))
	{
	local.waittime = 3

	while ((level.doorpos == 1) && (level.doorsmoving == 0))
	{
	if (local.waittime > 0)
	{
	local.waittime --
	if (level.doorblocked == 1)
	{
	local.waittime = 3
	}
	wait 1
	}
	else
	{
	$("doors_" + self.floor) doclose
	level.doorsclosing = 1
	if (level.doorsmoving != 1)
	{
	$("doors_" + self.floor) playsound lift_gate 	
	}
	level.doorsmoving = 1
	$inner_door moveEast (vector_length ($inner_door.origin - $inner_door_closed.origin))
	$inner_door waitmove
	level.doorpos = 0
	level.doorsmoving = 0
	level.doorsclosing = 0
	local.waittime = 3
	end
	}
	}
	}
	
end

//---------------//
// Door Blocked? //
//---------------//

door_blocked:

	local.player = parm.other
	if (level.doorsclosing == 1)
	{
	$("doors_" + level.pos) doopen
	if (level.doorsmoving != 1)
	{
	$("doors_" + self.floor) playsound lift_gate 	
	}
	level.doorsmoving = 1
	$inner_door moveWest (vector_length ($inner_door.origin - $inner_door_closed.origin))
	$inner_door waitmove
	level.doorpos = 0
	level.doorsmoving = 0
	}
	while (local.player istouching $door_block)
	{
	level.doorblocked = 1
	wait .01
	}
	level.doorblocked = 0
end

//------------------------------//
// Shows which floor lift is on //
//------------------------------//

indicator_mover: 

while (1)
{
	if((vector_length ($lift.origin - $floor_1.origin)) < 5)
	{
	$pos_1 show
	$pos_2 hide
	$pos_3 hide
	$pos_4 hide
	}

	if((vector_length ($lift.origin - $floor_2.origin)) < 5)
	{
	$pos_2 show
	$pos_1 hide
	$pos_3 hide
	$pos_4 hide
	}
	
	if((vector_length ($lift.origin - $floor_3.origin)) < 5)
	{
	$pos_3 show
	$pos_1 hide
	$pos_2 hide
	$pos_4 hide
	}
	
	if((vector_length ($lift.origin - $floor_4.origin)) < 5)
	{
	$pos_4 show
	$pos_1 hide
	$pos_2 hide
	$pos_3 hide
	}
wait .01
}

end
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

bind

Post by tltrude »

Bind "$door_block" to something, or it will get left behind.
Tom Trude,

Image
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

$door_block spans the entire height of the lift shaft, only between the doors ofcourse
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

iprintln

Post by tltrude »

Well, it is hard to tell what it is doing. You need a few "iprintln" in there to see what the variable values are.

iprintln "Door Blocked = " (level.doorblocked)
Tom Trude,

Image
Bjarne BZR
Site Admin
Posts: 3298
Joined: Wed Feb 05, 2003 2:04 pm
Location: Sweden
Contact:

Post by Bjarne BZR »

That code feels like a spagetti monster :shock: :wink:
That is, the call method is very hard to understand, because it does so many things. Also I'm not sure you really know what it does, because after I matched up all the {'s and }'s, there was this pice left at the end of the call method:

Code: Select all

call:   
   //--------------//
   // Triggers Off //
   //--------------//

   if ((level.doorblocked == 0) || (level.doorsmoving == 0))
   {
      $inner_trigger_1 nottriggerable // turns off the triggers
      $inner_trigger_2 nottriggerable
      $inner_trigger_3 nottriggerable
      $inner_trigger_4 nottriggerable
      $outer_triggers nottriggerable

      //---------------//
      // Moves Buttons //
      //---------------//

      $call_buttons playsound click
      $call_buttons moveNorth 1 // moves buttons
      $call_buttons move
      wait .2
      $call_buttons moveSouth 1
      $call_buttons move

      //-------------//
      // Close Doors //   
      //-------------//

      if (level.doorpos == 1)
      {
         if (level.pos == self.floor)
         {
         }
         else
         {
            $("doors_" + level.pos) doclose
            level.doorsclosing = 1
            if (level.doorsmoving != 1) // SOUND FIX!
            {
               $("doors_" + level.pos) playsound lift_gate
            }
            level.doorsmoving = 1
            $inner_door moveEast (vector_length ($inner_door.origin - $inner_door_closed.origin))
            $inner_door waitmove
            level.doorpos = 0
            level.doorsmoving = 0
            level.doorsclosing = 0
         }
      }
   }

   //---------------------//
   // Up and Down display //
   //---------------------//
   
   if(self.floor > level.pos) // if called floor is higher than current lift position
   {
      $lift_up show
      level.posa = 1
   }

   if(self.floor < level.pos)   
   {
      $lift_down show
      level.posa = 0
   }
   
   //------------//
   // Moves Lift //
   //------------//

   if (level.doorpos == 0)
   {
      $lift moveto $("floor_" + self.floor)
      $lift loopsound lift_sound
      $lift waitmove // moves the lift to that destination
      $lift loopsound lift_sound wait
      level.pos = self.floor

      //------------//
      // Open Doors //
      //------------//

      $("doors_" + self.floor) doopen
      if (level.doorsmoving != 1)
      {
         $("doors_" + self.floor) playsound lift_gate
      }
      level.doorsmoving = 1
      $inner_door moveWest (vector_length ($inner_door.origin - $inner_door_open.origin))
      $inner_door waitmove
      level.doorpos = 1
      level.doorsmoving = 0
   }
   
   //--------------------------//
   // Up and Down display Hide //   
   //--------------------------//

   if(level.posa == 1) // if up button is showing, hide it
   {
      $lift_up hide
   }

   if(level.posa == 0)
   {
      $lift_down hide
   }
      
   //-------------//
   // Triggers on //
   //-------------//
   
   $inner_trigger_1 triggerable // turns triggers on
   $inner_trigger_2 triggerable      
   $inner_trigger_3 triggerable      
   $inner_trigger_4 triggerable      
   $outer_triggers triggerable

   //--------------------------------//
   // Close Doors if lift not in use //
   //--------------------------------//

   if ((local.waittime == 0) || (local.waittime == NIL))
   {
      local.waittime = 3
      while ((level.doorpos == 1) && (level.doorsmoving == 0))
      {
      if (local.waittime > 0)
      {
         local.waittime --
      if (level.doorblocked == 1)
      {
         local.waittime = 3
      }
      wait 1
   }
   else
   {
      $("doors_" + self.floor) doclose
      level.doorsclosing = 1
      if (level.doorsmoving != 1)
      {
         $("doors_" + self.floor) playsound lift_gate    
      }
      level.doorsmoving = 1
      $inner_door moveEast (vector_length ($inner_door.origin - $inner_door_closed.origin))
      $inner_door waitmove
      level.doorpos = 0
      level.doorsmoving = 0
      level.doorsclosing = 0
      local.waittime = 3
      end
   }
}
}
end
So take a long hard look at it again, is the if / else blocks really as you ment them to be?

I suggest dividing that method up into smaller ones, easier to understand, mess prone to errors and WAY easier to show to other people :)

My guess for the reason for your error is that you think the if ((level.doorblocked == 0) || (level.doorsmoving == 0)) block spans the entire call method, but in fact it ends just above the

Code: Select all

//---------------------//
// Up and Down display //
//---------------------//
comment.
Admin .MAP Forums
Image
Head above heels.
fuhrer
Captain
Posts: 253
Joined: Sun Mar 14, 2004 3:36 am

Post by fuhrer »

ok, :) i know its a little messy (little? lol) but i think i know whats causing it

Code: Select all

$inner_door moveEast (vector_length ($inner_door.origin - $inner_door_closed.origin))


	$inner_door waitmove


	level.doorpos = 0
	level.doorsmoving = 0
	level.doorsclosing = 0
the waitmove on that object, if u set the call thread running, it gets to that line and waits for the door to close before continuing correct?

so if u then trigger the blocked thread while its waiting...

it wont ever get to where its waiting to get to, so the call thread is stuck on that waitmove line.

i need some other way of determining when the doors have stopped moving so i can still use

Code: Select all

 level.doorpos = 0
	level.doorsmoving = 0
	level.doorsclosing = 0
and change the waitmove to move.
Post Reply