//Elevator tutorial
//Architecture:Erick 
//Scripting:Erick

//----NOTE TO PEOPLE WHO WANT THIS FOR MULTIPLAYER-------------------
//Where it says "$player" in the script replace this with "local.player" and add "local.player = parm.other" in the line above this


main:
	
	
level waittill prespawn
	
	

	$down_switch bind $elevator_cab //<---bind the switches to the elevator so it doesnt look weird
	$up_switch bind $elevator_cab
	$down_trigger bind $down_switch //<--bind triggers to the switches
	$up_trigger bind $up_switch
		$elevator_cab movedown 8
		$elevator_cab time 0     //---I had it moved up for lighting
		$elevator_cab move
$elevator_cab speed 64 //sets the speed to 64 units per second
level.elepos = 1 //starts on floor 1
level.liftavator = 1 //this is the world units in height
$elevator_cab2 speed 64

level waittill spawn

thread elevator_prep
thread liftavator_prep

iprintln_noloc "testing!!!"

end

elevator_prep:
thread movedown
thread moveup
end

movedown:
$down_trigger waittill trigger

iprintlnbold_noloc "Down trigger has been used!" 

if (level.elepos == 1) //if the elevator is on floor 1 then end because it cant go down anymore
end

$up_trigger nottriggerable
$down_trigger nottriggerable

local.position = level.elepos
	$down_switch anim turn
	
	$elevator_cab loopsound lighthouse_run
		$elevator_cab moveto $("floor" + (local.position - 1))
		$elevator_cab waitmove
	$elevator_cab stoploopsound
	
	$down_switch anim idle
		level.elepos--
			$down_trigger triggerable
			$up_trigger triggerable
	iprintlnbold_noloc "level.elepos = " (level.elepos) 
goto elevator_prep

end

moveup:
$up_trigger waittill trigger

iprintlnbold_noloc "Up trigger has been used!" 

if (level.elepos == 5)
end

$down_trigger nottriggerable
$up_trigger nottriggerable
	local.position = level.elepos

	$up_switch anim turn
	
	$elevator_cab loopsound lighthouse_run
		$elevator_cab moveto $("floor" + (local.position + 1))
		$elevator_cab waitmove
	$elevator_cab stoploopsound
	
	$up_switch anim idle
		level.elepos++
			$up_trigger triggerable
			$down_trigger triggerable
	iprintlnbold_noloc "level.elepos = " (level.elepos) 
goto elevator_prep

end

//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
liftavator_prep:
	$up_trigger2 triggerable
	$down_trigger2 triggerable
	$elevator_cab2 stoploopsound
		$up_switch2 anim idle
		$down_switch2 anim idle
			$elevator_cab2 bind $elev_liftup
			$piece1 bind $elevator_cab2
			$piece2 bind $elevator_cab2
			$up_switch2 bind $piece2
			$down_switch2 bind $piece1
			$up_trigger2 bind $up_switch2
			$down_trigger2 bind $down_switch2
thread up 
thread down

end

up:

$up_trigger2 waittill trigger

if (level.liftavator == 832)
{
	goto liftavator_prep
}
	$down_trigger2 nottriggerable //turn it off for no conflict
		$up_switch2 anim move	
while ($player.useheld) //when the player is holding the use key do this
{
	if (level.liftavator == 832)
	{
	goto liftavator_prep
	}
$elevator_cab2 loopsound lighthouse_run
$elev_liftup moveup 1
$elev_liftup waitmove
level.liftavator++

iprintln_noloc "level.liftavator = " (level.liftavator)
}
	$elevator_cab2 stoploopsound
	$down_trigger2 triggerable
		goto liftavator_prep
		
end


////////////-------------------------------go down-------------------------------------------
down:

$down_trigger2 waittill trigger

if (level.liftavator == 1)
{
	goto liftavator_prep
}
	$up_trigger2 nottriggerable //turn it off for no conflict
		$down_switch2 anim move	
while ($player.useheld) //when the player is holding the use key do this
{
	if (level.liftavator == 1)
	{
	goto liftavator_prep
	}
$elevator_cab2 loopsound lighthouse_run
$elev_liftup movedown 1
$elev_liftup waitmove
level.liftavator--

iprintln_noloc "level.liftavator = " (level.liftavator)
}
	$elevator_cab2 stoploopsound
	$up_trigger2 triggerable
		goto liftavator_prep
end
